1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. JavaScript / Говнокод #7119

    +161

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

    VIA, 30 Июня 2011

    Комментарии (13)
  8. 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)
  9. PHP / Говнокод #7117

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    /**
     * GetResponse
     * For common activation code length must be only 4 or 5 or 7 or 8 chars
     *
     * From XXX ... or 10
     * From YYY ... or 11
     *
     * @return string
     */

    эволюция

    elw00d, 30 Июня 2011

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

    +151

    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
    <?
    if(!defined('Hacking')) { die('Hacking attempt!'); exit;}
    
    $database_user_name="demo";
    $database_password="demo";
    $database_name="demo";
    $display_errors = false;
    $AdminEmail="[email protected]";
    $bpref="demo";
    $domenname="demo";
    function connect_db()
    {
    global $database_user_name, $database_password;
    $db=mysql_connect("localhost",$database_user_name,$database_password) or die ("Could not connect");
    mysql_query("SET NAMES cp1251") or die("Invalid query: " .mysql_error());
    return $db;
    }
    function db_name()
    {
    global $database_name;
    $db_name=$database_name;
    return $db_name;
    }
    function get_now()
    {
    $db=connect_db();
    $db_name=db_name();
    mysql_select_db($db_name,$db);
    $sql="select now() as now";
    $result=mysql_query($sql,$db);
    $myrow=mysql_fetch_array($result);
    $now=$myrow["now"];
    return $now;
    }
    function puterror($message)
    {
    echo("<p>$message</p>");
    exit();
    }
    foreach($_GET as $chexss) {
    if((eregi("<[^>]*script[^>]*>", $chexss)) || (eregi("<[^>]*object[^>]*>", $chexss)) ||
    (eregi("<[^>]*iframe[^>]*>", $chexss)) || (eregi("<[^>]*applet[^>]*>", $chexss)) ||
    (eregi("<[^>]*meta[^>]*>", $chexss)) || (eregi("<[^>]*style[^>]*>", $chexss)) ||
    (eregi("<[^>]*form[^>]*>", $chexss)) || (eregi("\([^>][^)]*\)", $chexss)) ||
    (eregi("<[^>]*frameset[^>]*>", $chexss)) || (eregi("<[^>]*onmouseover[^>]*>", $chexss)) ||
    (eregi("<[^>]*img[^>]*>", $chexss)) || (eregi("\"", $chexss)) || (eregi("'", $chexss))){
    die("Попытка ХАКА !");
    }
    } 
    $zzzz = html_entity_decode(urldecode($_SERVER['QUERY_STRING']));
    if ($zzzz) {
    if ((strpos($zzzz, '<') !== false) ||
    (strpos($zzzz, '>') !== false) ||
    (strpos($zzzz, '"') !== false) ||
    (strpos($zzzz, './') !== false) ||
    (strpos($zzzz, '../') !== false) ||
    (strpos($zzzz, '\'') !== false) ||
    (strpos($zzzz, '.pl') !== false) ||
    (strpos($zzzz, '.php') !== false)) 
    {
    die("Попытка ХАКА !");
    }
    }
    $zamena_b = array( "\x27", "\x22", "\x60", "\t",'\n','\r', '\\', "'","¬","#",";","~","[","]","{","}","=","-","+",")","(","*","&","^","%","$","<",">","?","!",".pl", ".php",'"' );
    $_GET = str_replace($zamena_b, '', $_GET);
    $_POST = str_replace($zamena_b, '', $_POST);
    $_SESSION = str_replace($zamena_b, '', $_SESSION);
    $_COOKIE = str_replace($zamena_b, '', $_COOKIE);
    $_ENV = str_replace($zamena_b, '', $_ENV);
    $_FILES = str_replace($zamena_b, '', $_FILES);
    $_REQUEST = str_replace($zamena_b, '', $_REQUEST);
    $_SERVER = str_replace($zamena_b, '', $_SERVER);
    ?>

    Просторы интернета богаты... Так вот люди работают с СУБД

    nethak, 30 Июня 2011

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