1. PHP / Говнокод #7127

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $key = 0;
    foreach ($this->hosts as $key => $host) {
       $key++;
        .....
    }

    goliath, 01 Июля 2011

    Комментарии (22)
  2. Assembler / Говнокод #7126

    +143

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    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

    Tronix, 01 Июля 2011

    Комментарии (39)
  3. Pascal / Говнокод #7125

    +93

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    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

    Tronix, 01 Июля 2011

    Комментарии (24)
  4. Java / Говнокод #7124

    +70

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    //обработка поведения кнопки копировать
          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);
             }
          }
          //-----------------------------------------------------------

    Это - "Гребаный копипаст"

    maxt, 01 Июля 2011

    Комментарии (6)
  5. C++ / Говнокод #7123

    +147

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    try
    {
        // A lot of code
    }
    catch (Exception &exception)
    {
        Application->ShowException(&exception);
    }
    catch (...)
    {
        try
        {
           throw Exception("");
        }
        catch (Exception &exception)
        {
            Application->ShowException(&exception);
        }
    }

    :) Обработка исключений

    egoroff, 01 Июля 2011

    Комментарии (8)
  6. Ruby / Говнокод #7122

    −104

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    @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! похоже :)

    lnk, 01 Июля 2011

    Комментарии (4)
  7. C# / Говнокод #7121

    +113

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    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;
            }

    ресайз изображения

    tuxcod, 30 Июня 2011

    Комментарии (7)
  8. PHP / Говнокод #7120

    +145

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    <?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 пользователя, дальше это все клеится в один массив для отображения в табличке.

    Nicklasos, 30 Июня 2011

    Комментарии (11)
  9. JavaScript / Говнокод #7119

    +161

    1. 1
    2. 2
    3. 3
    function returnFalse() {
    	return false;
    }

    VIA, 30 Июня 2011

    Комментарии (13)
  10. PHP / Говнокод #7118

    +163

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    $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 по-джедайски

    maximum, 30 Июня 2011

    Комментарии (10)