1. 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)
  2. 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)
  3. Си / Говнокод #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)
  4. 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)
  5. Pascal / Говнокод #18060

    +144

    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
    function IsIntStr(const str:string):boolean;                                    // Для проверки, состоит ли логин целиком из цифр.
    var                                                                             // TryStrToInt не подходит.
      p:pchar;
    begin
      result:=false;
      p:=pchar(str);
      if p^=#0 then exit;
      while p^ <> #0 do
      begin
        if not (p^ in ['0'..'9']) then
        exit;
        p:=charnext(p) ;
      end;
      result:=true;
    end;

    Showmessage(IntToStr(4324324233213564)); // а хуйца не желаете?

    Stertor, 24 Апреля 2015

    Комментарии (12)
  6. Pascal / Говнокод #18059

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    FYears.Items.Clear;
          for i := 10 downto 1 do
            FYears.Items.Add(IntToStr(Year - i));
          FYears.Items.Add(IntToStr(Year));
          for i := 1 to 10 do
            FYears.Items.Add(IntToStr(Year + i));

    Заполнение итемов номерами лет
    Сначала добавим 10 лет до даты Х
    Потом дату Х
    Потом 10 лет после даты Х
    RAD Studio XE8 FMX.Calendar.Style.pas

    PeaK, 24 Апреля 2015

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

    +143

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    if TPlatformServices.Current.SupportsPlatformService(IFMXLocaleService, IInterface(LocaleService)) then
            S := LocaleService.GetLocaleFirstDayOfWeek
          else
            S := '6';
          FFirstDayOfWeekNum := Ord(S.Chars[0]) - Ord('0');
          {$IFDEF MACOS}
          FFirstDayOfWeekNum:= Ord(S.Chars[0]) + Ord('0');
          {$ENDIF}
          {$IFDEF ANDROID}
            FFirstDayOfWeekNum := FFirstDayOfWeekNum - MondayOffset;
          {$ENDIF}

    Это FireMonkey! FMX.Calendar.Style.pas! И это реально работает.
    Главное, что всё очевидно.

    PeaK, 24 Апреля 2015

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public function createAdvertApart () { // ВНИМАНИЕ! Видимость функции protected
    
    // проверяем max размер допустимый к загрузке
    			if ( $_files[size] > 3000000 )
    			$error[] = "Файл превышает размер три мегабайта";

    Прислали вместе с резюме пример кода, а там ...

    kolko91, 24 Апреля 2015

    Комментарии (3)
  9. Pascal / Говнокод #18056

    +144

    1. 1
    IntToStr(StrToInt(VarToStr()))

    Сегодня пришла мадам и спросила почему это не работает. Сказали что бы так больше не ...кодила.

    ViktorR, 24 Апреля 2015

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

    +144

    1. 1
    Шёл 2015 год, а SQLite на ведре так и не научился сравнивать не ASCII'шные строки без учёта регистра...

    Или это у меня руки из жопы растут?

    bormand, 24 Апреля 2015

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