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

    +153

    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
    php_sapi_name() === 'cli' or exit('Only CLI mode allowed');
    
    getenv('API_HOST') or exit(<<<EOT
    
      To run tests you should setup "API_HOST" environment variable.
      Try follow in bash command line:
    
      $ export API_HOST=<api_host>
      cd path/to/tests
      php direct_report_problem.php
    
    
    EOT
    );
    
    defined('API_ENDPOINT') || define('API_ENDPOINT', getenv('API_HOST') . '/webservice/index.php');
    
    $method = API_ENDPOINT . '?op=...';
    
    $describe = function ($msg, $test) {
        printf("\n\n[%s]\n\n%s\n\n", $msg, shell_exec($test()));
        sleep(2);
    };
    
    $describe('Cannot upload empty report', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' ' . $method;
    });
    
    $describe('Can upload only direct report note', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' -F problem_note=NOTE'
        . ' ' . $method;
    });
    
    $describe('Can upload only direct report sound', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' -F [email protected]'
        . ' ' . $method;
    });
    
    $describe('Can upload only direct report image', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' -F [email protected]'
        . ' ' . $method;
    });
    
    $describe('Can upload all data direct report note, image, sound', function() use ($method) {
        return 'curl'
        . ' -F user_id=61'
        . ' -F problem_note=NOTE'
        . ' -F [email protected]'
        . ' -F [email protected]'
        . ' ' . $method;
    });

    __proto__, 10 Декабря 2013

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

    +155

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function lastDay($month, $year) {
        if ($month != 12) {
            $m = $month + 1;
            $y = $year;
        } else {
            $m = 1;
            $y = $year + 1;
        }
        return strftime("%d", mktime(0, 0, 0, $m, 0, $y));
    }

    Оригинальный и дофига понятный способ получить последний день текущего месяца.

    anton0xf, 09 Декабря 2013

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

    +154

    1. 1
    2. 2
    $date = date("Y-m-01", strtotime("-1 month"));
    $like = substr($date, 0, 8) . "%";

    а потом $like вставляется в sql-код

    anton0xf, 09 Декабря 2013

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    var infoDiv = "<div id='fastInfo' style='font-size:16px !important;padding: 6px;padding-bottom:10px; z-index:1000000;position:fixed;top:20%;width:3px;right:0;background:white;border: 1px solid green;border-right:0;'></div>";
    $('#navi').before(infoDiv);
    var ggwp = $('a[href*="user_info="]');
    $.each(ggwp, function(index, value) {
    	value.setAttribute("onmouseenter", "$('#fastInfo').animate({'width': '300px'}, 200);function received(data) { if ($($(data).find('.gradient_block1:has(\"table\")')[0]).html() == undefined) {dtxs = $($(data).find('.stnd_padd:has(\"table\")')[0]).html().replace('img', 'xuimg');} else {dtxs = $($(data).find('.gradient_block1:has(\"table\")')[0]).html().replace('img', 'xuimg');}	$('#fastInfo').html('<span style=\"font-size:small\">' + dtxs + '<hr style=\"border:0;height:1px;background-color:black;margin:6px;color:black\" /><div style=\"padding-left:13px\">' + $($(data).find('.bottom_link_block')[0]).html() + '</div><hr style=\"border:0;height:1px;background-color:black;margin:6px;color:black\" /><div style=\"padding-left:13px;font-size:small\">' + $($(data).find('.blue_border_bottom')[0]).html().replace(/padding-bottom:10px;/gim, ''));}$.ajax({'url': 'http://spaces.ru/anketa/?name=" + value.href.match(/user_info=([a-zA-Z0-9\-\_]+)/gim)[0].replace("user_info=", "") + "', success: received});");
    	value.setAttribute("onmouseleave", "$('#fastInfo').animate({'width': '3px'}, 200);function clrscr() {$('#fastInfo').html('');} setTimeout(clrscr, 200);");
    });

    Ребят, это диагноз?
    Навесить обработчик через .on/.bind/.live не смог.

    Efog, 09 Декабря 2013

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

    +122

    1. 1
    2. 2
    3. 3
    Не смог выделить 100 строк, объединённых общей логикой, да и всей картины это бы не передавало.
    Для любителей покопаться в. 
    Ссылка в описании.

    https://github.com/KustoSoft/ru2ch-toolset
    © Корпорация KustoSoft

    jsgovno, 08 Декабря 2013

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

    +78

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public class LocalizedMatcher implements Matcher, ContainsExtraTypeInformation, CapturesArguments, MatcherDecorator, Serializable {
    
        ...
     
        public void _dont_implement_Matcher___instead_extend_BaseMatcher_() {
            // yeah right
        }
    
        ...
    
    }

    Порадовал именно коммент :)

    myzone, 08 Декабря 2013

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

    +9

    1. 1
    #   define BOOST_MPL_AUX_NTTP_DECL(T, x) T x

    Очень интересный стайлгайд Алексей Гуртового

    crastinus, 07 Декабря 2013

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

    +9

    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
    int numBlock = 0;
        for(int i = 0; i < 16; i++)
            for(int j = 0; j < 25; j++)
            {
    
            if(levelInfo[i][j].active)
            {
            if(levelInfo[i][j].part && levelInfo[i][j].type) continue;
            if(levelInfo[i][j].type)
            {
                tempLevel[numBlock*8  ] = i*24;
                tempLevel[numBlock*8+1] = (j)*24;
                tempLevel[numBlock*8+2] = (i+2)*24;
                tempLevel[numBlock*8+3] = (j)*24;
                tempLevel[numBlock*8+4] = (i+2)*24;
                tempLevel[numBlock*8+5] = (j+1)*24;
                tempLevel[numBlock*8+6] = i*24;
                tempLevel[numBlock*8+7] = (j+1)*24;
            }
            else
            {
                tempLevel[numBlock*8  ] = i*24;
                tempLevel[numBlock*8+1] = (j)*24;
                tempLevel[numBlock*8+2] = (i+1)*24;
                tempLevel[numBlock*8+3] = (j)*24;
                tempLevel[numBlock*8+4] = (i+1)*24;
                tempLevel[numBlock*8+5] = (j+1)*24;
                tempLevel[numBlock*8+6] = i*24;
                tempLevel[numBlock*8+7] = (j+1)*24;
            }
    
            if(levelInfo[i][j].type)
                for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[0][k];
            else
                for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[1][k];
            }
            else
            {
            tempLevel[numBlock*8  ] = i*24;
            tempLevel[numBlock*8+1] = (j)*24;
            tempLevel[numBlock*8+2] = (i+1)*24;
            tempLevel[numBlock*8+3] = (j)*24;
            tempLevel[numBlock*8+4] = (i+1)*24;
            tempLevel[numBlock*8+5] = (j+1)*24;
            tempLevel[numBlock*8+6] = i*24;
            tempLevel[numBlock*8+7] = (j+1)*24;
            for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[2][k];
            }
            numBlock++;
            }
    
        for(int i = 0; i < 2; i++)
            for(int j = 0; j < 3; j++)
            {
                if(!fallBlocks[i][j].active) continue;
                if(fallBlocks[i][j].part && fallBlocks[i][j].type) continue;
                if(!fallBlocks[i][j].type)
                {
                    tempLevel[numBlock*8  ] = (fallPosX+i)*24;
                    tempLevel[numBlock*8+1] = (fallPosY-j)*24;
                    tempLevel[numBlock*8+2] = (fallPosX+i+1)*24;
                    tempLevel[numBlock*8+3] = (fallPosY-j)*24;
                    tempLevel[numBlock*8+4] = (fallPosX+i+1)*24;
                    tempLevel[numBlock*8+5] = (fallPosY-j+1)*24;
                    tempLevel[numBlock*8+6] = (fallPosX+i)*24;
                    tempLevel[numBlock*8+7] = (fallPosY-j+1)*24;
                    for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[1][k];
                }
                else
                {
                    tempLevel[numBlock*8  ] = (fallPosX+i)*24;
                    tempLevel[numBlock*8+1] = (fallPosY-j)*24;
                    tempLevel[numBlock*8+2] = (fallPosX+i+2)*24;
                    tempLevel[numBlock*8+3] = (fallPosY-j)*24;
                    tempLevel[numBlock*8+4] = (fallPosX+i+2)*24;
                    tempLevel[numBlock*8+5] = (fallPosY-j+1)*24;
                    tempLevel[numBlock*8+6] = (fallPosX+i)*24;
                    tempLevel[numBlock*8+7] = (fallPosY-j+1)*24;
                    for(int k = 0; k < 8; k++) tempTex[numBlock*8+k] = coord[0][k];
                }
                numBlock++;
            }

    Нямка. В унитаз уже не помещается, вылью сюда

    pelmenka, 07 Декабря 2013

    Комментарии (17)
  9. PHP / Говнокод #14193

    +155

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if ($localize && is_array($results))
    	foreach ($results as $_k => $_row)
    		foreach ((array) $_row as $_rc => $_col)
    			if ($_col_unserialized = unserialize($_col))
    				if (is_array($_col_unserialized))
    					if (isset($_col_unserialized[$_SESSION['language']]))
    						$results[$_k]->{$_rc} = $_col_unserialized[$_SESSION['language']];
    					else
    						$results[$_k]->{$_rc} = array_shift($_col_unserialized);

    fidelcomandante, 07 Декабря 2013

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

    +28

    1. 1
    QVector<double*>*** ElemBoundCond = tbc->getElementsBC();

    Abbath, 06 Декабря 2013

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