1. Лучший говнокод

    В номинации:
    За время:
  2. PHP / Говнокод #6238

    +184

    1. 1
    BLOG_BLOG_BLOG_NO_BLOG

    Константа в 1C-Bitrix.

    Баден-Баден отдыхает.

    maxru, 05 Апреля 2011

    Комментарии (17)
  3. C# / Говнокод #6125

    +115

    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
    columnDomain.Visible =
     (grid.MainView.RowCount >
    0
    &&
     !String.IsNullOrEmpty(
         ((ListItem)
      grid.MainView.
         GetRow(0)).Domain)
    &&
      ((ListItem)
     grid.MainView.GetRow(0))
          .Domain !=
     ((ListItem)
     grid.MainView.GetRow(0))
         .DisplayName);

    Это реальное форматирование кода, очевидно сделанное для удобства чтения на узком и высокои мониторе :) И такого многие и многие экраны

    eval_2009, 29 Марта 2011

    Комментарии (17)
  4. ActionScript / Говнокод #6098

    −103

    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
    public static function trimExtraLineBreaks(string:String):String
    {
    	var trimmedString:String = string;
    
    	for(var i:int = 0; i < 20; i++)
    	{
    		trimmedString = trimmedString.replace(new RegExp("\r\r","g"),"\r");
    		trimmedString = trimmedString.replace(new RegExp("\r\n","g"),"\r");
    		trimmedString = trimmedString.replace(new RegExp("\n\n","g"),"\n");
    		trimmedString = trimmedString.replace(new RegExp("\n\r","g"),"\n");
    		trimmedString = trimmedString.replace(new RegExp("\n ","g"),"\n");
    		trimmedString = trimmedString.replace(new RegExp("\r ","g"),"\n");
    		trimmedString = trimmedString.replace(new RegExp(" \n","g"),"\n");
    		trimmedString = trimmedString.replace(new RegExp(" \r","g"),"\n");
    	}
    
    	return trimmedString;
    }

    Натолкнулся на просторах github'а во время поиска чего-то там... Ей богу сразу забыл, что искал.

    fljot, 27 Марта 2011

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

    +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
    <?php
    
    function test_menu() {
    //  $menu['test'] = array(
    //    'page callback' => 'test_page',
    //    'access callback' => TRUE,
    //  );
    
      $menu['test/%user_uid_optional'] = array(
        'page callback' => 'test_view',
        'page arguments' => array(1),
        'access callback' => 'test_access',
        'access arguments' => array(1),
      );
    
      $menu['test/%user/view'] = array(
        'title' => 'View',
        'type' => MENU_DEFAULT_LOCAL_TASK,
        'weight' => -10,
      );
    
      $menu['test/%user/edit'] = array(
        'title' => 'Edit',
        'page callback' => 'test_edit',
        'page arguments' => array(1),
        'access callback' => 'test_access',
        'access arguments' => array(1),
        'type' => MENU_LOCAL_TASK,
      );
    
      return $menu;
    }
    
    function test_page() {
      global $user;
      if ($user->uid) {
        menu_set_active_item("test/$user->uid");
        return menu_execute_active_handler();
      }
      else {
        drupal_goto('user/login');
      }
    }
    
    function test_view($account) {
      module_load_include('pages.inc', 'user');
      return user_view($account);
    }
    
    function test_edit($account) {
      module_load_include('pages.inc', 'user');
      return user_edit($account);
    }
    
    function test_access($account) {
      dpm($account);
      return TRUE;
    }

    vectoroc, 25 Марта 2011

    Комментарии (17)
  6. Си / Говнокод #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)
  7. C++ / Говнокод #5974

    +167

    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
    float ArenaTeam::GetChanceAgainst(uint32 own_rating, uint32 enemy_rating)
    {
        // returns the chance to win against a team with the given rating, used in the rating adjustment calculation
        // ELO system
       // return 1.0f/(1.0f+exp(log(10.0f)*(float)((float)enemy_rating - (float)own_rating)/400.0f));
    	float a,b;
    
    	a = own_rating;
    	b = enemy_rating;
    
    		 if(a<1800 && b<1800) return 16;
    		 if(a>=1800 && a<2000 && b<2000 || b>=1800 && b<2000 && a<2000) return 15;
    		 if(a>=2200 && b>=2200) return 15;
    	if(a>b){
    		 if(a>=2000 && a<2100 && b>=2100 && b<2200) return 17;
    		 if(a>=2000 && a<=2100 && b>=2200) return 18;
    		 if(b>=2000 && b<2100 && a>=2200) return 9;
    		 if(a>=2000 && a<2100 && b>=2000 && b<2100) return 15;
    		 if(a>=2100 && a<2200 && b>=2100 && b<2200) return 15;
    		 if(a>=2100 && a<2200 && b>=2200) return 16;
    		 if(b>=2100 && b<2200 && a>=2200) return 11;
    		 if (a>=2000 && a<2100 && b >=1850) return 10;
    		 if (a>=2000 && a<2100 && b <=1850) return 5;
    		 if (a>=2100 && a<=2200 && b >=1950 && b <2000) return 9;
    		 if (a>=2100 && a<=2200 && b >=1900 && b <2000) return 7;
    		 if (a>=2100 && a<=2200 && b >=2000 && b <2100) return 11;
    		 if (a>=2100 && a<2200 && b <=1900 && b >=1750) return 4;
    		 if (a>=2100 && a<2200 && b <1750) return 3;
    		 if (a>=2200 && b >=1950 && b <=2000) return 4;
             if (a>=2200 && b <=1950 && b>=1800) return 2;
    		 if (a>=2200 && b <=1850) return 1;
    		 if(a>=1500 && a<1600 && b >=2200) return 31;
    		 if(a>=1500 && a<1600 && b>=2000 && b <2100) return 28;
    		 if(a>=1500 && a<1600 && b>=2100 && b<2200) return 29;
    		 if(a>=1500 && a<1600 && b>=2100 && b>2200) return 31;
    		 if (a>=1900 && a<2000 && b>=2000 && b<= 2075) return 18;
    		 if (a>=1900 && a<2000 && b>=2075 && b<= 2150) return 24;
    		 if (a>=1900 && a<2000 && b>=2150 && b<= 2200) return 25;
    		 if (a>=1900 && a<2000 && b>=2150 && b> 2200) return 27;
    		 if (a>=1800 && a<1900 && b>=2000 && b<= 2075) return 22;
    		 if (a>=1800 && a<1900 && b>=2075 && b<= 2150) return 27;
    		 if (a>=1800 && a<1900 && b>=2150 && b<= 2200) return 29;
    		 if (a>=1800 && a<1900 && b>=2150 && b> 2200) return 30;
    		 if (a>=1600 && a<1800 && b>=2000 && b<= 2075) return 22;
    		 if (a>=1600 && a<1800 && b>=2075 && b<= 2150) return 28;
    		 if (a>=1600 && a<1800 && b>=2150 && b<= 2200) return 29;
    		 if (a>=1600 && a<1800 && b>=2150 && b> 2200) return 30;
    		 if(a<1500 & b>=2000) return 31;
    	}else{
                     // same just b instead of a and a instead of b
    	}
        
    }

    New developer for wow server ;) Best part is the cast to floats at start imo

    kerhong, 14 Марта 2011

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

    +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
    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
    <?php
    class security extends engine{
        var $temp=array();
    
        function getUserId(){
            $hash=explode('::',$_COOKIE['site_hash']);
            $id=$hash[0];
            return $id;
        }
    
        function getUserSecurityAccess($id){
            if(is_numeric($id)){
                $id=rawurlencode($id);
                $conn_id=mysql_connect('host','user','passwd');
                mysql_select_db('database');
                $q=mysql_query("SELECT groupid FROM `users`
                                WHERE id='".$id."'",$conn_id);
                if($q){
                    if(mysql_numrows($q)!=0){
                        $result=@mysql_fetch_assoc($q);
                        return $result['group_id'];
                    }else{
                        return -1;
                    }
                }else{
                    return -1;
                }
                mysql_close($conn_id);
            }else{
                return -1;
            }
        }
    
        function checkUserPermission($module,$act){
            #return true;
            $this->temp=array();
            $this->temp['_result']=0;
            $this->temp['_uid']=explode('::',$_COOKIE['site_hash']);
            $this->temp['_uid']=$this->temp['_uid'][0];
            $this->temp['_gid']=$this->getUserSecurityAccess($this->temp['_uid']);
            $this->temp['_conn_id']=mysql_connect('host','user','passwd');
            mysql_select_db('database');
            $this->temp['_q1']=mysql_query('SELECT perms'
                            .'FROM `secure_groups`' 
                            .'WHERE id='.$this->temp['_gid']);    
            $this->temp['_access_stamp']=mysql_fetch_assoc($this->temp['_q1']);
            $this->temp['_access_stamp']=$this->temp['_access_stamp']['perms'];
            $this->temp['_access_stamp']=explode(';',$this->temp['_access_stamp']);
            $this->temp['_access_stamp']=array_slice($this->temp['_access_stamp'],0,-1);
            foreach($this->temp['_access_stamp'] as $this->temp['v']){
                $this->temp['_mod_access']=explode(':',$this->temp['v']);
                $this->temp['_mod_indefier']=$this->temp['_mod_access'][0];
                if($this->temp['_mod_indefier']==$module){
                    $this->temp['_perms']=explode(',',$this->temp['_mod_access'][1]);
                    switch($act){
                        case 'r':
                            $this->temp['_result']=($this->temp['_perms'][0]==1)? 1:0;
                            break;
                        case 'w':
                            $this->temp['_result']=($this->temp['_perms'][1]==1)? 1:0;
                            break;
                    }
                    break;
                }
            }
            mysql_close($conn_id);
            return $this->temp['_result'];
        }
    }
    ?>

    Понравилось окончание статьи
    "Надеюсь, что мы скоро встретимся...
    Кто хочет почитать остальные мои статьи - прошу на http://e-code.tnt43.com.
    С уважением Карпенко Кирилл, глава IT-отдела ИНПП. "

    MoLe-X, 12 Марта 2011

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

    +122

    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
    <?php require_once "db_config.php";
     
     class db extends db_config {
     
      private $connection;
      
      function __construct(){
       $this->open_connection();
    //   echo "Соединение установлено ";
      }
      
      private function open_connection(){
       $this->connection=mysql_connect($this->DB_HOST,$this->DB_USER,$this->DB_PASS);
       if (!$this-connection){
        die("Соедитение с базой данных не установлено: ".mysql_error());
       } else {
        $db_select=mysql_select_db($this->DB_NAME);
    	if (!$db_select){
    	 die("База данных не определена: ".mysql_error());
    	}
       }
       mysql_query("set names utf8")or die("set name utf8 failed");
       mysql_query("set lc_time_names=ru_RU");
      }
      
      public function sql($query){
       $result=mysql_query($query,$this->connection);
       if (!result){
        die("Запрос не выполнен: ".mysql_error());
       }
       return $result;
      }
     }
     $db = new db();?>

    Типа сингелтон

    Vasiliy, 10 Марта 2011

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

    +154

    1. 1
    function(&(*(--Iter)++);

    Вот как надо использовать итератор...

    Tirect, 01 Марта 2011

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

    +159

    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
    <?
    			if(($socle == 1302 || $socle == 2723 || $socle == 2723 || $socle == 211) && ($power == 1816 || $power = 1296 || $power = 2741 || $power = 2741 || $power = 216  || $power = 1854))//G9 40W
    				{echo '<br/><a href="/catalog/?id=1&section=2163&dep=12">Купить лампочку: цоколь G9, мощность 40W</a>';}
    			else if(($socle == 1324 || $socle == 2964 || $socle == 212) && ($power == 1826 || $power == 2942 || $power == 1325 || $power == 1861 || $power == 217  || $power == 1734))//GU10 50W
    				{echo '<br/><a href="/catalog/?id=2&section=2163&dep=12">Купить лампочку: цоколь GU10, мощность 50W</a>';}
    			else if(($socle == 2855 || $socle == 1294 || $socle == 2733 || $socle == 1883 || $socle == 1721) && ($power == 1816 || $power = 1296 || $power = 2741 || $power = 2741 || $power = 216  || $power = 1854))//E14 40W
    				{
    				echo '<br/><a href="/catalog/?id=3&section=2163&dep=12">Купить лампочку: цоколь E14, мощность 40W</a><br/>';
    				echo '<br/><a href="/catalog/?id=4&section=4212&dep=12">Купить энергосберегающую лампочку: цоколь E14, мощность 7W</a>';
    				}
    			else if(($socle == 2748 || $socle == 1305 || $socle == 3051 || $socle == 203 || $socle == 1724) && ($power == 1816 || $power = 1296 || $power = 2741 || $power = 2741 || $power = 216  || $power = 1854))//E27 40W
    				{
    				echo '<br/><a href="/catalog/?id=5&section=2162&dep=12">Купить лампочку: цоколь E27, мощность 40W</a><br/>';
    				echo '<br/><a href="/catalog/?id=6&section=4212&dep=12">Купить энергосберегающую лампочку: цоколь E27, мощность 11W</a>';
    				}
    			else if(($socle == 2748 || $socle == 1305 || $socle == 3051 || $socle == 203 || $socle == 1724) && ($power == 1919 || $power = 1817 || $power = 5163 || $power = 1306 || $power = 2727 || $power = 205 || $power = 3052 || $power = 1850))//E27 60W
    				{
    				echo '<br/><a href="/catalog/?id=7&section=2162&dep=12">Купить лампочку: цоколь E27, мощность 60W</a><br/>';
    				echo '<br/><a href="/catalog/?id=8&section=4212&dep=12">Купить энергосберегающую лампочку: цоколь E27, мощность 11W</a>';
    				}
    			else if(($socle == 2748 || $socle == 1305 || $socle == 3051 || $socle == 203 || $socle == 1724) && ($power == 1919 || $power = 1817 || $power = 5163 || $power = 1306 || $power = 2727 || $power = 205 || $power = 3052 || $power = 1850))//E27 60W
    				{
    				echo '<br/><a href="/catalog/?id=9&section=2162&dep=12">Купить лампочку: цоколь E27, мощность 60W</a><br/>';
    				echo '<br/><a href="/catalog/?id=10&section=4212&dep=12">Купить энергосберегающую лампочку: цоколь E27, мощность 11W</a>';
    				}		
    		?>

    Говнокодеры не спят, они какают и какают :))))
    Учитесь, как надо давать покупателю возможность выбрать подходящую лампочку)

    greevex, 25 Февраля 2011

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