1. Куча / Говнокод #1686

    +62.7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    class UglyColumnsRedefine < ActiveRecord::Migration
      def self.up
        change_column :variable_sets, :active, :boolean
        VariableSet.all.each{|v| v.update_attribute :active, !!v.active}
      end
    
      def self.down
      end
    end

    Миграция с весёлым названием 20090601130619_ugly_columns_redefine.rb, для рельсового приложения, аля "так делать низя".

    NoName, 26 Августа 2009

    Комментарии (1)
  2. Python / Говнокод #1685

    −105.1

    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
    def init_images():
        rect  = [[0,0],[0,0],[0,0],[0,0],[0,0]]
        image = [[0,0],[0,0],[0,0],[0,0],[0,0]]
        
        rect[0][0], image[0][0]=load_image('box.png')
        rect[0][1], image[0][1]=load_image('box.png')
        
        rect[1][0], image[1][0]=load_image('fpoint.png')
        rect[1][1], image[1][1]=load_image('freefpoint.png')
        
        rect[2][0], image[2][0]=load_image('spoint.png')    
        rect[2][1], image[2][1]=load_image('freespoint.png')
        
        rect[3][0], image[3][0]=load_image('fbox.png')
        rect[3][0], image[3][0]=load_image('fbox.png')
        
        rect[4][0], image[4][0]=load_image('sbox.png')
        rect[4][1], image[4][1]=load_image('sbox.png')
        
        return image, rect

    Процедура загрузки изображений. Т.к. программа писалась через силу (мозги не работали), получались вот такие жуткие куски кода...

    algor_1, 25 Августа 2009

    Комментарии (4)
  3. JavaScript / Говнокод #1684

    +158.8

    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
    function h_circle_1_view() {
    	document.getElementById("circle_1").style.display = "block";
    	document.getElementById("circle_2").style.display = "none";
    	document.getElementById("circle_3").style.display = "none";
    	document.getElementById("circle_4").style.display = "none";
    	document.getElementById("circle_5").style.display = "none";
    	}
    	function h_circle_1_none() {
    	document.getElementById("circle_1").style.display = "none";
    	}
    	
    	function h_circle_2_view() {
    	document.getElementById("circle_1").style.display = "none";
    	document.getElementById("circle_2").style.display = "block";
    	document.getElementById("circle_3").style.display = "none";
    	document.getElementById("circle_4").style.display = "none";
    	document.getElementById("circle_5").style.display = "none";
    	}
    	function h_circle_2_none() {
    	document.getElementById("circle_2").style.display = "none";
    	}
    	
    	function h_circle_3_view() {
    	document.getElementById("circle_1").style.display = "none"; 
    	document.getElementById("circle_2").style.display = "none"; // прячем 1, 2
    	document.getElementById("circle_3").style.display = "block";	// показываем 3
    	document.getElementById("circle_4").style.display = "none";
    	document.getElementById("circle_5").style.display = "none";
    	}
    	function h_circle_3_none() {
    	document.getElementById("circle_3").style.display = "none";
    	}
    	
    	function h_circle_4_view() {
    	document.getElementById("circle_1").style.display = "none"; 
    	document.getElementById("circle_2").style.display = "none"; 
    	document.getElementById("circle_3").style.display = "none"; // прячем 1, 2
    	document.getElementById("circle_4").style.display = "block";	// показываем 3
    	document.getElementById("circle_5").style.display = "none";
    	}
    	function h_circle_4_none() {
    	document.getElementById("circle_4").style.display = "none";
    	}
    	
    	function h_circle_5_view() {
    	document.getElementById("circle_1").style.display = "none"; 
    	document.getElementById("circle_2").style.display = "none"; 
    	document.getElementById("circle_3").style.display = "none"; // прячем 1, 2
    	document.getElementById("circle_4").style.display = "none";	// показываем 3
    	document.getElementById("circle_5").style.display = "block";
    	}
    	function h_circle_5_none() {
    	document.getElementById("circle_5").style.display = "none";
    	}

    Натолкнулся вот при тестировании одного проекта

    Abductio, 25 Августа 2009

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

    +153

    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
    while(true)  // Последующие недели.
            {
                for($i = 0; $i < 7; $i++)
                {
                    if($this->date_count > $this->all_days)
                        break;
                    else
                    {
                        $this->calendar_table[$this->week_counter][$i] = $this->date_count;
                        $this->date_count++;
                    }
                }
                if($this->date_count > $this->all_days)
                    break;
                $this->week_counter++;
            }

    Заполнение массива с датами для календаря после первой недели...

    Grockles, 25 Августа 2009

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    class DbSimple_Generic_Database extends DbSimple_Generic_LastError
    {
    ...
        /**
         * Virtual protected methods
         */
        function ____________PROTECTED() {} // for phpEclipse outline
    ...
    }

    ой какая красотень у нас будет в аутлайне теперь...

    Smoke, 25 Августа 2009

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

    +130

    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
    public static LanguageConfiguration GetLanguageByUrl()
            {
                string requestHost = HttpContext.Current.Request.Url.Host.ToLower();
    
                foreach (LanguageConfiguration language in languages.Values)
                  foreach (DomainConfiguration domain in language.Domains)
                        if (domain.Name.Equals(requestHost))
                            return language;
                
                return languages[LanguageCodes[0]];
            }
    
            public static List<string> LanguageCodes
            {
                get
                {
                    //caching languages
                    if (languages == null)
                    {
                        languages = new Dictionary<string, LanguageConfiguration>();
                        if (languagesConfiguration.Languages.Count > 0)
                            foreach (LanguageConfiguration language in languagesConfiguration.Languages)
                                languages.Add(language.Code, language);
                        else
                            languages.Add(String.Empty, new LanguageConfiguration());
                    }
                    return  new List<string>(languages.Keys);
                }
            }

    "Сначала отрежь, потом отмерь".

    Cyxapb, 25 Августа 2009

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

    +50

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    int i, j;
    for (i = j = 0; i < 4; i++)
    	if (frame & (0x8 >> i))
    	{
    		if (i < 2 && p.value < double(frames1[j]) && !(i && j) ||
    			i > 1 && p.value > double(frames1[j]))
    			p.value.attr = 1 + i;
    		j++;
    	}

    Как вам цикл до 4 с тремя проверками на значение счётчика? :)

    Dimarius, 25 Августа 2009

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

    +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
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    $id_country = 0;
    $id_region = 0;
    $id_city = 0;
    $zip_code = 0;
    if(isset($_REQUEST["id_country"]))
    {
        $id_country=$_REQUEST["id_country"];
    }
    if(isset($_REQUEST["id_region"]))
    {
        $id_region=$_REQUEST["id_region"];
    }
    if(isset($_REQUEST["id_city"]))
    {
        $id_city=$_REQUEST["id_city"];
    }
    if(isset($_REQUEST["zip_code"]))//проверка zip кода
    {
        $zip_code=$_REQUEST["zip_code"];
    }
    
    $id_country=strip_tags(trim(strval($_REQUEST["id_country"])));
    $id_region=strip_tags(trim(strval($_REQUEST["id_region"])));
    $id_city=strip_tags(trim(strval($_REQUEST["id_city"])));
    $zip_code=strip_tags(trim(strval($_REQUEST["zip_code"])));
    
    ..........................
    //переходим на Шаг 2 решистрации
    header("location: ./registration.php?sel=2");
    ..........................

    Индусы среди нас!

    Bartelby, 25 Августа 2009

    Комментарии (22)
  9. PHP / Говнокод #1678

    +150.9

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    //$arr - array with arbitrary keys
    
    end($arr);
    do {
           if( <some condition> ) {
                <something of no importance>
                unset($arr[key($arr)]);
            }
            else {
                <something of no importance>
            } 
    } while( prev($arr) !== false );

    Предполагалось, что на входе будет непустой массив. Потом он будет пролистан с конца (это необходимо) и из него по некоторому условию исключаются элементы. При этом после первого исключения итератор оказывается вне массива и prev() возвращает false (в самом массиве false не размещён заведомо).

    interested, 25 Августа 2009

    Комментарии (1)
  10. C++ / Говнокод #1677

    +47.9

    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
    IsSimpleAssign = ( !isIfWhileForReturn&&
                        ( _currString->ecoString )->IsAtOncePresent( equalsSign )&&
                        ( _currString->ecoString )->IsAtOncePresent( star ) &&
                        ( _currString->ecoString )->IsAtOncePresent( amper ) &&
    
                        ( ( ( _currString->ecoString )->GetCharPos( amper ) <
                        ( _currString->ecoString )->GetCharPos( star ) ) ||
                        ( ( _currString->ecoString )->GetCharPos( amper ) >
                        ( _currString->ecoString )->GetCharPos( star ) ) ) &&
    
                        ( ( ( _currString->ecoString )->GetCharPos( equalsSign ) <
                        ( _currString->ecoString )->GetCharPos( star ) ) &&
                        ( ( _currString->ecoString )->GetCharPos( amper ) <
                        ( _currString->ecoString )->GetCharPos( equalsSign ) )
    
                        ||
                        ( ( _currString->ecoString )->GetCharPos( equalsSign ) >
                        ( _currString->ecoString )->GetCharPos( star ) ) &&
                        ( ( _currString->ecoString )->GetCharPos( amper ) >
                        ( _currString->ecoString )->GetCharPos( equalsSign ) ) )
    
                        );

    где-то в недрах рукописного парсера

    gilya, 25 Августа 2009

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