- 1
- 2
- 3
if ( number % 10 == 0 ) {
number %= 10;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+59
if ( number % 10 == 0 ) {
number %= 10;
}
мне кажется, или...
−109
class QuerysetResponse(object):
"""
вариант респонса для фильтрации гридов или диктселекфилдов
используя механизм инструкций
"""
def __init__(self, queryset, application, root=None):
self.root = root or "data"
def __new__(cls, *args, **kwargs):
return super(cls, cls).__new__(cls)(*args, **kwargs)
def __call__(self, queryset, application):
dict_list = []
pack = get_pack_instance(application)
for item in pack.list_columns:
if isinstance(item, (list, tuple)):
dict_list.append(item[0])
elif isinstance(item, dict) and item.get('data_index'):
dict_list.append(item['data_index'])
self.dict_ = dict_list
if not queryset:
queryset = []
return PreJsonResult(dict(rows=list(queryset),
total=len(queryset)), dict_list=self.dict_).get_http_response()
self.root не используется, ну, это видно. QuerysetResponse "инстанцируется" во всем проекте один раз.
Мне бы такое даже в голову не пришло.
+157
if ( diffYear < 5 ) {
document.getElementById('yearsText').innerHTML = "года |";
} else if ( diffYear > 1 ){
document.getElementById('yearsText').innerHTML = "лет |";
} else {
document.getElementById('yearsText').innerHTML = "год |";
}
if ( diffMonth > 4 ) {
document.getElementById('monthText').innerHTML = "месяцев |";
} else if ( diffMonth > 1 ){
document.getElementById('monthText').innerHTML = "месяца |";
} else {
document.getElementById('monthText').innerHTML = "месяц |";
}
if ( diffDay > 5 ) {
document.getElementById('monthText').innerHTML = "дней |";
} else if ( diffDay > 1 ){
document.getElementById('monthText').innerHTML = "дня |";
} else {
document.getElementById('monthText').innerHTML = "день |";
}
}
очередная кака с датой
−161
my @arr = (1,2,3,4);
foreach (@arr)
{
threads->new(\&doSomething, $_)->join;
}
Цикл на 4...? Запуск потоков.
+91
<? die;
if($_GET['tn'])
{
if(($i = $conf['settings'][$s = "{$arg['modpath']}=>img"]) && ($img = explode(",", $i))){ $tn = array_combine($img, $img); }else{
$tn = array($_GET['tn']=>preg_replace('/[^0-9a-z_]/', '', $_GET['tn']));
} $sql = "SELECT `". mpquot($_GET['fn'] ? $_GET['fn'] : "img"). "` FROM {$conf['db']['prefix']}{$arg['modpath']}_{$tn[$_GET['tn']]} WHERE id=".(int)$_GET['id'];
$file_name = mpopendir("include")."/".($fn = mpql(mpqw($sql), 0, ($_GET['fn'] ? $_GET['fn'] : "img")));
if(!array_search(array_pop(explode('.', $file_name)), array(1=>"jpg", "jpeg", "png", "gif"))){
$file_name = mpopendir("img/ext/". array_pop(explode('.', $file_name)). ".png");
}
}else{
$file_name = mpopendir("modules/{$arg['modpath']}/img/". basename($_GET['']));
} header ("Content-type: image/". array_pop(explode('.', $file_name)));
echo mprs($file_name, $_GET['w'], $_GET['h'], $_GET['c']);
?>
это не шуууутки мы встретились в маршруууутке
+76
if ( !log.append(log_line) )
log.append("Can't append to log");
Безумие, оно рядом.
+158
$i = 0;
for ($k = 0; $k<=5; $k++){
if ($i==5)
break;
foreach (getContent($id) as $content_row) {
$i++;
$htmlshowcase = $content_row->getShowcase(1, $k);
if ($htmlshowcase == '')
$i--;
else
$html .= $htmlshowcase;
if ($i==5)
break;
}
}
Лучший способ прохода по циклу.
+129
import std.uuid;
import std.file;
import std.path;
import std.string;
ubyte[] sdlBytes = cast(ubyte[]) import("SDL2.dll"); // SDL2.dll contents
void main(string[] args)
{
auto uuid = randomUUID();
string uuid = randomUUID().toString();
string filename = format("SDL2-%s.dll", uuid); // Making an unique file name.
string depacked = buildPath(tempDir(), filename);
std.file.write(depacked, sdlBytes); // Writing the dynlib to a temporary file.
DerelictSDL2.load(depacked); // Use the depacked dynlib and load its symbols.
}
лол, надо поюзать.
+152
<?
require_once('ittable.class.php');
class ITForm extends ITTable
{
public function __construct($tbl)
{
parent::__construct($tbl);
//путь с скрипту который удаляет файлы по tblname record_id filename
$this->path2deletephp='/itcms4/ckeditor/delete.php';
}
public function printForm($i, $action, $head, $submitvalue='', $captcha=0)
{
$form = $this->generateFormData($i, $action, $head, $submitvalue, $captcha);
print "<h1>$form->head</h1>
$form->begin
$form->inputhidden
<table>";
foreach($form->inputs as $k=>$v)
print "<tr id='itforms_$k'" . ($this->columns[$k]->blockclass?' class="' . $this->columns[$k]->blockclass . '"':'') ."><td>$v->name</td><td>$v->input</td></tr>\n";
print "</table>
$form->files
<hr><input type='submit' value='$form->submitvalue'></form>
<script type='text/javascript'>
var itform;
$(document).ready(function()
{
itform = new ITForm($('#$this->tbl$i->id'));
$form->js
});
</script>
";
}
public function insertForm($head, $submitvalue='', $i=0)
{
if(!$i)
$i = new stdClass();
$copy_id = intval($_GET['copy_id']);
if($copy_id)
{
$r=exec_mysql_query("SELECT * FROM $this->tbl WHERE id='$copy_id'");
$row=mysql_fetch_array($r);
foreach($row as $k=>$v)
if(!isset($i->$k))
$i->$k = $v;
}
//чтобы можно было загрузить файлы делаем временный id в диапазоне от 10^7 до 2*10^9
$i->id = 'r' . rand(10000000, 2000000000);
$this->printForm($i, 'insert.php', $head, $submitvalue);
}
public function updateForm($id, $head, $submitvalue='')
{
$this->printForm($this->getObject($id), 'update.php', $head, $submitvalue);
if(mysql_numrows(exec_mysql_query("SELECT id FROM it_updatelog WHERE tbl='$this->tbl' AND record_id='$id'")))
print "<a href=/crm2/log/?w_tbl_2=$this->tbl&w_record_id_1=$id>История изменений</a><br>";
}
public function deleteForm($id, $head, $submitvalue='')
{
$this->printForm($this->getObject($id), 'delete.php', $head, $submitvalue);
}
public function updateForm4Object($o, $head, $submitvalue='')
{
$this->printForm($o, 'update.php', $head, $submitvalue);
if(mysql_numrows(exec_mysql_query("SELECT id FROM it_updatelog WHERE tbl='$this->tbl' AND record_id='$o->id'")))
print "<a href=/crm2/log/?w_tbl_2=$this->tbl&w_record_id_1=$o->id>История изменений</a><br>";
}
Продолжение: http://govnokod.ru/17479
+152
<?
require_once('ittable.class.php');
class ITForm extends ITTable
{
public function __construct($tbl)
{
parent::__construct($tbl);
//путь с скрипту который удаляет файлы по tblname record_id filename
$this->path2deletephp='/itcms4/ckeditor/delete.php';
}
public function generateFormData($i, $action, $head, $submitvalue='', $captcha=0)
{
global $itcmscfg;
$form->submitvalue=htmlentities($submitvalue?$submitvalue:$head, ENT_NOQUOTES, 'UTF-8');
$form->tbl = $this->tbl;
if($this->files) $enctype='enctype="multipart/form-data"';
$form->head = htmlentities($head, ENT_NOQUOTES, 'UTF-8');
$form->begin = "<form name='$this->tbl$i->id' id='$this->tbl$i->id' action='$action' method='post' $enctype>";
$form->inputhidden .= "<input type='hidden' name='id' value='$i->id'><input type='hidden' name='referer' value='" . ($_SERVER['HTTP_REFERER']?$_SERVER['HTTP_REFERER']:'./') . "'>\n";
if($action=='delete.php') {$form->disabled = 'disabled'; $OPERATION = UPDATABLE;}
elseif($action=='insert.php') $OPERATION = INSERTABLE;
elseif($action=='update.php') $OPERATION = UPDATABLE;
else $OPERATION = UPDATABLE;
foreach($this->columns as $field=>$ftype)
{
$itforms = " $form->disabled name='$field' id='input-$field'" . $this->getITFormsAttr($field);
$value = isset($i->$field) ? $i->$field : ($_GET[$field] ? $_GET[$field]: $ftype->Default);
if(!$ftype->htmlcode) $value = htmlentities($value, ENT_QUOTES, 'UTF-8');
$itcmscfg->cfgfile = intval($itcmscfg->cfgfile);
if($ftype->Key=='UNI') $itforms .= " data-async='false' data-unique='{cfgfile:$itcmscfg->cfgfile, tblname:\"$this->tbl\", record_id:\"$i->id\"}'";
if($ftype->visibility & HIDDEN){$form->inputhidden .= "<input type='hidden' $itforms value='$value'>"; continue;}
//если поле не RADONLY, то проверить задан ли regexp и разрешена ли операция
if( !($ftype->visibility & READONLY) )
if(!$ftype->pattern || !($ftype->visibility & $OPERATION))
continue;
$form->inputs[$field]->name = "<label for='input-$field' id='label-$field'>$ftype->outputname</label>";
//выводим элементы
if($ftype->options)
{
$form->inputs[$field]->input = $ftype->options->html($field, " $form->disabled " . $this->getITFormsAttr($field), $value);
if($ftype->options->type==OT_BINARY_CHECKBOX)
$form->js .= "itform.setCheckboxProperty('$field', 'sum', '$ftype->minselected', '$ftype->maxselected');\n";
}
elseif($ftype->inputtype=='wysiwyg')
$form->inputs[$field]->input = "<script src=/include/ckeditor/ckeditor.js></script>
<textarea class='ckeditor' name='$field'>$value</textarea>";
elseif($ftype->Type=='text')
$form->inputs[$field]->input = "<textarea rows='10' cols='80' $itforms " . ($form->disabled?' readonly':'') . ">$value</textarea>";
elseif($ftype->inputtype)
$form->inputs[$field]->input = "<input type='$ftype->inputtype' value='$value' $itforms>";
else
$form->inputs[$field]->input = "<input type='text' value='$value' $itforms>";
$f1 = $ftype->func;
if(isset($f1))
$form->inputs[$field]->input .= (' ' . $f1($value));
}//foreach
if($this->files)
{
foreach($this->files as $k=>$o)
{
$itforms = "";
//это только для action==insert.php можно, при редактирвоании не обязательно файл заливать
$itforms .= ($o->required && $action=='insert.php') ? " data-min-length='1'" : '';
$itforms .= $o->validExtentions ? " data-regexp='$o->validExtentions'" : '';
if($o->help) $itforms .= " data-help='$o->help'";
if($o->multiple)
{
$itforms .= ' multiple';
$multiple = '[]';
}
else
$multiple='';
$outputname = htmlentities($o->outputname, ENT_NOQUOTES, 'UTF-8');
$form->inputs[$k]->name = "<label for='input-$k'>$outputname</label>";
$form->inputs[$k]->input = "<input type='file' name='$k$multiple' id='input-$k' $itforms>";
}//foreach
if(intval($i->id))
$form->files = $itcmscfg->fs->getFiles4TblRecord($this->tbl, $i->id);
}//if
return $form;
}//fun