1. PHP / Говнокод #16697

    +155

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <?php
    
    $data = file_get_contents("/path/to/photo.jpg"); // Read the file's contents
    $name = 'myphoto.jpg';
    
    force_download($name, $data);

    Я знаю конечно что это не говнокод, но последствия будут ужасными если не передать сразу же в функцию данные (т.к. PHP будет копировать содержимое дважды), представьте себе файл в 2МБ и много запросов, сервер капут в два раза быстрее.
    - https://ellislab.com/codeigniter/user-guide/helpers/download_helper.html

    volter9, 15 Сентября 2014

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

    −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
    &НаСервере
    Процедура ПриСозданииНаСервере(Отказ, СтандартнаяОбработка)
    
            НовыйДокумент = Документы.ДокументПредЗаявка.СоздатьДокумент();
             НовыйДокумент.Дата = ТекущаяДата();
             НовыйДокумент.Записать(РежимЗаписиДокумента.Проведение);
             СПД = НовыйДокумент.Ссылка;
             
             //Открываем документ
             ОткрытьЗначение(СПД);
          
    КонецПроцедуры

    Я не вкурил, но полагаю, что ЭТО новый способ создания документа на основании...

    Danik, 15 Сентября 2014

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

    +151

    1. 1
    2. 2
    3. 3
    4. 4
    //...
    <script>splashRadar('leftcol', 1);</script>
    <script>splashRadar('baseStyles');</script>
    //...

    На мейл.сру.

    gost, 14 Сентября 2014

    Комментарии (18)
  4. JavaScript / Говнокод #16693

    +157

    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
    $('#id_accept_eula').click(function () {
        // код аффтара
        try {
            var v = 1 - this.getAttribute('value');
            this.setAttribute('value', v);
            if (v == 1) {
                $('#submit_button').removeAttr('disabled');
            } else {
                $('#submit_button').attr('disabled', 'disabled');
            }
        } catch (e) {
            alert('exc: ' + e);
        }
        // заменил на
        $("#submit_button").prop('disabled', !this.checked);
    });

    Когда платят за строки кода...

    govnozmey, 14 Сентября 2014

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

    +131

    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
    /*
     * Copyright (C) 2007-2012 Allwinner Technology Co., Ltd.
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License as
     * published by the Free Software Foundation; either version 2 of
     * the License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
     * MA 02111-1307 USA
     */
    
    #ifndef __DISP_DISPLAY_I_H__
    #define __DISP_DISPLAY_I_H__
    
    #include "ebios_de.h"
    #include "ebios_lcdc_tve.h"
    #include "drv_disp_i.h" /* For DISP_XXXXXX status codes */
    
    #define DE_INF __inf
    #define DE_WRN __wrn
    
    #define OSAL_IRQ_RETURN IRQ_HANDLED
    
    #define HANDTOID(handle)  ((handle) - 100)
    #define IDTOHAND(ID)  ((ID) + 100)
    
    #define INTC_IRQNO_SCALER0  SW_INT_IRQNO_DEFEBE0
    #define INTC_IRQNO_SCALER1  SW_INT_IRQNO_DEFEBE1
    #define INTC_IRQNO_LCDC0    SW_INT_IRQNO_LCDCTRL0
    #define INTC_IRQNO_LCDC1    SW_INT_IRQNO_LCDCTRL1
    
    #define MAX_SPRITE_BLOCKS   32
    
    /*basic data information definition*/
    enum {
    	FALSE = 0,
    	TRUE
    };
    
    #define DIS_NULL 0
    
    #define BIT0    0x00000001
    #define BIT1	0x00000002
    #define BIT2	0x00000004
    #define BIT3	0x00000008
    #define BIT4	0x00000010
    #define BIT5	0x00000020
    #define BIT6	0x00000040
    #define BIT7	0x00000080
    #define BIT8	0x00000100
    #define BIT9	0x00000200
    #define BIT10	0x00000400
    #define BIT11	0x00000800
    #define BIT12	0x00001000
    #define BIT13	0x00002000
    #define BIT14	0x00004000
    #define BIT15	0x00008000
    #define BIT16	0x00010000
    #define BIT17	0x00020000
    #define BIT18	0x00040000
    #define BIT19	0x00080000
    #define BIT20	0x00100000
    #define BIT21	0x00200000
    #define BIT22	0x00400000
    #define BIT23	0x00800000
    #define BIT24	0x01000000
    #define BIT25	0x02000000
    #define BIT26	0x04000000
    #define BIT27	0x08000000
    #define BIT28	0x10000000
    #define BIT29	0x20000000
    #define BIT30	0x40000000
    #define BIT31	0x80000000
    
    
    #endif

    Нашёл в драйвере дисплея. Вместо 1<<N.

    mittorn, 13 Сентября 2014

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $data = $DB->...
    reset($data);
    while (list(, $row) = each($data)) {
        // do somethig with $row
    }

    Я не понимаю, почему просто не использовать foreach?!

    matasar, 13 Сентября 2014

    Комментарии (7)
  7. Куча / Говнокод #16690

    +125

    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
    (closer-mop:defclass virtual-metaclass (closer-mop:standard-class) ())
    
    (closer-mop:defclass virtual-slot-definition
        (closer-mop:standard-slot-definition)
      ((function :initarg :function 
                 :accessor virtual-slot-definition-function)))
    
    (defmethod slot-definition-allocation ((slotd virtual-slot-definition))
      :virtual)
    
    (defmethod (setf slot-definition-allocation) 
        (allocation (slotd virtual-slot-definition))
      (unless (eq allocation :virtual)
        (error "Cannot change the allocation of a ~S"
               'virtual-direct-slot-definition)) allocation)
    
    (closer-mop:defclass virtual-direct-slot-definition 
        (closer-mop:standard-direct-slot-definition
         virtual-slot-definition) ())
    
    (defmethod closer-mop:direct-slot-definition-class
        ((class virtual-metaclass) &rest initargs)
      ;; Use virtual-direct-slot-definition if appropriate.
      (if (eq (getf initargs :allocation) :virtual)
          (find-class 'virtual-direct-slot-definition)
          (call-next-method)))
    
    (closer-mop:defclass virtual-effective-slot-definition 
        (closer-mop:standard-effective-slot-definition
         virtual-slot-definition) ())
    
    (defmethod closer-mop:effective-slot-definition-class 
        ((class virtual-metaclass) &rest initargs)
      ;; Use virtual-effective-slot-definition if appropriate.
      (let ((slot-initargs (getf initargs :initargs)))
        (if (member :virtual-slot slot-initargs)
            (find-class 'virtual-effective-slot-definition)
            (call-next-method))))
    
    (defmethod closer-mop:compute-effective-slot-definition 
        ((class virtual-metaclass) name direct-slot-definitions)
      ;; Copy the function into the effective slot definition
      ;; if appropriate.
      (let ((effective-slotd (call-next-method)))
        (dolist (slotd direct-slot-definitions)
          (when (typep slotd 'virtual-slot-definition)
            (setf (virtual-slot-definition-function effective-slotd) 
                  (virtual-slot-definition-function slotd))
            (return)))
        effective-slotd))
    
    (defmethod closer-mop:slot-value-using-class 
        ((class virtual-metaclass) object slot-name)
      (let ((slotd (find slot-name (closer-mop:class-slots class) 
                         :key 'closer-mop:slot-definition-name)))
        (if (typep slotd 'virtual-slot-definition)
            (funcall (cadr (virtual-slot-definition-function slotd)) :get object)
            (call-next-method))))
    
    (defmethod (setf closer-mop:slot-value-using-class) 
        (value (class virtual-metaclass) object slotd)
      (if (typep slotd 'virtual-slot-definition)
          ;; This is ugly and probably not portable, but what if?
          (funcall (cadr (virtual-slot-definition-function slotd))
                   :set object value)
          (call-next-method)))
    
    (defmethod closer-mop:slot-boundp-using-class 
        ((class virtual-metaclass) object slot-name)
      (let ((slotd (find slot-name (closer-mop:class-slots class) 
                         :key 'closer-mop:slot-definition-name)))
        (if (typep slotd 'virtual-slot-definition)
            (funcall (cadr (virtual-slot-definition-function slotd)) :is-set object)
            (call-next-method))))
    
    (defmethod closer-mop:slot-makunbound-using-class 
        ((class virtual-metaclass) object slot-name)
      (let ((slotd (find slot-name (closer-mop:class-slots class) 
                         :key 'closer-mop:slot-definition-name)))
        (if (typep slotd 'virtual-slot-definition)
            (funcall (virtual-slot-definition-function slotd) :unset object)
            (call-next-method))))

    О простоте объектно-ориентированого программирования, или страшная правда, которую от вас так долго скрывали.
    Написано по мотивам: http://www.lispworks.com/documentation/lw50/LWUG/html/lwuser-173.htm В попытке сделать это, по возможности, портабельным (на SBCL вроде даже завелось).

    Я понимаю, что читать это никто не будет, поэтому, краткий пересказ событий:
    Захотелось мне виртуальных свойств, ну тоесть так, чтобы при обращении к Сипипишной библиотеке, для которой я ваяю оберкту не было различий между обычными Лисповыми объектами и Сипипишными.
    Простой вариант - скопировать значения, но перформанс же!
    И вот родился этот вариант. (Использование не показано, т.как не влезло).

    wvxvw, 12 Сентября 2014

    Комментарии (16)
  8. JavaScript / Говнокод #16689

    +153

    1. 1
    2. 2
    $("div.entry-comment-wrapper").has("p strong a").each( function (i,e){
    $.ajax({'url':'http://govnokod.ru/ratings/comment/'+$(e).attr('id').replace('comment-','')+'/against'}) } );

    gost, 12 Сентября 2014

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

    +173

    1. 1
    var magnitude = parseInt('10' + new Array(8).join('0'));

    вот такое встретилось

    Sulik78, 12 Сентября 2014

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

    +138

    1. 1
    p.fANT = Convert.ToUInt16(((devStat & (1 << 13)) != 0 ? "1" : "0") + ((devStat & (1 << 12)) != 0 ? "1" : "0"), 2);

    Вот сижу думаю так задуманно или автор сам не понял что написал

    Smekalisty, 12 Сентября 2014

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