1. Java / Говнокод #18166

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public static final long SECOND = 1000;
       public static final long MINUTE = 1000 * 60;
       public static final long HOUR = MINUTE * 60;
       public static final long DAY = HOUR * 24;
       public static final long WEEK = DAY * 7;
       public static final long MONTH = DAY * 30;
       public static final long SEMIANNUAL = DAY * 183;
       public static final long YEAR = DAY * 365;

    ajtkulov, 14 Мая 2015

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

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    //выберем все th-ячейки заголовка грида
    var allGridHeaderCells = cell.parentNode.children;
    //получим индекс ячейки 0...N, на которой произошел клик
    for (var ThisColNum = 0; ThisColNum < allGridHeaderCells.length; ThisColNum++) {
    	if (allGridHeaderCells[ThisColNum] == cell) {
    		break;
    	}
    }

    Пишет очень аккуратный программист. Но зачем так?! Вместо простого cell.cellIndex.
    Отдельный штрих, что дальше он использует переменную ThisColNum, определённую в цикле, доступность которой вне цикла — это вообще пережиток прошлого ECMAScript, не знавшего let.

    torbasow, 14 Мая 2015

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

    +144

    1. 1
    $orig_id = isset($_POST["orig_id"]) ? (int) $_POST["orig_id"] : (int) $_GET["orig_id"];

    https://github.com/uisky/notabenoid/blob/6edfee9f33b8466be9164cd3ba6be90b8f3a5770/protected/controllers/MyCommentsController.php#L123

    Stallman, 14 Мая 2015

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

    +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
    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
    private List<string> urls = new List<string>();
    
            private int urls_index = -1;
    
            private ProgressBar pb = new ProgressBar()
            {
                Width = 291,
                Height = 26,
                Maximum = 100,
                Minimum = 0,
                Location = new Point(12, 41)
            };
    
            public Object SyncIndex = new Object();
    
    public void DownLoad(object index)
            {
                int indexwhile = (int) index;
                while (work)
                {
                    int localIndex;
    
                    lock (SyncIndex)
                    {
                        urls_index++;
                        localIndex = urls_index;
                    }
    
                    WebClient webClient = new WebClient();
                    try
                    {
                        webClient.DownloadFile(new Uri(urls[localIndex]), "img/" + localIndex + ".jpg");
                        webClient.DownloadProgressChanged += (s, a) => Invoke(new Action(() => {progressBars[indexwhile].Value = a.ProgressPercentage;})); 
                    }
                    catch (Exception exception)
                    {
                        Invoke(new Action(() =>
                        {
                            listBox2.Items.Add("Ошибка" + listBox1.Items[localIndex]);
                        }));
    
                        DownLoad(index);
                    }
    
                    Invoke(new Action(() =>
                    {
                        listBox1.Items[localIndex] =  "Загружен" + listBox1.Items[localIndex];
                        label1.Text = urls.Count.ToString();
                        richTextBox1.Text += localIndex + @".jpg Загружен" + Environment.NewLine;
                    }));
    
                    Thread.Sleep(500);
    
                }
            }
    
    
    private void button2_Click(object sender, EventArgs e)
            {
                work = true;
    
                Thread[] threads = new Thread[30];
    
                
    
                for (int i = 0; i < 20; i++)
                {
                    int mnoj = i + 1;
                    progressBars[i] = new ProgressBar()
                    {
                        Width = 291,
                        Height = 26,
                        Maximum = 100,
                        Minimum = 0,
                        Location = new Point(12, 41)
                    };
                    progressBars[i].Location = new Point(12, 41 * mnoj);
                    Controls.Add(progressBars[i]);
                    threads[i] = new Thread(DownLoad);
                    threads[i].IsBackground = true;
                    threads[i].Start(i);
                }
            }

    И все в одной форме..

    igorkrets, 14 Мая 2015

    Комментарии (1)
  5. JavaScript / Говнокод #18162

    +142

    1. 1
    var x = _.without.bind(_, someArray).apply(_, anotherArray);

    Человек не был знаком с методом difference в underscore

    syxov, 14 Мая 2015

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

    +142

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    <?php
    class ModelCheckoutOrder extends Model {
    	public function addOrder($data) {
    		$this->event->trigger('pre.order.add', $data);
    		$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET invoice_prefix = '" . $this->db->escape($data['invoice_prefix']) . "', store_id = '" . (int)$data['store_id'] . "', store_name = '" . $this->db->escape($data['store_name']) . "', store_url = '" . $this->db->escape($data['store_url']) . "', customer_id = '" . (int)$data['customer_id'] . "', customer_group_id = '" . (int)$data['customer_group_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', custom_field = '" . $this->db->escape(isset($data['custom_field']) ? serialize($data['custom_field']) : '') . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_country = '" . $this->db->escape($data['payment_country']) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_zone = '" . $this->db->escape($data['payment_zone']) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_address_format = '" . $this->db->escape($data['payment_address_format']) . "', payment_custom_field = '" . $this->db->escape(isset($data['payment_custom_field']) ? serialize($data['payment_custom_field']) : '') . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', payment_code = '" . $this->db->escape($data['payment_code']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "', shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($data['shipping_country']) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($data['shipping_zone']) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_address_format = '" . $this->db->escape($data['shipping_address_format']) . "', shipping_custom_field = '" . $this->db->escape(isset($data['shipping_custom_field']) ? serialize($data['shipping_custom_field']) : '') . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', shipping_code = '" . $this->db->escape($data['shipping_code']) . "', comment = '" . $this->db->escape($data['comment']) . "', total = '" . (float)$data['total'] . "', affiliate_id = '" . (int)$data['affiliate_id'] . "', commission = '" . (float)$data['commission'] . "', marketing_id = '" . (int)$data['marketing_id'] . "', tracking = '" . $this->db->escape($data['tracking']) . "', language_id = '" . (int)$data['language_id'] . "', currency_id = '" . (int)$data['currency_id'] . "', currency_code = '" . $this->db->escape($data['currency_code']) . "', currency_value = '" . (float)$data['currency_value'] . "', ip = '" . $this->db->escape($data['ip']) . "', forwarded_ip = '" .  $this->db->escape($data['forwarded_ip']) . "', user_agent = '" . $this->db->escape($data['user_agent']) . "', accept_language = '" . $this->db->escape($data['accept_language']) . "', date_added = NOW(), date_modified = NOW()");

    Я вас еще немного помучаю, хорошо?
    3978 символов, считая отступы

    https://github.com/opencart/opencart/blob/d5f66b0d75a5adf35815e333e45598bbc38750d0/upload/catalog/model/checkout/order.php#L6

    Fike, 14 Мая 2015

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

    +141

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    char    chByte15[3] = { pchCodeKey[0x15 * 2], pchCodeKey[0x15 * 2 + 1], 0 };
    char    chByte16[3] = { pchCodeKey[0x16 * 2], pchCodeKey[0x16 * 2 + 1], 0 };
    char    chByte18[3] = { pchCodeKey[0x18 * 2], pchCodeKey[0x18 * 2 + 1], 0 };
    
    unsigned char   uchByte15h;
    unsigned char   uchByte16h;
    unsigned char   uchByte18h;
    
    uchByte15h =  strtoul(chByte15, NULL, 16);
    uchByte16h =  strtoul(chByte16, NULL, 16);
    uchByte18h =  strtoul(chByte18, NULL, 16);

    все забыли про scanf()...

    Dummy00001, 13 Мая 2015

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

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if(isset($_GET['go']))
    	$go = htmlspecialchars(strip_tags(stripslashes(trim(urldecode(mysql_escape_string($_GET['go']))))));
    else
    	$go = "main";
    
    // ....
    
    switch($go){

    "Тыыыыыыы не пройдеееешь!". Зафильтровали (да ещё и криво) бедную переменную только для того, чтобы потом использовать её в switch-case блоке. Индусы-паникеры.

    bSun0000, 13 Мая 2015

    Комментарии (7)
  9. JavaScript / Говнокод #18158

    +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
    (function($){
    
      function pickMenuByHash(hash) {
    
        if(hash == undefined || hash == '' || hash == '#')
          hash = '#home'; // хеш по умолчанию
    
        // Выбираем ссылки с нужным хешем, чтро бы потом присвоить им класс "active"
        var A_tags = $('a[href="' + hash + '"]');
        
        // Ищем все ссылки в родительском теге UL относительно ссылок и удаляем у них классы "active"
        A_tags.parents('UL').find('a').removeClass('active');
    
        // Добавляем к ссылкам с нужным нам хешем класс "active"
        $('a[href="' + hash + '"]').addClass('active');
      }
    
      // Обновить состояние менюшек (сверху и справа) при загрузке страницы
      $(function(){
        pickMenuByHash(document.location.hash);
      });
    
      // При изменении хеша обновить состояния менюшек (сверху и справа)
      $(window).on('hashchange', function(){
        pickMenuByHash(document.location.hash);
      });
    
    })(jQuery);

    Вот тебе при изменении хеша на сайте верхнее и правое меню будет в актуальном для хеша состоянии.

    littlefuntik, 13 Мая 2015

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

    +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
    const char *pS;
    		char *pD;
    
    		// clear out new string
    		szNew[0] = '\0';
    
    		pS = pszValue;
    		pD = szNew;
    
    		// step through the string, only copying back in characters that are printable
    		while( *pS )
    		{
    			if( ((byte)*pS) < 32 || ((byte)*pS) > 255 )
    			{
    				pS++;
    				continue;
    			}
    			*pD++ = *pS++;
    		}
    
    		// terminate the new string
    		*pD = '\0';

    Мало того, char в проекте подразумевается signed

    mittorn, 12 Мая 2015

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