- 1
- 2
- 3
- 4
- 5
$key = 0;
foreach ($this->hosts as $key => $host) {
$key++;
.....
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+161
$key = 0;
foreach ($this->hosts as $key => $host) {
$key++;
.....
}
+143
cmp bl,1
je France_jmp
cmp ax,380
je Bulgaria_jmp
cmp ax,383
je Slavonia_jmp
cmp ax,385
je Croatia_jmp
mov bx,400
mov dx,440
call IfAnd
cmp bl,1
je Germany_jmp
jmp next_s
USA_jmp: jmp USA
Grinford_jmp: jmp Grinford
France_jmp: jmp France
Bulgaria_jmp: jmp Bulgaria
Slavonia_jmp: jmp Slavonia
Croatia_jmp: jmp Croatia
Germany_jmp: jmp Germany
next_s:
mov bx,450
mov dx,459
call IfAnd
cmp bl,1
je Japan_jmp
mov bx,460
mov dx,469
call IfAnd
cmp bl,1
je Russia_jmp
cmp ax,471
je Taiwan_jmp
cmp ax,474
je Estonia_jmp
cmp ax,475
je Litvia_jmp
cmp ax,477
jmp next_ss
Japan_jmp: jmp Japan
Russia_jmp: jmp Russia
Taiwan_jmp: jmp Taiwan
Estonia_jmp: jmp Estonia
Litvia_jmp: jmp Latvia
Lithuania_jmp: jmp Lithuania
Philippines_jmp: jmp Philippines
Ukraine_jmp: jmp Ukraine
Moldova_jmp: jmp Moldova
Hongkong_jmp: jmp Hongkong
Britain_jmp: jmp Britain
Greece_jmp: jmp Greece
Cyprus_jmp: jmp Cyprus
Macedonia_jmp: jmp Macedonia
Malta_jmp: jmp Malta
Ireland_jmp: jmp Ireland
Belgium_jmp: jmp Belgium
Portugal_jmp: jmp Portugal
Iceland_jmp: jmp Iceland
Denmark_jmp: jmp Denmark
next_ss:
je Lithuania_jmp
cmp ax,480
je Philippines_jmp
cmp ax,482
je Ukraine_jmp
cmp ax,484
je Moldova_jmp
cmp ax,489
je Hongkong_jmp
Прога для проверки правильности штрих-кодов по контрольной сумме и определение страны-производителя. Про таблицы перехода и near-адресацию конечно в те времена еще не догадывался, только начинал учить асм.
PS: А интерфейс у нее ничего такой был для ассемблера, правда слизал с NU: http://habrastorage.org/storage1/e4efe022/903c7848/d99f7f4f/33d1ed16.png
+93
if Length(PP.curdir)<36 then
pt:=' '+PP.curdir+' '
else pt:=' \...'+Copy(PP.curdir,Length(PP.curdir)-30,31)+' ';
Ptr:=PP.f_ptr;
if PP.vol='' then PP.vol:='No Label';
WriteString(1,cc+(40-length(pt)) div 2,pt,Pal[8]);
WriteString(22,cc+1+(cc*(34-length(PP.vol))) div 40,'['+PP.vol+']',Pal[7]);
if PP.vol='No Label' then PP.vol:='';
{if PP.empty then exit;}
inc(ptr,sizeof(filrec)*row);
for i:=row to n+row do begin
if (i <PP.files) and (not PP.empty) then begin fname:=ptr^.filename;
{if (ptr^.fileattr and 16) = 0 then StrLwr(fname);}
if (Ptr^.fileattr and 2) <> 0 then fname[1]:=upcase(fname[1]);
if ((Ptr^.fileattr and Hidden) <> 0) and (Pos('.',Fname)>0) then fname[Pos('.',Fname)+1]:=upcase(fname[Pos('.',Fname)+1]);
SortFIle(fname);
for a := length(fname) to 11 do fname:=fname+' ';
fname:=fname+'│';
if (Ptr^.fileattr and 16) = 0 then Str(Ptr^.filesize:10,pt)
else if fname[1]='.' then pt:='UP──-DIR'
else pt:='SUB─-DIR';
fname:=fname+pt+'│';
DateTimeCnv(pt,Ptr^.filedttm);
fname:=fname+pt; {SetFattr}
if Ptr^.selected then WriteString(2+i-row,cc,fname,Pal[1]) else
WriteString(2+i-row,cc,fname,Pal[2]);
inc(ptr,sizeof(filrec));
end
else WriteString(2+i-row,cc,' │ │ │ ',Pal[1]);
end;
end;
procedure Put_File(PP:Panel;cc,row,x:word;active:boolean);
var
fname,pt:string;
{ptr:P_filrec;}
begin
if PP.empty then exit;
ptr:=PP.F_ptr;
inc(ptr,sizeof(filrec)*(row+x));
fname:=ptr^.filename;
{if (ptr^.fileattr and 16) = 0 then StrLwr(fname);}
if (Ptr^.fileattr and 2) <> 0 then fname[1]:=upcase(fname[1]);
if ((Ptr^.fileattr and Hidden) <> 0) and (Pos('.',Fname)>0) then fname[Pos('.',Fname)+1]:=upcase(fname[Pos('.',Fname)+1]);
SortFile(fname);
for a := length(fname) to 11 do fname:=fname+' ';
fname:=fname+'│';
if (Ptr^.fileattr and 16) = 0 then Str(Ptr^.filesize:10,pt)
else if fname[1]='.' then pt:='UP──-DIR'
else pt:='SUB─-DIR';
fname:=fname+pt+'│';
DateTimeCnv(pt,Ptr^.filedttm);
fname:=fname+pt;
if active then If Ptr^.selected then WriteString(2+x,cc,fname,Pal[3]) else
WriteString(2+x,cc,fname,Pal[4])
else if Ptr^.selected then WriteString(2+x,cc,fname,Pal[1]) else
WriteString(2+x,cc,fname,Pal[2])
Файловый менеджер по-типу NC. Pascal, 7-ой класс школы. Участок формирования одной из панелей.
PS: Вообще, это даже как-то работало: http://habrastorage.org/storage1/84736ecc/b4711597/5b1d2618/5b60c662.png
+70
//обработка поведения кнопки копировать
if(tni.isTreeStruct()) {
copyDocuments.setEnabled(false);
}
else {
copyDocuments.setEnabled(true);
if(jTree.getSelectionCount() > 1) {
copyDocuments.setEnabled(false);
}
else {
copyDocuments.setEnabled(true);
}
}
//-----------------------------------------------------------
//обработка поведения кнопки копировать c файлами
if(tni.isTreeStruct()) {
copyDocsWithFile.setEnabled(false);
}
else {
copyDocsWithFile.setEnabled(true);
if(jTree.getSelectionCount() > 1) {
copyDocsWithFile.setEnabled(false);
}
else {
copyDocsWithFile.setEnabled(true);
}
}
//-----------------------------------------------------------
Это - "Гребаный копипаст"
+147
try
{
// A lot of code
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
:) Обработка исключений
−104
@hands_by_value.each do |hand|
if @hands_by_value.slice(@hands_by_value.index(hand)+1..@hands_by_value.index(@hands_by_value.last)).include?(hand)
@hands_by_value.delete_at(@hands_by_value.index(hand))
end
end
Рукотворный array.uniq! похоже :)
+113
public string GetNormalImage(int newWidth, int newHeight, string sufix = "normal") {
String[] tmp = _originalImagePath.Split('.');
String newImagePath = "";
for (int i = 0; i < tmp.Length - 1; i++)
{
newImagePath += tmp[i];
newImagePath += "_";
}
newImagePath += sufix + ".";
newImagePath += tmp[tmp.Length - 1];
Image oldImage = Image.FromFile(_originalImagePath);
if (oldImage.Height >= oldImage.Width) {
Image newImage;
newImage = FixedSize(oldImage, newWidth, newHeight);
newImage.Save(newImagePath);
} else {
float heightRatio = (float)newHeight / (float)oldImage.Height;
float widthRatio = (float)newWidth / (float)oldImage.Width;
float bestRatio = 1;
if (heightRatio < widthRatio) {
bestRatio = heightRatio;
} else {
bestRatio = widthRatio;
}
var result = new System.Drawing.Bitmap((int)Math.Round(oldImage.Width * bestRatio), (int)Math.Round(oldImage.Height * bestRatio));
using (var graphics = Graphics.FromImage(result))
{
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawImage(oldImage, new Rectangle(Point.Empty, new Size((int)Math.Round(oldImage.Width * bestRatio), (int)Math.Round(oldImage.Height * bestRatio))));
}
result.Save(newImagePath);
}
return newImagePath;
}
ресайз изображения
+145
<?php
/* {{{ index */
function creative_stat_default()
{
$dtime = urldecode(get_param('dtime', date('d.m.Y-d.m.Y')));
list($begin_t, $end_t) = convert_date_calendar($dtime);
$user = User::get_instance();
$DB = DbSimple::getDb();
$creatives_ids = $user->get_users_ids_by_roles(array('creative'));
// user names
$sql = "
SELECT user_id AS ARRAY_KEY, {$user->sql_case_names} as name
FROM users
WHERE user_id IN (?a)";
$user_names = $DB->select($sql, $creatives_ids);
// tasks all
$sql = "
SELECT to_user_id AS ARRAY_KEY, count(task_id) as tasks_all
FROM creative_tasks
WHERE to_user_id IN (?a) AND dtime BETWEEN ?d AND ?d
GROUP BY to_user_id
";
$tasks = $DB->select($sql, $creatives_ids, $begin_t, $end_t);
// tasks done
$sql = "
SELECT to_user_id AS ARRAY_KEY, count(task_id) as tasks_done
FROM creative_tasks
WHERE to_user_id IN (?a) AND dtime BETWEEN ?d AND ?d AND status_id = ?d
GROUP BY to_user_id
";
$tasks_done = $DB->select($sql, $creatives_ids, $begin_t, $end_t, GOODS_STATUS_ACTIVE);
// goods all
$sql = "
SELECT creatives_id AS ARRAY_KEY, count(good_id) as goods_all
FROM goods
WHERE creatives_id IN (?a) AND date_create BETWEEN ?d AND ?d
GROUP BY creatives_id
";
$goods_all = $DB->select($sql, $creatives_ids, $begin_t, $end_t);
// goods active
$sql = "
SELECT creatives_id AS ARRAY_KEY, count(good_id) as goods_active
FROM goods
WHERE creatives_id IN (?a) AND date_create BETWEEN ?d AND ?d AND status_id = ?d
GROUP BY creatives_id
";
$goods_active = $DB->select($sql, $creatives_ids, $begin_t, $end_t, GOODS_STATUS_ACTIVE);
foreach($creatives_ids as $id) {
$stat[$id] = array_merge(
$user_names[$id],
isset($tasks[$id]) ? $tasks[$id] : array('tasks_all' => 0),
isset($tasks_done[$id]) ? $tasks_done[$id] : array('tasks_done' => 0),
array(
'tasks_not_ready' => (isset($tasks[$id]['tasks_all']) ? $tasks[$id]['tasks_all'] : 0) -
(isset($tasks_done[$id]['tasks_done']) ? $tasks_done[$id]['tasks_done'] : 0)),
isset($goods_all[$id]) ? $goods_all[$id] : array('goods_all' => 0),
isset($goods_active[$id]) ? $goods_active[$id] : array('goods_active' => 0)
);
}
render_tpl('creative/stat/index', array(
'header' => 'Статистика креатива',
'dtime' => $dtime,
'stat' => $stat
), 'creative#stat');
}
/* }}} */
Собираю статистику. Каждый запрос возвращает массив с ключем = id пользователя, дальше это все клеится в один массив для отображения в табличке.
+161
function returnFalse() {
return false;
}
+163
$json = "";
$json .= "{\n";
$json .= "page: $page,\n";
$json .= "total: $total,\n";
$json .= "rows: [";
$rc = false;
while ($row = mysql_fetch_array($result)) {
if ($rc) $json .= ",";
$json .= "\n{";
$json .= "id:'".$row['id']."',";
$json .= "cltr: 'fo',";
$json .= "cell:['";
$json .= $row['secid'];
$json .="','".$row['blasttradedate'];
$json .="','".round($row['bid'],$row['decimals']);
$json .="','".round($row['offer'],$row['decimals']);
$json .="','".round($row['price'],$row['decimals']);
if(round($row['last'],$row['decimals'])) $json .="','".round($row['last'],$row['decimals']);
else $json .="', '";
// и еще много строк в том же духе
}
$json .= "]\n";
$json .= "}";
Сборка JSON по-джедайски