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

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    header('Content-Type: text/plain; charset=windows-1251'); // текстовый формат... что бы переносы строки нормально отображались и ширина букв была одинаковая
    
    function CheckDir($s,$step)
    {
            echo str_repeat('-',$step).basename($s)."\r\n"; 
            $a = glob($s.'/*',GLOB_ONLYDIR);
            foreach($a as $v)
            {
                    CheckDir($v,$step+1); 
            }
    }

    qbasic, 16 Марта 2011

    Комментарии (3)
  2. Си / Говнокод #5997

    +105

    1. 1
    int c = ((i-(i%(int)pow(10,p)))/(int)pow(10,p))%10;

    Выделение из числа I цифры, стоящей на месте P с конца.
    =>
    i = 1234, p = 2, c => 2

    danilissimus, 16 Марта 2011

    Комментарии (24)
  3. PHP / Говнокод #5996

    +167

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public function generateGUID ()
      {
          $GUID = $this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter()."-";
          $GUID = $GUID.$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter()."-";
          $GUID = $GUID.$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter()."-";
          $GUID = $GUID.$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter()."-";
          $GUID = $GUID.$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter();
          return $GUID;
      }

    из класса для работы с paypal. (скачан с оффсайта)

    newmindcore, 16 Марта 2011

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

    +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
    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
    function price_filter_form()
    {
        // Хуярим неиибически сложную систему фильтрации по цене:
        $sql = "
    SELECT
    Max(c_good.price) AS `max`,
    Min(c_good.price) AS `min`,
    Count(c_good.price) AS `count`
    FROM
    c_good
    WHERE
    c_good.podcat_id =  '".mysql_real_escape_string($_GET['id'])."' AND
    c_good.onoff =  '1' AND c_good.`check` = '1'";
        $sql = mysql_query($sql) OR DIE (log_error('sql'));
        $price = mysql_fetch_assoc($sql);
        #echo ("<pre>");
        #print_r($price);
        #echo ("</pre>");
        if ($price['count'] < '10') // если товаров меньше 10, выводим 1 диапазон цен
        {
         $price_form = "<option value=\"".$price['min'].":".$price['max']."\">".$price['min']."-".$price['max']."руб.</option>";    
        }
        else
        {
            // Далее идёт непонятный говнокод, который к удивлению работает
            $step = (($price['max']-$price['min'])/11);
            $step = ceil($step);
            $step_len = strlen($step);
            $step = round($step, -($step_len-1));
            $first_step = ($price['min']+$step);
            $first_step_len = strlen($first_step);
            $first_step = (round($first_step, -($first_step_len-2))-1);
            #if ($first_step < $price['min']) $first_step = $price['min']+$step;
            $price_form = "<option value=\"".$price['min'].":".$first_step."\">".$price['min']."-".$first_step."руб.</option>";
            $price_form .= "<option value=\"".($first_step+1).":".($first_step+$step)."\">".($first_step+1)."-".($first_step+$step)."руб.</option>";
            
            #echo $step;
            for ($i=1;$i<8;$i++)
            {
             $price_form .= "<option value=\"".($first_step+($step*$i)+1).":".($first_step+($step*($i+1)))."\">
             ".($first_step+($step*$i)+1)."-".($first_step+($step*($i+1)))."руб.</option>";    
            }
            $price_form .= "<option value=\"".($first_step+($step*8)+1).":".$price['max']."\">
            ".($first_step+($step*8)+1)."-".$price['max']."руб.</option>";
        }
        $price_form = str_replace("\"".$defult_price['1']."\"", "\"".$defult_price['1']."\" selected", $price_form);
        return $price_form;
    }
    ?>

    вот с таким ГК пришлось столкнуться, после профилирования. Как Вам? Или - это нормально для PHP???
    P.S. комментарии сохранены авторские.

    ZeiZ, 16 Марта 2011

    Комментарии (3)
  5. PHP / Говнокод #5994

    +161

    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
    elseif(isset($_GET['del']))
    {
        foreach($_POST as $id=>$a)
        {
            mysql_query("DELETE FROM `{$prefixbd}$table` WHERE `id`='".intval($id)."'")or die(mysql_error());
            @chmod(ret_img($file_path.$id),0777);
            @unlink(ret_img($file_path.$id));
            @chmod(ret_img($file_path.$id.'_big'),0777);
            @unlink(ret_img($file_path.$id.'_big'));
            $sql=mysql_query("SELECT FROM `{$prefixbd}{$table}_img` WHERE `prod`='".intval($id)."'")or die(mysql_error());
            while($data=mysql_fetch_assoc($sql)){
                @chmod(ret_img($file_path.$id.'_'.$data['id'].'_add'),0777);
                @unlink(ret_img($file_path.$id.'_'.$data['id'].'_add'));
                @chmod(ret_img($file_path.$id.'_big_'.$data['id'].'_add'),0777);
                @unlink(ret_img($file_path.$id.'_big_'.$data['id'].'_add'));
                mysql_query("DELETE FROM `{$prefixbd}{$table}_img` WHERE `id`='".$data['id']."'");
            }
        }

    Обратите внимание как удаляет файлы)) исходник из некого chrono CMS

    dobs2005, 16 Марта 2011

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

    +126

    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
    Type window = core.getTypeCreationWindowFromType( this.currentType );
                if (window != null)
                {
                    var cr_window = Activator.CreateInstance( window );
                    if (window == typeof( forms.showWindow ))
                    {
                        ((forms.showWindow)cr_window).setTitle( "Добавить новую позицию" );
                        ((forms.showWindow)cr_window).setType( this.chldrenType );
                        ((forms.showWindow)cr_window).fill( );
                        ((forms.showWindow)cr_window).setSelectionMode( );
                        if (this.isExlusivePositionResolve == true) 
                        {
                            // var new_item = Activator.CreateInstance( this.chldrenType );
                            //new_item = (types.ICovertiablePersist<this.chldrenType>)core.instance().ge
    
                            ((forms.showWindow)cr_window).selectedItem += ( forms.showWindow form ) =>
                            {
                                var new_item = Activator.CreateInstance( this.chldrenType );
                                ///new_item = core.instance().getObject(this, form.selected_id);
    
                                int parent_object_id = -1; // Это номер связанного с 
                                                           //выриьбаемым обектом объекта, 
                                                           //тоесть если окно выбора было 
                                                           //кастомизированна и тип выбираемы 
                                                           //х щзначений другой нежели целевой 
                                                           //то мы ищем звязь между обектом ородите и дитя !!!
                                FieldInfo[] fields = this.chldrenType.GetFields( );
                                
                                int id = ((types.persistent)new_item).id;
                                bool isExists = false;
                                for (int i = 0; i < this.dgv_grid.RowCount; i++) 
                                {
                                    int id_s;
                                    int.TryParse( this.dgv_grid.Rows[i].Cells["id"].Value.ToString( ),out id_s );
                                    if (id_s == id) 
                                    {
                                        int count;
                                        int.TryParse( this.dgv_grid.Rows[i].Cells["count"].Value.ToString( ), out count );
                                        this.dgv_grid.Rows[i].Cells["count"].Value = count++;
                                        isExists = true;
                                    }
                                }
                                if (isExists == false) 
                                {
                                    this.addOnePosition( new_item );
                                }
                            };
                        }
                    }
                    else 
                    {
                        ((Form)cr_window).FormClosed += ( object sender, FormClosedEventArgs e ) => {
                            this.fill( );
                        };                   
                    }
                    ((System.Windows.Forms.Form)cr_window).Show( );
                }
                else
                {
                    MessageBox.Show( "Объекты такого типа создавать запрещено" );
                }

    Нашел его миленкого. Переписываю ))) А коменн то комент

    glilya, 15 Марта 2011

    Комментарии (20)
  7. Pascal / Говнокод #5992

    +119

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    Function F1(z: Byte): Real;  {Функция возведения (-1) в степень "к"}
    
      Begin
    
        If z=1
    
          Then F1:=-1
    
          Else F1:=F1(z-1)*-1;
    
      End;

    Нашел в лабораторной по вычмату 2-х годичной давности)

    1_and_0, 15 Марта 2011

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    ...
    $tlang->description = "Русский";
    $tlang->filename = "russian.php";
    $tlang->template_path = 'newtpl'; // Какой идиот придумал хранить настройки шаблонов в языках???
    ...

    Кусок из шоп скрипт... ивправду какого хрена так делать - загадка...

    dobs2005, 15 Марта 2011

    Комментарии (9)
  9. Си / Говнокод #5990

    +127

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    [code=Си]
    switch(n)
    case 1:
    {
      /* code1 */
      /* fallthrough */
      case 2:
      /* code 2 */
    }
    [/code]

    Все имена и явки изменены!
    Сцуко, работает. Щас в стандарт полезу, интересно же! Обвиняют меня, я киваю на издержки мержа. Но смешно.

    nil, 15 Марта 2011

    Комментарии (17)
  10. JavaScript / Говнокод #5989

    +160

    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
    function antispam()
    {
    var num1=Math.floor(Math.random()*11)+1;
    var num2=Math.floor(Math.random()*11)+1;
    var sum = num1+num2;
    var userP = prompt("To check that you are not spammer, solve this simple equation - "+num1+"+"+num2+"=?","");
    if (userP != null)
    {
    if (userP != sum) 
    {
    document.write("<!--");
    alert("Wrong answer!");
    } 
    else 
    {
    document.write('<form id="logform" action="proceed.php" onsubmit="javascript:return validate("logform","email");" method="post"><p>Your name: <input type="text" name="name" /></p><p>Your password: <input type="password" name="password" /></p><p>Your e-mail: <input type="text" name="email" id="email" /></p><p><input type="submit" value="Register!" /></p></form>');
    }
    }
    }

    Вот в таком режиме работает уже месяца два. Если не ГК, прошу, посоветуйте как можно это лучше сделать (или прикрутить капчу и не парится? :)). На JS я практически не пишу, я пишу в основном под .NET.

    RaZeR, 15 Марта 2011

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