- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
if (p)
free(p);
/* ... */
if (p)
q = realloc(p, size);
else
q = malloc(size);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+137
if (p)
free(p);
/* ... */
if (p)
q = realloc(p, size);
else
q = malloc(size);
немного классики.
из сырцов pdftohtml.
+121
package simplecms
import auth.*
class AuthFilters {
private checkPermission(def controller, def p, def session, def params) {
if (p) {
boolean result = session.user?.profile?.permissions?.contains(p)
if (p.delegate) {
result |= controller.checkDelegation[p.name](session, params)
} else if (p.controllerChecked) {
result &= controller.checkPermission[p.name](session, params)
}
if (!result && p.parent) {
result = checkPermission(controller, p.parent, session, params)
}
return result
}
return true
}
def filters = {
main(controller:'*', action:'*') {
before = {
def mappings = PermissionMapping.findAllByControllerAndMethodInList(controllerName, [actionName, '*'])
boolean denied = mappings?.size() > 0
if (denied) {
def permissions = []
session.user?.attach()
mappings.each { mapping ->
if (mapping.permission?.guest) {
denied = false
} else if (permission.parent == null){
permissions << mapping.permission
}
}
if (denied) {
denied = !permissions.any { checkPermission(grailsApplication.mainContext.getBean(controllerName), it, session, params) }
}
}
return !denied
}
}
}
}
Нашёл у себя в проекте. Иерархия разрешений? ну так будем проверять только корневые, что заморачиваться?!
+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(), про который все так много говорят?»
Добротный, защищенный на все сто, класс капчи. Невозможно сломать, уже просто потому, что невозможно понять...