1. JavaScript / Говнокод #5896

    +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
    switch (ch) {
                case 't':
                    next('t');
                    next('r');
                    next('u');
                    next('e');
                    return true;
                case 'f':
                    next('f');
                    next('a');
                    next('l');
                    next('s');
                    next('e');
                    return false;
                case 'n':
                    next('n');
                    next('u');
                    next('l');
                    next('l');
                    return null;
                }
                error("Unexpected '" + ch + "'");
            },

    https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js

    nin-jin, 05 Марта 2011

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

    +120

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    public class XXX
    {
        private Object m_ForLock = new object();
        private String m_Path = "";
        public XXX(String Path)
        {
            lock (m_ForLock)
            {
                 m_Path = Path;
            }
         }
    }

    javros, 05 Марта 2011

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

    +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
    <table class="form_order_create form_order_create_check" >
      
        <tr> <? /* пробел */?>
          <td style="width:30px">&nbsp;</td>
          <td style="vertical-align:middle;width:30%;" colspan=2>
            <div class="name" style="padding-left:10px;">
              &nbsp;
            </div>
          </td>
        </tr>
      
        <? /* Номер заказа */?>
        <tr>
          <td style="width:30px">&nbsp;</td>
          <td style="vertical-align:middle;width:30%;">
            <div class="name" style="padding-left:10px;">
              <u>Номер заказа:</u>
            </div>
          </td>
          <td style="vertical-align:middle;">
            <div class="name" style="padding-left:10px;">
              №<?=$arResult["ORDER_ID"]?>
            </div>
          </td>
        </tr>
        
        <tr> <? /* пробел */?>
          <td style="width:30px">&nbsp;</td>
          <td style="vertical-align:middle;width:30%;" colspan=2>
            <div class="name" style="padding-left:10px;">
              &nbsp;
            </div>
          </td>
        </tr>
     
      </table>

    Язык конечно не php, но достойно.

    leonard, 05 Марта 2011

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function &_extract(&$array, $path) {
      $element = &$array;
      while(count($path)) {
        $key = array_shift($path);
        $element = &$element[$key];
      }
    
      return $element;
    }

    vectoroc, 05 Марта 2011

    Комментарии (12)
  5. C++ / Говнокод #5892

    +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
    int main () {
            char    bStr[] = "<H1>",
                            eStr[] = "</H1>",
                            ifName[] = "E:\\dostat.txt";
            ifstream ifst;
            int i;
     
            ifst.open(ifName);
            if(!ifst)
                    exit(-1);
     
            for(;!ifst.eof();){
                    for(i=0;!ifst.eof()&&ifst.get()==bStr[i];i++);
                    ifst.unget();
                    if(!bStr[i]){
                            for(;;){
                                    for(i=0;!ifst.eof()&&ifst.get()==eStr[i];i++);
                                    if(!eStr[i])
                                            break;
                                    for(;i>=0;i--)
                                            ifst.unget();
                                    cout<<(char)ifst.get();
                            }
                            cout<<endl<<"--------------------------------"<<endl;
                    }
                    else
                            ifst.get();
            }
            cin.get();
            return 0;
    }

    qbasic, 05 Марта 2011

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

    +166

    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
    bool ok = false;
     
            // инициализируем WinInet
            HINTERNET hInternet =
                    ::InternetOpen(
                            TEXT("WinInet Test"),
                            INTERNET_OPEN_TYPE_PRECONFIG,
                            NULL,NULL,
                            0);
     
            if (hInternet != NULL) {
                    // открываем HTTP сессию
                    HINTERNET hConnect =
                            ::InternetConnect(
                                    hInternet,
                                    TEXT(URL),
                                    INTERNET_DEFAULT_HTTP_PORT,
                                    NULL,NULL,
                                    INTERNET_SERVICE_HTTP,
                                    0,
                                    1u);
     
                    if (hConnect != NULL) {
                            // открываем запрос
                            HINTERNET hRequest =
                                    ::HttpOpenRequest(
                                            hConnect,
                                            TEXT("GET"),
                                            TEXT(DOC),
                                            NULL,
                                            NULL,
                                            0,
                                            INTERNET_FLAG_KEEP_CONNECTION,
                                            1);
     
                            if (hRequest != NULL) {
                                    // посылаем запрос
                                    BOOL bSend = ::HttpSendRequest(hRequest, NULL,0, NULL,0);
                                    if (bSend) {
                                            // создаём выходной файл
                                            ofstream fnews("news.html",ios::out|ios::binary);
                                            
                        if (fnews.is_open())
                                            for (;;) {
                                                    // читаем данные
                                                    char  szData[1024];
                                                    DWORD dwBytesRead;
                                                    BOOL bRead =
                                                            ::InternetReadFile(
                                                                    hRequest,
                                                                    szData,sizeof(szData)-1,
                                                                    &dwBytesRead);
    
                                                    if (bRead == FALSE  ||  dwBytesRead == 0)
                                                            break;
     
                                                    // сохраняем результат
                                                    szData[dwBytesRead] = 0;
                                                    fnews << szData;
                                                    cout << szData;
     
                                                    ok = true;
                                            }
                                    }
                                    // закрываем запрос
                                    ::InternetCloseHandle(hRequest);
                            }
                            // закрываем сессию
                            ::InternetCloseHandle(hConnect);
                    }
                    // закрываем WinInet
                    ::InternetCloseHandle(hInternet);
            }

    qbasic, 05 Марта 2011

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

    +82

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    for (FileItem item : items) {
        try {
            item.write(new File(repo 
                    + System.currentTimeMillis() 
                    + "_" + item.getName()));
        } catch (Exception ex) {
            log.error(ex, ex);
        }
        mav.addObject("result", "http://xxx.xx/uploads/"
                + System.currentTimeMillis() 
                + "_" + item.getName());
    }

    долго думал почему имя файла на диске не совпадает с именем в ссылке.

    zlob.jc, 05 Марта 2011

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

    +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
    <html> 
    <head>
    <title>Калькулятор</title> 
    </head>
    <body>
    <?
    function show()
    {
    global $action, $result, $first, $second;
    ?>
    <FORM method="GET" action="">
    <input type="text" name="first">
    <input type="text" name="second">
    <table>
    <tr>
    <td><input type="submit" name="action" value="sum"></td>
    <td><input type="submit" name="action" value="min"></td>
    <td><input type="submit" name="action" value="mult"></td>
    </tr>
    <tr>
    <td><input type="submit" name="action" value="dev" ;></td>
    <td><input type="submit" name="action" value="stepen";></td>
    <td><input type="submit" name="action" value="procent";></td>
    <td><input type="submit" name="action" value="koren";></td>
    </tr>
    </table>
    </form>
    <?
    }
    function calc() 
    { 
    global $action, $result, $first, $second; 
    switch($action)
    {
    case "sum": $result = $first+$second; 
    break;
    case "min": $result = $first-$second; 
    break;
    case "mult": $result = $first*$second; 
    break;
    case "dev":
    if (!$second) 
    {
    exit("Извините, программа не может выполнить действие: на ноль делить нельзя");
    }
    $result=$first/$second; 
    break;
    case "procent": $result = $first*($second/100); 
    break;
    case "stepen": $result = pow($first, $second); 
    break;
    case "koren": $result = pow($first,0.5); 
    break;
    }
    ?>
    <b> <? echo $result; ?> </b> 
    <?
    }
    if ($action) 
    calc(); 
    else show();
    ?>
    </body> 
    </html>

    qbasic, 04 Марта 2011

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

    +77

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function formatSpeedBits(speed) {
    	// format speed in bits/sec, input: bytes/sec
    	if (speed < 125000) return Math.round(speed / 125) + " Kbps";
    	if (speed < 125000000) return Math.round(speed / 1250)/100 + " Mbps";
    	// else
    	return Math.round(speed / 1250000)/100 + " Gbps";  // wow!
    }

    JS в интерфейсе прошивки dd-wrt. Не совсе говнокод.

    danilissimus, 04 Марта 2011

    Комментарии (14)
  10. Си / Говнокод #5887

    +105

    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
    #define C_WRONG              -2000
    
    ....
    
    int tttt_atoi(char* p_string){
    
       int result = C_WRONG;
    
       if ( *p_string < '0' || *p_string > '9' )
          return C_WRONG;
    
       result = atoi(p_string);
       return result;
    }
    
    double tttt_atof(char* p_string){
    
       double result = C_WRONG;
       result = atof(p_string);
       if (result!=0){
          return result;
       }
       else{
          if(strcmp(p_string,"0.0")==0 || strcmp(p_string,"0")==0 || strcmp(p_string,"0.")==0){
             return result;
          }
          else{
             return C_WRONG;
          }
       }
    }

    и вы посмейтесь. или facepalm'нитесь. синтакс оригинала.

    Dummy00001, 04 Марта 2011

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