1. Куча / Говнокод #18141

    +142

    1. 1
    URxvt*foreground: #C0C0C0

    Вот что монокай с urxvt делает.

    codemonkey, 10 Мая 2015

    Комментарии (0)
  2. Java / Говнокод #18140

    +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
    String tp22 = "";
    int v1 = (Math.random(8))+1;
     if (v1=1)
     { tp22.charAt(1)="a";}
     if (v1=2)
     { tp22.charAt(1)="b";}
     if (v1=3)
     { tp22.charAt(1)="c";}
     if (v1=4)
     { tp22.charAt(1)="d";}
     if (v1=5)
     { tp22.charAt(1)="e";}
     if (v1=6)
     { tp22.charAt(1)="f";}
     if (v1=7)
     { tp22.charAt(1)="g";}
     if (v1=8)
     { tp22.charAt(1)="h";}
     if (v1=9)
     { tp22.charAt(1)="i";}

    Получаем случайную букву.

    Imp, 10 Мая 2015

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

    +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
    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
    typedef enum {
            INIT1=0, INIT2,  INIT3,  INIT4,  INIT5,  INIT6,  INITN,
            BIND1,   BIND2,  BIND3,  BIND4,  BIND5,  BIND6,  BINDN,
            YIELD1,  YIELD2, YIELD3, YIELD4, YIELD5, YIELD6, YIELDN, 
            COMPARE, CHECK, FILTER, CFILTER, PFILTER, CHOOSE, NOOP, CONTINUE,
            GET_ENODE, 
            GET_CGR1, GET_CGR2, GET_CGR3, GET_CGR4, GET_CGR5, GET_CGR6, GET_CGRN,
            IS_CGR
        } opcode;
    ...
    ...
    ...
    
    
    
            switch (m_pc->m_opcode) {
            case INIT1:
                m_app          = m_registers[0];
                if (m_app->get_num_args() != 1)
                    goto backtrack;
                m_registers[1] = m_app->get_arg(0);
                m_pc = m_pc->m_next;
                goto main_loop;
                
            case INIT2:
                m_app          = m_registers[0];
                if (m_app->get_num_args() != 2)
                    goto backtrack;
                m_registers[1] = m_app->get_arg(0);
                m_registers[2] = m_app->get_arg(1);
                m_pc = m_pc->m_next;
                goto main_loop;
                
            case INIT3:
                m_app          = m_registers[0];
                if (m_app->get_num_args() != 3)
                    goto backtrack;
                m_registers[1] = m_app->get_arg(0);
                m_registers[2] = m_app->get_arg(1);
                m_registers[3] = m_app->get_arg(2);
                m_pc = m_pc->m_next;
                goto main_loop;
                
            case INIT4:
                m_app          = m_registers[0];
                if (m_app->get_num_args() != 4)
                    goto backtrack;
                m_registers[1] = m_app->get_arg(0);
                m_registers[2] = m_app->get_arg(1);
                m_registers[3] = m_app->get_arg(2);
                m_registers[4] = m_app->get_arg(3);
                m_pc = m_pc->m_next;
                goto main_loop;
                
            case INIT5:
                m_app          = m_registers[0]; 
                if (m_app->get_num_args() != 5)
                    goto backtrack;
                m_registers[1] = m_app->get_arg(0);
                m_registers[2] = m_app->get_arg(1);
                m_registers[3] = m_app->get_arg(2);
                m_registers[4] = m_app->get_arg(3);
                m_registers[5] = m_app->get_arg(4);
                m_pc = m_pc->m_next;
                goto main_loop;
                
            case INIT6: 
                m_app          = m_registers[0];
                if (m_app->get_num_args() != 6)
                    goto backtrack;
                m_registers[1] = m_app->get_arg(0);
                m_registers[2] = m_app->get_arg(1);
                m_registers[3] = m_app->get_arg(2);
                m_registers[4] = m_app->get_arg(3);
                m_registers[5] = m_app->get_arg(4);
                m_registers[6] = m_app->get_arg(5);
                m_pc = m_pc->m_next;
                goto main_loop;
                
            case INITN:
                m_app      = m_registers[0];
                m_num_args = m_app->get_num_args();
                if (m_num_args != static_cast<const initn *>(m_pc)->m_num_args)
                    goto backtrack;
                for (unsigned i = 0; i < m_num_args; i++)
                    m_registers[i+1] = m_app->get_arg(i);
                m_pc = m_pc->m_next;
                goto main_loop;

    Из изходников STM-солвера Z3
    https://github.com/Z3Prover/z3/blob/master/src/smt/mam.cpp#L2298
    Почему нельзя было оставить только вариант INITN? Цикл отбирает так много ресурсов?

    j123123, 10 Мая 2015

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

    +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
    29. 29
    30. 30
    31. 31
    32. 32
    class Ship{
    
    public static void main(String []args){
    //бла-бла-бла
    String s = Ship.getTp22();
    }
    String getTp22(){
    public String tp22 = "-*";
    int v1 = (Math.random(8))+1;
     if (v1=1)
     { tp22.charAt(1)="a";}
     if (v1=2)
     { tp22.charAt(1)="b";}
     if (v1=3)
     { tp22.charAt(1)="c";}
     if (v1=4)
     { tp22.charAt(1)="d";}
     if (v1=5)
     { tp22.charAt(1)="e";}
     if (v1=6)
     { tp22.charAt(1)="f";}
     if (v1=7)
     { tp22.charAt(1)="g";}
     if (v1=8)
     { tp22.charAt(1)="h";}
     if (v1=9)
     { tp22.charAt(1)="i";}
    
    return tp22;
    }
    
    }

    Гениальный способ генерации строки со случайной буквой.

    Imp, 10 Мая 2015

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    function GetArgs(const str:string):string;
    begin
      result:=strpas(pathgetargs(pchar(str))); //UB
    end;

    result:=strpas(pathgetargs(pchar(str))); //UB
    Плохой мальчик.

    Stertor, 09 Мая 2015

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

    +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
    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
    95. 95
    96. 96
    97. 97
    //Search from title,content,category,address,zipcode,city
        if ($s_for !== '' && $s_cat !== '' && $s_to !== '') {
            $query = "SELECT *
                FROM
                $wpdb->posts
                INNER JOIN $wpdb->term_relationships
                ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
                LEFT JOIN $wpdb->postmeta 
                ON $wpdb->posts.ID = $wpdb->postmeta.post_id
                WHERE
                $wpdb->posts.post_status = '$cc_post_status'
                AND $wpdb->posts.post_type = '$cc_post_type'
                AND ($wpdb->posts.post_title LIKE '%$s_for%'
                OR $wpdb->posts.post_content LIKE '%$s_for%')
                AND (($wpdb->postmeta.meta_key = '$cc_meta_address' AND $wpdb->postmeta.meta_value LIKE '%$s_to%')
                OR ($wpdb->postmeta.meta_key = '$cc_meta_city' AND $wpdb->postmeta.meta_value = '$s_to')
                OR ($wpdb->postmeta.meta_key = '$cc_meta_zipcode' AND $wpdb->postmeta.meta_value = '$s_to'))
                AND $wpdb->term_relationships.term_taxonomy_id = {$s_cat}
                GROUP BY ID {$limit}";
            //Search from title,content
        } elseif ($s_for !== '' && $s_cat == '' && $s_to == '') {
            $query = "SELECT *
                FROM
                $wpdb->posts
                INNER JOIN $wpdb->term_relationships
                ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
                INNER JOIN $wpdb->terms
                ON $wpdb->term_relationships.term_taxonomy_id = $wpdb->terms.term_id
                WHERE
                $wpdb->posts.post_status = '$cc_post_status' AND post_type = '$cc_post_type' 
                AND ($wpdb->terms.name = '$s_for' or post_title like '%$s_for%' or post_content like '%$s_for%') 
                GROUP BY ID {$limit}";
            //Search from title,content and category
        } elseif ($s_for !== '' && $s_cat !== '' && $s_to == '') {
            $query = "SELECT $wpdb->posts.*
                FROM
                $wpdb->posts
                INNER JOIN $wpdb->term_relationships
                ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
                WHERE
                $wpdb->posts.post_type = '$cc_post_type'
                AND 
                $wpdb->posts.post_status = '$cc_post_status'
                AND
                ($wpdb->posts.post_title LIKE '%$s_for%' OR $wpdb->posts.post_content LIKE '%$s_for%')
                AND
                ($wpdb->term_relationships.term_taxonomy_id = {$s_cat})
                GROUP BY ID {$limit}";
            //Search from category,zip,address and city
        } elseif ($s_for == '' && $s_cat !== '' && $s_to !== '') {
            $query = "SELECT $wpdb->posts.*
                FROM
                $wpdb->posts
                INNER JOIN $wpdb->postmeta
                ON $wpdb->posts.ID = $wpdb->postmeta.post_id
                INNER JOIN $wpdb->term_relationships
                ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
                WHERE
                $wpdb->posts.post_type = '$cc_post_type'
                AND $wpdb->posts.post_status = '$cc_post_status'
                AND
                ($wpdb->term_relationships.term_taxonomy_id = {$s_cat})
                AND (($wpdb->postmeta.meta_key ='$cc_meta_address' AND $wpdb->postmeta.meta_value LIKE '%$s_to%')
                OR ($wpdb->postmeta.meta_key ='$cc_meta_city' AND $wpdb->postmeta.meta_value = '$s_to')
                OR ($wpdb->postmeta.meta_key ='$cc_meta_zipcode' AND $wpdb->postmeta.meta_value = '$s_to'))
                GROUP BY ID {$limit}";
            //Search from category
        } elseif ($s_for == '' && $s_cat !== '' && $s_to == '') {
            $query = "SELECT $wpdb->posts.*
                FROM
                $wpdb->posts
                INNER JOIN $wpdb->term_relationships
                ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
                WHERE
                $wpdb->posts.post_type = '$cc_post_type'
                AND $wpdb->posts.post_status = '$cc_post_status'
                AND
                ($wpdb->term_relationships.term_taxonomy_id = {$s_cat})
                GROUP BY ID {$limit}";
            //Search from address,city and zipcode
        } elseif ($s_for == '' && $s_cat == '' && $s_to !== '') {
            $query = "SELECT $wpdb->posts.*
                FROM
                $wpdb->posts
                INNER JOIN $wpdb->postmeta
                ON $wpdb->posts.ID = $wpdb->postmeta.post_id
                WHERE
                $wpdb->posts.post_type = '$cc_post_type'
                AND $wpdb->posts.post_status = '$cc_post_status'                                  
                AND (($wpdb->postmeta.meta_key ='$cc_meta_address' AND $wpdb->postmeta.meta_value LIKE '%$s_to%')
                OR ($wpdb->postmeta.meta_key ='$cc_meta_city' AND $wpdb->postmeta.meta_value = '$s_to')
                OR ($wpdb->postmeta.meta_key ='$cc_meta_zipcode' AND $wpdb->postmeta.meta_value = '$s_to'))
                GROUP BY ID {$limit}";
            //Search from tags,title,content and zipcode,city,address
        } elseif ($s_for !== '' && $s_cat == '' && $s_to !== '') {
    
        // And so on .... until all possible combinations of arguments

    Classicraft wordpress theme ... luckily he had only 3 arguments :D

    alex_123, 09 Мая 2015

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

    −94

    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
    # Мы хотели бы подключиться к базе данных. Мы не знаем, верны ли логин и пароль
    # Если соединение с базой будет неуспешно, то
    # Он бросит исключение. Обратите внимание, что MyDatabase и DatabaseException
    # НЕ являются реальными классами, мы просто используем их в качестве примеров.
    
    try:
        database = MyDatabase(db_host, db_user, db_password, db_database)
        database_connection = database.connect()
    except DatabaseException:
        pass
    
    if database_connection is None:
        print('The database could not connect')
    else:
        print('The database could connect')

    Часто вы хотите выполнить действие, которое может работать либо завершиться неудачно. Используя None, вы можете проверить успех действия. Вот пример:

    3_14dar, 09 Мая 2015

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

    +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
    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
    function cvet(){
    
    var i=Math.ceil(Math.random() *80);
    
    if (i > 0 && i <= 10 ) a = 0;
    if (i > 0 && i <= 10 ) b = 0;
    if (i > 0 && i <= 10 ) c = 255;
    if (i > 0 && i <= 10 ) d = 1;
    else
    
    if (i > 10 && i <= 20 ) a = 0;
    if (i > 10 && i <= 20 ) b = 0;
    if (i > 10 && i <= 20 ) c = 255;
    if (i > 10 && i <= 20 ) d = 1;
    else
    if (i > 20 && i <= 30 ) a = 0;
    if (i > 20 && i <= 30 ) b = 255;
    if (i > 20 && i <= 30 ) c = 0;
    if (i > 20 && i <= 30 ) d = 1;
    else
    if (i > 30 && i <= 40 ) a = 0;
    if (i > 30 && i <= 40 ) b = 255;
    if (i > 30 && i <= 40 ) c = 255;
    if (i > 30 && i <= 40 ) d = 1;
    else
    if (i > 40 && i <= 50 ) a = 255;
    if (i > 40 && i <= 50 ) b = 0;
    if (i > 40 && i <= 50 ) c = 0;
    if (i > 40 && i <= 50 ) d = 1;
    else
    if (i > 50 && i <= 60 ) a = 255;
    if (i > 50 && i <= 60 ) b = 0;
    if (i > 50 && i <= 60 ) c = 255;
    if (i > 50 && i <= 60 ) d = 1;
    else
    if (i > 60 && i <= 70 ) a = 255;
    if (i > 60 && i <= 70 ) b = 255;
    if (i > 60 && i <= 70 ) c = 0;
    if (i > 60 && i <= 70 ) d = 1;
    else
    if (i > 70 && i <= 80 ) a = 255;
    if (i > 70 && i <= 80 ) b = 255;
    if (i > 70 && i <= 80 ) c = 255;
    if (i > 70 && i <= 80 ) d = 1;

    Целиком: https://jsfiddle.net/allcoma/x85w48Lj/

    buyfn, 09 Мая 2015

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

    +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
    <?php
    // cfg.php
    class DBcfg {
    	static $dbopt = array
    	(
    		'db_serv' => '',
    		'db_user' => 'h3ld1k',
    		'db_pass' => '',
    		'db_name' => '',
    		'db_prefix' => 'bp'
    	);
    }
    ?>
    
    <?php
    // core.php
    $database = @mysqli_connect("", "", "", "");
    if( mysqli_connect_errno() ) 
    {
        exit( "Не удалось подключиться к БД! Ошибка: " . mysqli_connect_error() . "" );
    }

    Ну вот так както =)

    Onotole, 08 Мая 2015

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

    +143

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    <? foreach ($arResult["SIZES"] as $skuId => $size): ?>
    	<? if ($skuId == $arResult["SKU_ID"]): ?>
    	<option value="<?= $skuId ?>" selected="selected" data-product-size="<?= $size ?>"><?= $size ?></option>
    	<? else: ?>
    	<option value="<?= $skuId ?>"
    		data-product-url="<?= $arResult["SKU_LIST"][$skuId]["DETAIL_PAGE_URL"] ?>"
    		data-product-size="<?= $size ?>"
    		<? if ($skuId == $arResult["SKU_ID"]) echo 'selected="selected"' ?>><?= $size ?></option>
    	<? endif ?>
    <? endforeach; ?>

    turbosnail, 08 Мая 2015

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