1. C++ / Говнокод #8276

    +997

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    list<int> l;
    //...
    for(int i=0;i<l.size();++i)
    {
     auto it=l.begin();
     advance(it, i);
     int item=*it;
     //...

    AnimeGovno-_-, 22 Октября 2011

    Комментарии (74)
  2. JavaScript / Говнокод #8275

    +163

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    Электронная почта (e-mail) - если указано, то проверяем корректность
    
    p_email = document.myform.email.value.toString();
    if (p_email != "") {
    t = p_email.indexOf("@");
    if((p_email.indexOf(".") == -1) || (t == -1) || (t < 1) || (t > p_email.length - 5) || (p_email.charAt(t - 1) == '.') || (p_email.charAt(t + 1) == '.')) {
    alert("Некорректно указан E-mail !");
    document.myform.email.focus();
    return false;
    }
    }

    http://www.whatis.ru/razn/razn14.shtml

    denis90, 22 Октября 2011

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

    +80

    1. 1
    2. 2
    3. 3
    4. 4
    getBtnContent().setEnabled(enable);
    if (getGridConfig().isContentEnabled()) {
           getBtnContent().setEnabled(enable);
    }

    Программист со стажем, всегда хочет быть уверен что кнопка будет доступна на 150%

    pvtPyle, 22 Октября 2011

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

    +116

    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
    <Grid Grid.Row="2" Margin="5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <ContentPresenter Grid.Row="0" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[0]}"/>
                <ContentPresenter Grid.Row="0" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[1]}"/>
                <ContentPresenter Grid.Row="0" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[2]}"/>
                <ContentPresenter Grid.Row="1" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[3]}"/>
                <ContentPresenter Grid.Row="1" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[4]}"/>
                <ContentPresenter Grid.Row="1" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[5]}"/>
                <ContentPresenter Grid.Row="2" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[6]}"/>
                <ContentPresenter Grid.Row="2" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[7]}"/>
                <ContentPresenter Grid.Row="2" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[8]}"/>
                <ContentPresenter Grid.Row="3" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[9]}"/>
                <ContentPresenter Grid.Row="3" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[10]}"/>
                <ContentPresenter Grid.Row="3" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[11]}"/>
                <ContentPresenter Grid.Row="4" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[12]}"/>
                <ContentPresenter Grid.Row="4" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[13]}"/>
                <ContentPresenter Grid.Row="4" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[14]}"/>
                <ContentPresenter Grid.Row="5" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[15]}"/>
                <ContentPresenter Grid.Row="5" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[16]}"/>
                <ContentPresenter Grid.Row="5" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[17]}"/>
                <ContentPresenter Grid.Row="6" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[18]}"/>
                <ContentPresenter Grid.Row="6" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[19]}"/>
                <ContentPresenter Grid.Row="6" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[20]}"/>            
            </Grid>

    legat, 22 Октября 2011

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

    +141

    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
    char *zamena(int m)
     {
       char *s;
       int a,b,c;
       a = m / 100;
       b=(m / 10)% 10;
       c=m % 10;
       if (a>0)
       switch (a)   
       {
        case 1: s=s+"сто ";
        case 2: s=s+"двести ";
        case 3: s=s+"триста ";
        case 4: s=s+"четыреста ";
        case 5: s=s+"пятьсот ";
        case 6: s=s+"шестьсот ";
        case 7: s=s+"семьсот ";
        case 8: s=s+"восемьсот ";
        case 9: s=s+"девятьсот ";
       }
       if (b==1) 
        switch (c)
       {
        case 1: s=s+"одиннадцать ";
        case 2: s=s+"двенадцать ";
        case 3: s=s+"тринадцать ";
        case 4: s=s+"четырнадцать ";
        case 5: s=s+"пятнадцать ";
        case 6: s=s+"шестнадцать ";
        case 7: s=s+"семнадцать ";
        case 8: s=s+"восемнадцать ";
        case 9: s=s+"девятнадцать ";
       }
       else
        switch (b)
       {
        case 2: s=s+"двадцать ";
        case 3: s=s+"тридцать ";
        case 4: s=s+"сорок ";
        case 5: s=s+"пятьдесят ";
        case 6: s=s+"шестьдесят ";
        case 7: s=s+"семьдесят ";
        case 8: s=s+"восемьдесят ";
        case 9: s=s+"девяносто ";
       }
       if (b!=1 && c>0) 
        switch (c)
       {
        case 1: s=s+"один ";
        case 2: s=s+"два ";
        case 3: s=s+"три ";
        case 4: s=s+"четыре ";
        case 5: s=s+"пять ";
        case 6: s=s+"шесть ";
        case 7: s=s+"семь ";
        case 8: s=s+"восемь ";
        case 9: s=s+"девять ";
       }
       return s;
     }

    Перевод целого числа в строку.

    Proger, 22 Октября 2011

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

    +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
    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
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    $searchCondition1 = ''; 
     $searchCondition2 = ''; 
     $searchCondition3 = ''; 
     $flag = false; 
     $sql = 'SELECT f.flight_id,
                   (SELECT city
                    FROM airports
                    WHERE airport_id = f.from) as _from,
                   (SELECT city
                    FROM airports
                    WHERE airport_id = f.to) as _to,
                    f.flight_date as fdate,
                    f.flight_time,
                    f.distance,
                    p.plain_name as plain
            FROM flight f JOIN planes p
                ON f.plain_id = p.plain_id
            WHERE '; 
     $fields = 0; 
     if($_POST['txtSearch']){ 
         if($_POST['txtFrom'] != ''){ 
             $searchCondition1 = " city = '".$_POST['txtFrom']."'"; 
             $flag = true; // set flag to TRUE
             $fields++; 
         }
         if($_POST['txtTo'] != ''){ // if To field is not empty
             $searchCondition2 = " city = '".$_POST['txtTo']."'"; 
             $flag = true;  // set flag to TRUE
             $fields++; 
         }
         if ($_POST['txtDate'] != ''){ // if Date field is not empty
             $searchCondition3 = " DATE(f.flight_date) = '".$_POST['txtDate']."'";
             $fields++; // and inc 
         }
         if($fields == 0){                             
             echo "<br/><div style=\"color:red\">Please, enter at least one filed to search</div>"; 
         }else{ 
             if($searchCondition1 != '' && $searchCondition2 == ''){ 
             $sql .= " f.from IN (SELECT airport_id
                                        FROM airports
                                        WHERE ".$searchCondition1.")"; 
             }
             if($searchCondition1 == '' && $searchCondition2 != ''){ 
                 $sql .= " f.to IN (SELECT airport_id
                                            FROM airports
                                            WHERE ".$searchCondition2.")"; 
             }                                                              
             if($searchCondition1 != '' && $searchCondition2 != ''){ 
                 $sql .= " f.from IN (SELECT airport_id
                                            FROM airports
                                            WHERE ".$searchCondition1.")
                                 AND f.to IN (SELECT airport_id
                                            FROM airports
                                            WHERE ".$searchCondition2.")"; 
             }
             if($searchCondition3 != ''){ 
                 if($flag){ 
                     $sql .= " AND ".$searchCondition3; 
                 }else{
                     $sql .= $searchCondition3; 
                 }
    
             }
             include_once('database.php'); 
             $db = createPDO();
             $result = $db->query($sql);
             echo '<table>
                  <tr>
                    <th>
                        From
                    </th>
                    <th>
                        To
                    </th>
                    <th>
                        Flight Date
                    </th>
                    <th>
                        Flight Time
                    </th>
                    <th>
                        Distance
                    </th>
                    <th>
                        Plane
                    </th>
                    <th>
                        Action
                    </th>
                </tr>'; // create an HTML table with headers
             while($row = $result->fetch()){...}

    Ищем в табличке в зависимости от заполненных полей в форме

    denis90, 22 Октября 2011

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

    +162

    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
    template <
    	typename PropertyOwner // Класс владельца
    >
    class properties {
    public:
    	// Получить указатель на владельца по указателю на свойство
    	static PropertyOwner * owner( void * property ) { 
    		int aai = (int)&(((PropertyOwner*)0)->__properties);
    		return (PropertyOwner *)((char*)property - aai);
    	}
    };
     
    /**
     * Шаблон класса свойства
     */
    template <
    	typename PropertyOwner, // Класс владельца
    	typename PropertyType, // Тип свойства
    	PropertyType (PropertyOwner::*getter)(), // Геттер
    	void (PropertyOwner::*setter)(PropertyType) > // Сеттер
    class property {
    public:
     
    	/**
    	 * Чтение свойства - вызов геттера
    	 */
    	operator PropertyType() {
    		return (properties<PropertyOwner>::owner( this )->*getter)();
    	}
     
    	/**
    	 * Запись в свойство - вызов сеттера
    	 */
    	void operator = ( const PropertyType & value ) {
    		(properties<PropertyOwner>::owner( this )->*setter)( value );
    	}
    };
     
    // Макросы для удобного определения свойств /////////
     
    /**
     * Начать объявления свойств в классе cls
     */
    #define properties_start(cls) union { properties<cls> __properties;
     
    /**
     * Закончить объявление свойств в классе cls
     */
    #define properties_end() };
     
    /**
     * Объявить свойство в классе cls типа type c геттером getter и сеттером setter
     */
    #define property(cls,type,getter,setter) property<cls,type,&cls::getter,&cls::setter>

    http://www.codenet.ru/progr/cpp/cpp-properties.php

    AnimeGovno-_-, 22 Октября 2011

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

    −99

    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
    # Work fine only on call with has_many association
    def self.new_from_params options
      new_rule = Rule.new
      return nil if new_rule.project_id.nil?
    
      rule = Rule.find_by_id options[:rule_id]
      if rule.nil? or (new_rule.project.id != rule.project.id)
        rule = Rule.new
      end
    
      new_rule.rule_id = options[:rule_id]
      new_rule.users = (rule.users.to_a + options[:users].to_a).uniq
      new_rule.statuses = (rule.statuses.to_a + options[:statuses].to_a).uniq
      new_rule.tags = (rule.tags.to_a + options[:tags].to_a).uniq
      new_rule.grouped_by = options[:grouped_by].presence || rule.grouped_by.presence
      new_rule.sorted_by = options[:sorted_by].presence || rule.sorted_by.presence
      new_rule.search = options[:search].presence || rule.search.presence
      new_rule.period_start = options[:period_start].presence || rule.period_start.presence
      new_rule.period_end = options[:period_end].presence || rule.period_end.presence
    
      new_rule
     end

    emerald, 21 Октября 2011

    Комментарии (5)
  9. ActionScript / Говнокод #8268

    −111

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public function cloneString(str:String):String {
    			if(str == null) return null;
    			_byteArray.position = 0;
    			_byteArray.writeUTF(str);
    			_byteArray.position = 0;
    			var res:String =  _byteArray.readUTF();
    			// fuck yeah!
    			return res;
    		}

    суровые сибирские программисты клонируют строки like a pro

    makc3d, 21 Октября 2011

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

    +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
    ...
    
      public function getLocations($fresh = 0)
        {
            $tld =& $this->varGet('tld');
            $domain =& $this->varGet('domain');
            
            // if website is viewed via IP
            $noWWWButIP =& $this->varGet('noWWWButIP');
    
            $memCacheKey = 'getLocations';
    
            if (!$fresh) {
                // already fetched and stored in vars?
                if (is_array($this->varGet('arrLocations')))
                    $arrLocations = $this->varGet('arrLocations');
                // lets try fetching from memcache
                else
                    $arrLocations = kd()->lib('kdCache')->get($memCacheKey);
            }
            // regenerate
            unset($arrLocations);
    
            if (!is_array($arrLocations)) {
    ...

    Кэшируем))

    kovel, 21 Октября 2011

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