1. Objective C / Говнокод #18072

    −407

    1. 1
    Какая блядина минусует все говнокоды?

    Her, 28 Апреля 2015

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

    +145

    1. 1
    2. 2
    if (in)
    	goto out;

    Найдено на просторах ядра (fsl_esai.c кому интересно). Не ГК само по себе но читается замечательно.

    lorc, 27 Апреля 2015

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

    +142

    1. 1
    this.reparent = function (new_parent) {var el = this.element; el.parentNode.removeChild(el); new_parent.appendChild(el);}

    Наткнулся в старом, но ещё работающем коде. Может быть, это даже я написал. Надеюсь, что нет.
    …Нет, похоже, всё-таки не я. Я бы не назвал класс подсвеченного элемента hilited, даже десять лет назад. Похоже, это босс писал.

    torbasow, 27 Апреля 2015

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

    +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
    function preg_replace_e_modifier(array $usage_tokens) {
        $tree = PhpCodeFixer::makeFunctionCallTree($usage_tokens);
        $data = PhpCodeFixer::delimByComma($tree[0]);
        $data = PhpCodeFixer::trimSpaces($data[0]);
        // getting delimiter
        if ($data[0][0] == T_CONSTANT_ENCAPSED_STRING) {
            $string = trim($data[0][1], '\'"');
            $delimiter = $string{0};
            if ($data[count($data)-1][0] == T_CONSTANT_ENCAPSED_STRING) {
                $string = trim($data[count($data)-1][1], '\'"');
                if (($modificator = strrchr($string, $delimiter)) !== false) {
                    if (strpos($modificator, 'e') !== false) {
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            return false;
        }
        return false;
    }

    return false; return false; return false; return false; return false;
    https://github.com/wapmorgan/PhpCodeFixer

    27cm, 27 Апреля 2015

    Комментарии (14)
  5. Perl / Говнокод #18067

    −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
    $utm = `$utmcalc_cmd $user $YEAR $MONTH` || "error";
    if ($oldtarif_mar == 16 || $oldtarif_mar == 17 || $oldtarif_mar == 19 || $oldtarif_mar == 27 || $oldtarif_mar == 45) {
    	if ($newtarif_mar == 16 || $newtarif_mar == 17 || $newtarif_mar == 19 || $newtarif_mar == 27 || $newtarif_mar == 45) {
    		$money2 = (($oldtarif_abonplata/30)*$daystoeom) - (($newtarif_abonplata/30)*$daystoeom);
    #		$nm1 = 0;
    	} else {
    		$money2 = (($oldtarif_abonplata/30)*$daystoeom) - (($newtarif_abonplata/30)*$daystoeom);
    #		$nm1 = $utm;
    	}
    } elsif ($oldtarif_mar != 16 || $oldtarif_mar != 17 || $oldtarif_mar != 19 || $oldtarif_mar != 27 || $oldtarif_mar != 45) {
    	if ($newtarif_mar == 16 || $newtarif_mar == 17 || $newtarif_mar == 19 || $newtarif_mar == 27 || $newtarif_mar == 45) {
    #		$money2 = $oldtarif_abonplata - ($utm*$oldtarif_koef) - (($newtarif_abonplata/30)*$daystoeom);
    		$money2 = (($oldtarif_abonplata/30)*$daystoeom) - (($newtarif_abonplata/30)*$daystoeom);
    #		$nm1 = -$cur_nm;
    	} else {
    #		$money2 = $oldtarif_abonplata - ($utm*$oldtarif_koef) - (($newtarif_abonplata/30)*$daystoeom);
    		$money2 = (($oldtarif_abonplata/30)*$daystoeom) - (($newtarif_abonplata/30)*$daystoeom);
    #		$nm1 = -(($newtarif_lymit/30)*$DAY);
    	}
    }

    Из биллинга одного довольно крупного интернет-провайдера
    Кто-то что-то хотел закомментить...

    begemot, 27 Апреля 2015

    Комментарии (1)
  6. Assembler / Говнокод #18066

    +249

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    mov     ecx, [eax+374h] 
    xor     edx, edx
    test    ecx, ecx
    jg      short loc_17BE80
    mov     ecx, edx 
    loc_17BE80:
    mov     [eax+374h], ecx
    mov     eax, [ebp+360h]
    mov     edx, [eax+374h]
    cmp     edx, [eax+102Ch]
    ;...

    Какой интересный способ обнуления ecx избрал компилятор...

    gost, 27 Апреля 2015

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

    +142

    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
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    ini_set('memory_limit', '100M'); // to be safe we are increasing the memory limit for search
    
    include_once $_SERVER['PHP_ROOT'].'/html/init.php'; // final lib include
    include_once $_SERVER['PHP_ROOT'].'/lib/s.php';
    include_once $_SERVER['PHP_ROOT'].'/lib/browse.php';
    include_once $_SERVER['PHP_ROOT'].'/lib/events.php';
    include_once $_SERVER['PHP_ROOT'].'/lib/websearch_classifier/websearch_classifier.php';
    
    flag_allow_guest();
    $user = search_require_login();
    
    if ($_POST) {
      $arr = us_flatten_checkboxes($_POST, array('ii'));
      $qs = '?';
      foreach($arr as $key = > $val) {
        $qs. = $key.'='.urlencode($val).'&';
      }
      $qs = substr($qs, 0, (strlen($qs) - 1));
      redirect($_SERVER['PHP_SELF'].$qs);
    }
    
    // If they performed a classmates search, these values are
    // needed to pre-populate dropdowns
    param_get_slashed(array('hy' = > $PARAM_STRING, 'hs' = > $PARAM_INT, 'adv' = > $PARAM_EXISTS, 'events' = > $PARAM_EXISTS, 'groups' = > $PARAM_EXISTS, 'classmate' = > $PARAM_EXISTS, 'coworker' = > $PARAM_EXISTS));
    $pos = strpos($get_hy, ':');
    if ($pos !== false) {
      $hsid = intval(substr($get_hy, 0, $pos));
      $hsyear = intval(substr($get_hy, $pos + 1));
    } else {
      $hsid = intval($get_hs);
      $hsyear = null;
    }
    
    tpl_set('hs_id', $hsid);
    tpl_set('hs_name', get_high_school($hsid));
    tpl_set('hs_year', $hsyear);
    tpl_set('is_advanced_search', $get_adv);
    tpl_set('user', $user);
    tpl_set('count_total', 0); // pre-set count_total for the sake of ads page length
    
    // Events search calendar data
    param_get(array('k' = > $PARAM_HEX, 'n' = > $PARAM_SINT));
    
    if (($get_k == search_module::get_key(SEARCH_MOD_EVENT, SEARCH_TYPE_AS))) {
    
      $EVENTS_CAL_DAYS_AHEAD = 60;
      $events_begin = strftime("%Y%m01"); // first of the month
      $events_end = strftime("%Y%m%d", strtotime(strftime("%m/01/%Y")) + (86400 * $EVENTS_CAL_DAYS_AHEAD));
      $events_params = array('dy1' = > $events_begin, 'dy2' = > $events_end);
    
      param_get(array('c1' = > $PARAM_INT, 'c2' = > $PARAM_INT), 'evt_');
      if (isset($evt_c1)) {
        $events_params['c1'] = $evt_c1;
      }
      if (isset($evt_c2)) {
        $events_params['c2'] = $evt_c2;
      }
      $results = events_get_calendar($user, $get_n, $events_params);
      tpl_set('events_date', $results['events_date']);
    }
    
    
    
    
    // Holy shit, is this the cleanest fucking frontend file you've ever seen?!
    ubersearch($_GET, $embedded = false, $template = true);
    
    // Render it
    render_template($_SERVER['PHP_ROOT'].'/html/s.phpt');
    
    /**
     * login function for s.php
     *
     * @author Philip Fung
     */
    
    function search_require_login() {
    
      //check if user is logged in
      $user = require_login(true);
    
      if($user 0 && !is_unregistered($user)) { return $user; }
    
      // this is an unregistered user
      param_get(
        array('k' = > $GLOBALS['PARAM_HEX'], // search key (used by rest of ubersearch code)
      ));
    
      global $get_k;
      $search_key = $get_k;
    
      //Let user see event or group search if criteria are obeyed
      if ($search_key && (search_module::get_key_type($search_key) == SEARCH_MOD_EVENT || search_module::get_key_type($search_key) == SEARCH_MOD_GROUP) //event or group search
      ) {
        return $user;
      } else {
        go_home();
      }
    }

    /*
    * @author Mark Slee
    *
    * @package ubersearch
    */


    Фейсбук и даты. Можете топить.

    inkanus-gray, 26 Апреля 2015

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

    +143

    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
    92. 92
    93. 93
    94. 94
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main ()
    {
        int n,m;
        char c[10][10];
        cin >> n >> m;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                cin >> c[i][j];
            }
        }
        c[0][0] = 'E';
        c[n-1][0] = 'D';
        c[0][m-1] = 'F';
        c[n-1][m-1] = 'C';
        
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (c[i][j] == 'A')
                {
                    if (j == 0) {c[i][j] = 'B';} else
                    {if (i>0 && c[i][j-1] != 'A' && c[i][j-1] != 'D' && c[i][j-1] != 'E' && (c[i-1][j] == 'E' || c[i-1][j] == 'F' || c[i-1][j] == 'B')) c[i][j] = 'B';}
    
                } 
                else 
                {
                        if (c[i][j] == 'B')
                    {
                        if (i == 0) {c[i][j] = 'A';} else
                        {if (j>0 && c[i-1][j] != 'B' && c[i-1][j] != 'F' && c[i-1][j] != 'E' && (c[i][j-1] == 'D' || c[i][j-1] == 'F' || c[i][j-1] == 'A')) c[i][j] = 'A';}
    
                    } 
                    else
                    { //уголки
                        if (i==0 && j > 0) 
                        {
                            if (c[i][j-1] == 'A' || c[i][j-1] == 'E') c[i][j] = 'F'; else c[i][j] = 'E';
                        } 
                        else
                        {
                            if (i==n-1 && j > 0) 
                            {
                                if (c[i][j-1] == 'A' || c[i][j-1] == 'D') c[i][j] = 'C'; else c[i][j] = 'D';
                            } 
                            else
                            {
                                if (j==0 && i > 0)
                                {
                                    if (c[i-1][j] == 'B' || c[i-1][j] == 'E') c[i][j] = 'D'; else c[i][j] = 'E';
                                } 
                                else
                                {
                                    if (j==m-1 && i > 0)
                                    {
                                        if (c[i-1][j] == 'B' || c[i-1][j] == 'F') c[i][j] = 'C'; else c[i][j] = 'F';
                                    }
                                    else 
                                    {
                                        if ((c[i-1][j] == 'B' || c[i-1][j] == 'F') && (c[i][j-1] == 'A' || c[i][j-1] == 'D')) c[i][j] = 'C';
                                        else
                                        {
                                            if (c[i-1][j] == 'B' || c[i-1][j] == 'E') c[i][j] = 'D';
                                            else
                                            {
                                                if (c[i][j-1] == 'A' || c[i][j-1] == 'E') c[i][j] = 'F';
                                                else c[i][j] = 'E';
                                            }
                                        }
                                    }
                                }
                            }
                        }                   
                    }
                }
            }
        }
    
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                cout << c[i][j];
            }
            cout << endl;
        }
    }

    http://vk.com/photo70606856_365037363
    Пройдено 77 тестов из 85

    yury99, 26 Апреля 2015

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

    +142

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    if (false == very_long_function(arg1, arg2, ...)) 
    {
        if (false == very_long_other_function(even_more_args) 
        {
            do_something();
        }
        else 
        {   
            do_something_else();
        }
    }

    И вот такими многоэтажками забит весь проект.

    codemonkey, 26 Апреля 2015

    Комментарии (5)
  10. Python / Говнокод #18061

    −180

    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
    try:
        ip_port = sys.argv[1].split(':')
        ip = ip_port[0]
     
        if len(ip_port) == 2:
            port = ip_port[1]
        elif len(ip_port) == 1:
            port = "80"
        else:
            raise IndexError
    except IndexError:
        print "Usage: %s <target ip:port>" % sys.argv[0]
        sys.exit(1)

    Эксплоиты. Неиссякаемый источник ГК.

    Я бы сделал так:

    try:
    ip_port = sys.argv[1].split(':')
    ip = ip_port[0]
    try:
    port = ip_port[1]
    except IndexError:
    port = 80
    except IndexError:
    print "Usage: %s <target ip:port>" % sys.argv[0]
    sys.exit(1)

    3_14dar, 25 Апреля 2015

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