- 1
- 2
- 3
List<String> list;
....
Long num = Long.parseLong( "" + list.size() );
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+79
List<String> list;
....
Long num = Long.parseLong( "" + list.size() );
Самый оригинальный способ конвертации int в Long, кот. встречал в проекте )
+41
int sheeps(int pole[10][10])
{
int i,j,f,k,r;
int rand_chislo, rand_chislo1, ts,s;
srand(time(NULL));
for (i=0;i<10;i++)
for (j=0;j<10;j++)
pole [i][j]=0;
do{ f=0;
rand_chislo = 0 + rand() %10;
rand_chislo1= 0 + rand() %10;
ts = 1+rand()%4;
if (ts==1) {for(i=0;i<3;i++) if(rand_chislo==i)f=1;}
if (ts==2) {for(i=7;i<10;i++) if(rand_chislo==i)f=1;}
if (ts==3) {for(i=0;i<3;i++) if(rand_chislo1==i)f=1;}
if (ts==4) {for(i=7;i<10;i++) if(rand_chislo1==i)f=1;}
}
while (f==1);
switch (ts){
case 1: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo-1][rand_chislo1]=1;
pole[rand_chislo-2][rand_chislo1]=1;pole[rand_chislo-3][rand_chislo1]=1; break;
case 2: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo+1][rand_chislo1]=1;
pole[rand_chislo+2][rand_chislo1]=1;pole[rand_chislo+3][rand_chislo1]=1; break;
case 3: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo][rand_chislo1-1]=1;
pole[rand_chislo][rand_chislo1-2]=1;pole[rand_chislo][rand_chislo1-3]=1;break;
case 4: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo][rand_chislo1+1]=1;
pole[rand_chislo][rand_chislo1+2]=1;pole[rand_chislo][rand_chislo1+3]=1; break; }
for (k=0;k<3;k++)
{
do{ f=0;
rand_chislo = 0 + rand() %10;
rand_chislo1= 0 + rand() %10;
ts = 1+rand()%4;
if (ts==1) {if(rand_chislo!=0){ for (i=rand_chislo-2;i<rand_chislo+2;i++)
for (j=rand_chislo1-1;j<=rand_chislo1+1;j++)
{if (pole[i][j]!=0){f=1;}}}else f=1; }
if (ts==2) {if (rand_chislo!=9) { for (i=rand_chislo-1;i<=rand_chislo+2;i++)
for (j=rand_chislo1-1;j<=rand_chislo1+1;j++)
{ if (pole[i][j]!=0){ f=1;}}}else f=1; }
if (ts==3) { if (rand_chislo1!=0) { for (i=rand_chislo-1;i<=rand_chislo+1;i++)
for (j=rand_chislo1-2;j<=rand_chislo1+1;j++)
{ if (pole[i][j]!=0){ f=1;}}}else f=1; }
if (ts==4) { if (rand_chislo1!=9) { for (i=rand_chislo-1;i<=rand_chislo+1;i++)
for (j=rand_chislo1-1;j<=rand_chislo1+2;j++)
{ if (pole[i][j]!=0){ f=1;}}}
else f=1; }
}
while (f==1);
switch (ts){
case 1: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo-1][rand_chislo1]=1; break;
case 2: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo+1][rand_chislo1]=1; break;
case 3: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo][rand_chislo1-1]=1;break;
case 4: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo][rand_chislo1+1]=1; break; }
}
for (k=0;k<2;k++)
{
do{ f=0;
rand_chislo = 0 + rand() %10;
rand_chislo1= 0 + rand() %10;
/*зесь еще 2 таких же while (if==1) и for k<3 и k<4 */
return pole[10][10];
}
курсовик первокурсника "морской бой". функция расстановки кораблей
+58
// что-то страшно мне стало
class Mysql{
private $db = null;
private $result = null;
//private $row = null;
function __construct($dbname,$dbuser,$dbpass,$dbhost){
$this->db = mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname) or die ("<br>Invalid query: " . mysql_error());
mysql_query("SET NAMES utf8") or die ("<br>Invalid query: " . mysql_error());
}
function connect(){
if(!$this->db){
exit("Error connect BD!");
}
}
function query($query){
if(!$query){exit("No [query]");}
$this->result = $query = mysql_query($query) or die ("<br>Invalid query: " . mysql_error());
return $query;
}
}
−158
SELECT ft_login,fi_system,ft_password,fk_id
FROM users u
INNER JOIN taccountscontent t ON u.id = t.fk_id
WHERE u.id IN (select id from users where id=123)
Оригинал http://www.askdev.ru/question/16663/%D0%97%D0%B0%D0%BF%D1%80%D0%BE%D1%81-%D0%BA-%D0%91%D0%94-%D0%B8-%D1%86%D0%B8%D0%BA%D0%BB-While/
−160
<div class="comment-content">
<% if comment.body.include?('[/quote]') %>
<% @text = Array.new %>
<% summ = '' %>
<% @text = simple_format(comment.body).split(' ') %>
<% namecheck = false %>
<% contentcheck = false %>
<% quotestart = false %>
<% donothing = true %>
<% quotecount = 0 %>
<% count_quotes = 0 %>
<% @text.each do |t| %>
<% if t.include?('[/quote]') %>
<% count_quotes ||= 0 %>
<% count_quotes += 1 %>
<% end %>
<% end %>
<% @text.each do |t| %>
<% if t.include?('[/quote]') %>
<% contentcheck = false %>
<% namecheck = false %>
<% t = t.gsub('[/quote]', '</div></div>') %>
<% elsif t.include?('[quote=') %>
<% namecheck = true %>
<% donothing = false %>
<% t = t.gsub('[quote=', '') %>
<% elsif t.include?(']') %>
<% t = t.gsub(']', '') %>
<% end %>
<% if donothing == false %>
<% if contentcheck == true and namecheck == true and t != '' and t != '<p>' and t != '</p>' %>
<% t = '<div class=quotecontent>' + '<div class=quotestart>' + '<div class=quotename>' + 'Цитата - ' + t + '</div>' %>
<% contentcheck = true %>
<% namecheck = false %>
<% elsif contentcheck == true and t != '' and t != '<p>' and t != '</p>' %>
<% t = '<div class=quotecontent>' + t %>
<% contentcheck = false %>
<% elsif namecheck == true and t != '' and t != '<p>' and t != '</p>' %>
<% t = '<div class=quotestart>' + '<div class=quotename>' + 'Цитата - ' + t + '</div>' %>
<% namecheck = false %>
<% contentcheck = true %>
<% end %>
<% end %>
<% summ = summ + t + ' ' %>
<% end %>
<% else %>
<% summ = comment.body %>
<% end %>
<%=raw simple_format(summ) %>
</div>
Вьюха списка комментариев. Когда это попало к верстальщику - он был мягко говоря шокирован.
−79
t = 40000 -- количество итераций, чтобы выполнялось примерно 1 миллисекунду
-- экспериментальным путем определено, что для ideone'вских машин это значение ~40000
sleep x = (apply (t*x) id x) `seq`
("I've waited ~" ++ show x ++ " milliseconds to tell this: 'pipisiunchik'.")
-- apply применяет ф-цию f к x n раз
apply 0 _ !x = x
apply !n !f !x = apply (n - 1) f (f x)
main = putStrLn $ sleep 1000
Спешу представить вам плод моего безделья: чистая ф-ция sleep на Haskell!
Тесты:
1sec - http://ideone.com/sLxRx
3.5sec - http://ideone.com/vn4Fd
10sec - http://ideone.com/U8s36
+120
private void button4_Click(object sender, RoutedEventArgs e)
{
if (!rand)
{
rand = true;
}
if (rand)
{
rand = false;
}
} // Кнопка переключения воспроизведения в случайный режим и оборатно
+72
public function isAdmin() {
$admins = Model::factory('User')->where('access_level_id', 1)->find_many();
$ids = array();
foreach($admins as $admin) {
$ids[]= $admin->id;
}
return in_array($this->id, $ids) ? true : false;
}
Метод проверки на админе из модели пользователей. Не, ну а чо.
−116
ВЫБОР
КОГДА ПолФизическихЛиц.Ссылка = "Женский"
ТОГДА "М"
ИНАЧЕ "Ж"
КОНЕЦ
Вот такой вот забавный запрос
−47
void init_by_array64(unsigned long long init_key[],
unsigned long long key_length)
{
unsigned long long i, j, k;
init_genrand64(19650218ULL);
i=1; j=0;
k = (NN>key_length ? NN : key_length);
for (; k; k--) {
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62)) * 3935559000370003845ULL))
+ init_key[j] + j; /* non linear */
i++; j++;
if (i>=NN) { mt[0] = mt[NN-1]; i=1; }
if (j>=key_length) j=0;
}
for (k=NN-1; k; k--) {
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62)) * 2862933555777941757ULL))
- i; /* non linear */
i++;
if (i>=NN) { mt[0] = mt[NN-1]; i=1; }
}
mt[0] = 1ULL << 63; /* MSB is 1; assuring non-zero initial array */
}
"Чистый и ясный код" (с)