1. Лучший говнокод

    В номинации:
    За время:
  2. PHP / Говнокод #18246

    +143

    1. 1
    http://govnokod.ru/comments/18245/rss ru [email protected] (govnokod.ru support) Mzz.Framework v.100500-release Wed, 27 May 2015 21:20:29 +0400 Fatal error: Call to a member function getCreated() on a non-object in /home/striker/applications/govnokod/tmp/templates_c/1563503196.file.export_quote_rss.tpl.php-ru.php on line 21

    http://govnokod.ru/, в чём дело:

    Dev_18, 27 Мая 2015

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

    +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
    // ...
    
    Action updatingLoadedItemsList = null;
    
    foreach (Item loadedItem in loadedItems)
        if (loadedItem.Id == currentItem.Id)
            updatingLoadedItemsList = () => loadedItems.RemoveAt(loadedItems.IndexOf(loadedItem));
    
    if(updatingLoadedItemsList != null)
        updatingLoadedItemsList.Invoke();
    	
    // ...

    pushistayapodmyshka, 19 Мая 2015

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

    +143

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    void MyWindow::OkButtonClicked()
    {
        if((!cb1->isChecked()) && (!cb2->isChecked()))
            emit Simple(line->text());
        if((cb1->isChecked()) && (!cb2->isChecked()))
            emit Register(line->text());
        if((!cb1->isChecked()) && (cb2->isChecked()))
            emit Invers(line->text());
        if((cb1->isChecked()) && (cb2->isChecked()))
            emit RegVers(line->text());
    }

    dia, 05 Мая 2015

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

    +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
    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
    function Calculation(a, b, op){
        if (typeof a == "number" && typeof (b) == "number"){
            var result;
            +a; +b;
            if (op == "+")  { result = a+b; alert(result);
            } else if (op == "-") { result = a-b; alert(result);
            } else if (op == "*"){ result = a*b; alert(result);
            } else if (op == "/"){
                if (b!=0){ 
                    result = a/b; alert(result);
                } else {
                    alert("Can`t divide on zero!");
                }
            }
        } else if (a instanceof Array && b instanceof Array) {
            var result = [];
            if ( a.length >= b.length ){
                length = a.length;
                for (var i=0; i < length; i++){
                    a[i] = parseFloat(a[i]);
                    b[i] = parseFloat(b[i]);
                    if (i < b.length-1){
                        if (op == "+"){ result[i] = a[i]+b[i];
                        } else if (op == "-"){ result[i] = a[i]-b[i];
                        } else if (op == "*"){ result[i] = a[i]*b[i];
                        } else if (op == "/"){
                            if (b[i]!=0){
                                result[i] = a[i]/b[i];
                            } else {
                                alert("Can`t divide on zero!");
                            }
                        }
                    } else {
                        result[i] = a[i];
                    }
                } 
                alert(result.join("  |  "));
            } else {
                length = b.length;
                for (var i=0; i < length; i++){
                    +a[i]; +b[i];
                    if (i < a.length-1){
                        switch (op){
                            case "+":
                                result[i] = a[i]+b[i];
                                break;
                            case "-":
                                result[i] = a[i]+b[i];
                                break;
                            case "*":
                                result[i] = a[i]+b[i];
                                break;
                            case "/":
                                if (b[i]!=0){
                                    result[i] = a[i]/b[i];
                                } else {
                                    alert("Can`t divide on zero!");
                                }
                                break;
                        }
                    } else {
                        result[i] = a[i];
                    }
                } 
                alert(result.join("  |  "));
            }
        } else if (a instanceof Object && b instanceof Object) {
            var tempObject = {};
                switch (op){
                    case "+":
                        tempObject.resultA = a.a+b.a;
                        tempObject.resultB = a.b+b.b;
                        break;
                    case "-":
                        tempObject.resultA = a.a+b.a;
                        tempObject.resultB = a.b+b.b;
                        break;
                    case "*":
                        tempObject.resultA = a.a+b.a;
                        tempObject.resultB = a.b+b.b;
                        break;
                    case "/":
                        if (b.b !=0 || b.a != 0){
                            tempObject.resultA = a.a+b.a;
                            tempObject.resultB = a.b+b.b;
                        } else {
                            alert("Can`t divide on zero!");
                        }
                        break;
                }
                
                alert(tempObject.resultA + " " + tempObject.resultB);
        }
    }

    Вот такой вот калькулятор!

    alexhelkar, 30 Апреля 2015

    Комментарии (10)
  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. JavaScript / Говнокод #17992

    +162

    1. 1
    <div onclick="selectHoveer($('#type_tr2'));">

    Учитесь щенки как передавать элементы в функцию

    gam0ra, 14 Апреля 2015

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

    +77

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    val field = HttpEntityWrapper.class.getDeclaredField("wrappedEntity");
    field.setAccessible(true);
    
    HttpEntity entity = response.getEntity();
    
    while (entity instanceof HttpEntityWrapper) {
    	entity = (HttpEntity) field.get(entity);
    }
    
    log.info("Response entity class: {}", entity.getClass().getName());

    Чего только не приходится делать ради отладки...

    someone, 10 Апреля 2015

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

    +137

    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
    #include <iostream>
    
    template <typename T>
    struct Symbol {};
    
    template <>
    struct Symbol<int> {
        static constexpr const char value = 'd';
    };
    template <>
    struct Symbol<float> {
        static constexpr const char value = 'f';
    };
    
    template<std::size_t N, typename T>
    constexpr bool check_arg_part(const char (&s)[N], size_t i, T d)
    {
        if (i == N)
            return true;
    
        if (i < N - 1) {
            if (s[i] == '%') {
                if (s[i + 1] != Symbol<T>::value)
                    return false;
            }
        }
        return check_arg_part(s, i + 1, d);
    }
    
    template<std::size_t N, typename T>
    constexpr bool check_arg(const char (&s)[N], T d) {
        return check_arg_part(s, 0, d);
    }
    
    int main(int , char*[]) {
        std::boolalpha(std::cout);
    
    
        constexpr bool r = check_arg("foo is int: %d", 1);
        std::cout << "Argument integer is correct: " << r << std::endl;
        constexpr bool r1 = check_arg("foo is float:  %f", 1.0f);
        std::cout << "Argument float is correct: " << r1 << std::endl;
        constexpr bool r2 = check_arg("foo is float: %f", 1);
        std::cout << "Argument int is correct: " << r2 << std::endl;
    
        return 0;
    }

    По мотивам http://govnokod.ru/17925:

    Функция в compile time проверяет соответствие типов. Работает на clang и почему-то валится на gcc.

    gorthauer87, 09 Апреля 2015

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

    +158

    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
    $sql="select Id as Id from $table_work where SubstatusId=1 and StatusId=6 and ((UNIX_TIMESTAMP()-UNIX_TIMESTAMP(UpdTime))>25200)";
    $result=mysql_query($sql) or die();
    while($row = mysql_fetch_array($result)){
    	$sqlu="update $table_work set StatusId=5, SubstatusId=0 where Id=".$row["Id"];
    	mysql_query($sqlu) or die();
    	$sqlu="CALL set_history(".$row["Id"].",NULL,'Отказ роботом')";   ;Внимание Вопрос, что в черном ящике
    	mysql_query($sqlu) or die();
    }
    
    ; а там просто INSERT 0_o
    CREATE DEFINER=`vvejxoqw`@`localhost` PROCEDURE `set_last_time`(IN `UserId` int,IN `RegionId` int)
    BEGIN
    Insert LastGetQueue (UserId,RegionId,LastGetQueue) VALUE(UserId,RegionId,NOW());
    END$

    Ну и моё любимое SELECT Id AS Id
    p.s. попалась в руки цмc'ка написанная 1С прогером, ребята это ад. По 3 минуты ждешь результата на 8Mhz 8Gb VPS

    gumanoit, 05 Апреля 2015

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

    −117

    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
    def onRefreshReaders( self, event ):
    
    		#try:
    			self.readersListBox.Clear()
    			readers = self.burner.getReaders()
    
    			if isinstance(readers,BaseException):
    				raise BaseException("Can't find burner app!")
    
    			self.readersListBox.AppendItems(  readers)
    			self.readersListBox.SetSelection( 0 )
    		#except OSError as e:
    			#wx.MessageBox("Signer cant be empty!\n", "Error",wx.OK | wx.ICON_ERROR)

    qj,fysqhjn

    Anus, 31 Марта 2015

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