- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
enum IsHaveItem{
//...
switch(Havelo)
{
case IsHaveItem::Have: have();
case IsHaveItem::Havent: haveOrNotHave();break;
default:assert(false&&"Признай, что ты идиот и это не лечится!");
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1000
enum IsHaveItem{
//...
switch(Havelo)
{
case IsHaveItem::Have: have();
case IsHaveItem::Havent: haveOrNotHave();break;
default:assert(false&&"Признай, что ты идиот и это не лечится!");
}
Нашёл в проекте. Нет, ни тогда, когда сработал ассерт.
+133
(require 'clsql)
(clsql:file-enable-sql-reader-syntax)
(clsql:connect
'("localhost" "database" "user" "password")
:database-type :mysql)
(defun how-many-goods-do-you-have (year month)
(declare
(type (integer 2000 2011) year)
(type (integer 1 12) month))
(clsql:select [item_id] [sale_date]
:from "table"
:where [or
[is [null [sale_date]]]
[< [sale_date]
(clsql:sql 'str_to_date\(
(format
nil
"~a-~2,'0d-00"
year month)
'|, '%Y-%m-%d')|
)]]))
Эксперименты :)
+158
function GetMonthByNum($m)
{
$month_int = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
$month_str = array('Январь', 'Февраль', 'Март','Апрель', 'Мая', 'Июнь','Июль', 'Август', 'Сентябрь','Октябрь', 'Ноябрь', 'Декабрь');
return str_replace($month_int, $month_str, $m);
}
Начало своего пути программирования несколько лет назад. Тогда еще долго думал, как оптимизировать данный код.
+964
private static int CompareWidgetsByOrder(Widget x, Widget y)
{
return x == null ? y == null ? 0 : 1 : y == null ? 0 : x.order > y.order ? -1 : x.order < y.order ? 1 : 0;
}
Вот до чего доводит стремление к компактности кода.
+141
echo wp_count_comments($post->ID)->approved;
Не знал, что так можно. Сработало, хыхы.
+1002
MAX_DATA_SIZE = unsigned char(~0) * sizeof(long);
Нахрена???)))
+165
# получение остатка от деления
function ostatok($chislo,$na_skolko)
{
$chislo2=$chislo/$na_skolko;
$chislo2=(int)$chislo2;
$chislo3=$chislo2*$na_skolko;
$chislo4=$chislo-$chislo3;
return $chislo4;
}
Получение остатка от деления двух чисел. Без комментариев.
+159
##############################################
# Bitrix: SiteManager #
# Copyright (c) 2002-2006 Bitrix #
# http://www.bitrixsoft.com #
# mailto:[email protected] #
##############################################
if (!class_exists("CCaptcha"))
{
class CCaptcha
{
var $imageWidth = 180;
var $imageHeight = 40;
// ...etc
Это Битрикс. Опять. bitrix\modules\main\classes\general\capt cha.php
Определение нативной капчи.
В строке 8 создатели сего как бы задаются воспросом «А вдруг еще никто не писал до нас капчи?».
Или перестраховываются — «а вдруг require() уже вызывался? И что такое require_once(), про который все так много говорят?»
Добротный, защищенный на все сто, класс капчи. Невозможно сломать, уже просто потому, что невозможно понять...
+146
<?php
function check($s)
{
$brackets = array(')' => '(', ']' => '[', '}' => '{');
$stack = array();
$stack_size = 0;
for($i = 0; $i < strlen($s); $i++)
{
if (in_array($s[$i], array_values($brackets)))
{
$stack[$stack_size++] = $s[$i];
}
else if (in_array($s[$i], array_keys($brackets)))
{
$last = $stack_size ? $stack[$stack_size-1] : '';
if ($last != $brackets[$s[$i]])
{
return false;
}
else
{
unset($stack[--$stack_size]);
}
}
}
return count($stack) == 0;
}
function check_brackets($s)
{
if(check($s))
{
return true;
}
else return false;
}
if($_POST["bracket_string"])
{
if(check_brackets($_POST["bracket_string"]))
{
$message = "Check passed";
}
else $message = "Check failed";
}
?>
Пацаны, есть задание. Срочно заговнокодить код, но чтобы точно работало.
−113
select o.*
from (select rownum rw
, o.*
from (select o.* from all_tables o order by table_name) o
where rownum < 20
) o
where o.rw >= 10;
Стандартный аналог "LIMIT 9,10" в Oracle.
http://www.sql.ru/faq/faq_topic.aspx?fid=171