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

    +1

    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
    function send_message_with_photo($token, $peer_id, $message, $image_file_path) {
        $ch = curl_init();
    
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
    
        /* Получаем ссылку для загрузки фотографии */
    
        curl_setopt($ch, CURLOPT_URL, 'https://api.vk.com/method/photos.getMessagesUploadServer');
        curl_setopt($ch, CURLOPT_POSTFIELDS, array(
            "access_token" => $token,
            "v" => "5.103"
        ));
    
        $result = json_decode(curl_exec($ch), true);
    
        $upload_url = $result['response']['upload_url'];
    
        /* Отправляем фотографию */
    
        curl_setopt($ch, CURLOPT_URL, $upload_url);
        $file = curl_file_create($image_file_path);
        curl_setopt($ch, CURLOPT_POSTFIELDS, array(
            "photo" => $file,
        ));
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
    
        $result = json_decode(curl_exec($ch), true);
    
        $server = $result['server'];
        $photo = $result['photo'];
        $hash = $result['hash'];
    
        /* Сохраняем фотографию */    
    
        curl_setopt($ch, CURLOPT_URL, 'https://api.vk.com/method/photos.saveMessagesPhoto');
        curl_setopt($ch, CURLOPT_POSTFIELDS, array(
            "access_token" => $token,
            "v" => "5.103",
            "server" => $server,
            "photo" => $photo,
            "hash" => $hash
        ));
    
        $result = json_decode(curl_exec($ch), true);
    
        $photo_id = strval($result['response'][0]['id']);
        $owner_id = strval($result['response'][0]['owner_id']);
    
        $attachment = "photo" . $owner_id . "_" . $photo_id;
    
        /* Отправляем сообщение */
    
        curl_setopt($ch, CURLOPT_URL, 'https://api.vk.com/method/messages.send');
        curl_setopt($ch, CURLOPT_POSTFIELDS, array(
            "access_token" => $token,
            "v" => "5.103",
            "random_id" => rand(),
            "peer_id" => $peer_id,
            "message" => $message,
            "attachment" => $attachment 
        ));
    
        $result =  json_decode(curl_exec($ch), true);
    
        curl_close($ch);
    }

    Говнокод для загрузки фото в ВК)

    kaluginvlad, 01 Февраля 2020

    Комментарии (104)
  2. Python / Говнокод #26402

    −1

    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
    g = {'А', 'Е', 'Ё', 'И', 'У', 'О', 'Я', 'Ы', 'Э', 'Ю'}
    s = input().split()
    last = -1
    start = -1
    first = 0
    f = 0
    GL = 0
    gl = 0
    cnt = 0
    el = s[0]
    if len(s) == 1:
        el = s[0]
        for i in range(len(el)):
            if el[i].isupper() and el[i] not in g:
                print('ошибка')
                exit()
            if el[i].isupper() and f:
                print('ошибка')
                exit()
            if el[i].upper() in g:
                gl += 1
                GL += 1
            if el[i].isupper():
                start = gl
                f = 1
        if gl and not f:
            print('ошибка')
            exit()
        if start == -1:
            print('не стихи')
            exit()
        if (start == 2 and gl == 3) \
                or (start == 1 and gl == 2) \
                or (start == 2 and gl == 2):
            print('недостаточно информации')
            exit()
    last = -1
    start = -1
    first = 0
    GL = 0
    f = 0
    gl = 0
    cnt = 0
    el = s[0]
    while start == -1 and first < len(s):
        el = s[first]
        first += 1
        for i in range(len(el)):
            if el[i].isupper() and el[i] not in g:
                print('ошибка')
                exit()
            if el[i].isupper() and f:
                print('ошибка')
                exit()
            if el[i].upper() in g:
                gl += 1
                GL += 1
            if el[i].isupper():
                start = gl
                gl = 0
                f = 1
        if gl and not f:
            print('ошибка')
            exit()
    if start == -1:
        print('не стихи')
        exit()
    cnt = gl
    for k in range(first, len(s)):
        el = s[k]
        f = 0
        gl = 0
        cnt = cnt
        for i in range(len(el)):
            if el[i].upper() in g:
                cnt += 1
                gl += 1
                GL += 1
            if el[i].isupper() and el[i] not in g:
                print('ошибка')
                exit()
            if el[i].isupper() and f:
                print('ошибка')
                exit()
            if el[i].isupper():
                if last == -1:
                    last = cnt
                    cnt = 0
                elif cnt != last:
                    print('не стихи')
                    exit()
                else:
                    cnt = 0
                f = 1
        if gl and not f:
            print('ошибка')
            exit()

    if GL == 1:
    print('не стихи')
    exit()
    if start > 3 or last > 3 or cnt > 2:
    print('не стихи')
    exit()
    if start == 1:
    if last == 2 and cnt < last:
    print('хорей')
    elif (last == 3 or last == -1) \
    and cnt < 3:
    print('дактиль')
    else:
    print('не стихи')
    elif start == 2:
    if (last == 2 and cnt < last) \
    or last == -1:
    print('ямб')
    elif last == 3:
    print('амфибрахий')
    else:
    print('не стихи')
    elif start == 3 \
    and (last == 3 or last == -1):
    print('анапест')
    else:
    print('не стихи')

    kodic, 31 Января 2020

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

    0

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    $('#calculator').on('change', clr);
    	$('#calculator').on('change', total_sum);
    	$('#calculator').on('click', '.title', add_block);
    	$('#calculator').on('change', total_kg);
    	$("input[name='group1']").on('click', total_sum);
    	$("input[name='pack']").on('click', total_sum);
    	$('#calculator').on('click', '.title', total_sum);
    	$('#dop_block_0').html(
    		'<select size="1" name="paper" class="paper" id="paper_0">' +
    		'<option selected="" disabled="">Вид макулатуры</option>' +
    		'<option value="Картон">Картон</option>' +
    		'<option value="Книги, журналы">Книги, журналы</option>' +
    		'<option value="Архив">Архив</option>' +
    		'<option value="Полиэтилен">Полиэтилен</option>' +
    		'<option value="Газеты">Газеты</option>' +
    		'</select>' +
    		'<input type="text"  placeholder="Вес в килограммах" name="weight" class="masa" id="masa_0" min="0">' +
    		'<p>' +
    		'Цена (руб/кг): <input type="text" class="price" value="0" disabled=""><input type="hidden" class="cur" id="cur_0" value="0" disabled="">' +
    		'</p>'
    	);
    	function total_kg() {
    		var i = 0;
    		var kg_ol = 0;
    		while (i < 6) {
    			var t = +$("#masa_" + i).val();
    			if (t !== t) { t = 0 };
    			kg_ol += t;
    			i++;
    		}
    		if (kg_ol >= 300) {
    			$('#test').attr('disabled', false);
    		}
    		else {
    			$('#test').attr('disabled', true);
    			$('#test').attr('checked', false);
    			$('#test').attr('checked', true);
    		}
    	};
    	function total_sum() {
    		var i = 0;
    		var pri0 = $("#test_block_" + i).find('.cur').val();
    		var price_ol = 0;
    		if (pri0 !== pri0) { pri0 = 0 };
    		while (i < 6) {
    			var t = +$("#test_block_" + i).find('.cur').val();
    			if (t !== t) { t = 0 };
    			price_ol += t;
    			i++;
    		}
    		$('.cur_ol').text(price_ol);
    	};
    	function add_block() {
    		var parent_id = $(this).parent().attr('id');
    		if ($('#' + parent_id + ' .block_dop').text() == "") {
    			$('#' + parent_id + ' .block_dop').html('<select size="1"  name="paper" class="paper">' +
    				'<option selected disabled>Вид макулатуры</option>' +
    				'<option  value="Картон">Картон</option>' +
    				'<option value="Книги, журналы">Книги, журналы</option>' +
    				'<option value="Архив">Архив</option>' +
    				'<option value="Полиэтилен">Полиэтилен</option>' +
    				'<option value="Газеты">Газеты</option>' +
    				'</select>' +
    				'<input type="text" placeholder="Вес в килограммах" name="weight" class="masa" id="masa_' + colum + '" min="0">' +
    				'<p>Цена (руб/кг): <input  type="text" class="price" value="0" disabled><input  type="hidden" class="cur" value="0" disabled></p>' +
    				'<script>jQuery(function($){$("#masa_' + colum + '").mask("999999",{placeholder:"",autoclear: false});});</script>');
    			$('#' + parent_id + ' .block_dop').slideDown();
    			$(this).html('Убрать вид макулатуры');
    			if (colum < 5) {
    				console.log("1=2");
    				var st = colum + 1;
    				$('#calculator .param').append('<div id="dop_block_' + st + '" class="dop">' +
    					'<p class="title">Добавить вид макулатуры</p>' +
    					' <div class="block_dop"></div>' +
    					'</div>');
    				colum++;
    			};
    		}
    		else {
    			if (colum == 1) {
    				console.log("2=1");
    				$('#' + parent_id + ' .block_dop').slideUp();
    				$('#' + parent_id + ' .block_dop').html("");
    				$(this).html('Добавить вид макулатуры');
    				console.log("сolum=" + colum);
    			}
    			else {
    				console.log("2=2");
    				$('#' + parent_id).slideUp();
    				$('#' + parent_id).remove();
    				colum--;
    			};
    function clr() {
    		var i = 0;
    		while (i < 6) {
    			var price = 0;
    			var x = $("#dop_block_" + i).find('.paper').val();
    			if ($('input[name=group1]:checked').val() == 2 && $('input[name=pack]:checked').val() == 1){
    				switch (x) {
    					case '1'://Картон

    Кокой "Java Script"

    phpBidlokoder2, 31 Января 2020

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

    −3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Что это за бесячая стрелка на говнокоде, которая появляется при горизонтальном скроле?
    https://i.imgur.com/uRcKSDO.png
    
    Браузер - Opera. В FF, IE, Google Chrome - не воспроизводится. 
    Это заговр против Норвежских разработчиков?

    Her, 29 Января 2020

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

    +3

    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
    var owl3L = $('.owl-carousel3 .js__product').length;
        owl3L && $('.owl-carousel3').owlCarousel({
            ...
            responsive: {
                0: {
                    items: 1,
                    loop: owl3L > 1 ? true : false,
                    slideBy: 1
                },
                600: {
                    items: 2,
                    loop: owl3L > 2 ? true : false,
                    slideBy: 2
                },
                1000: {
                    items: 4,
                    loop: owl3L > 4 ? true : false,
                    slideBy: 4
                }
            }
        });

    Какой "Java Script"

    phpBidlokoder2, 29 Января 2020

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public function update_balance()
    	{
    		$this->balance = $this->balance_at_end_of_day(time());
    	}
        
           public function balance_at_end_of_day($time)
    	{
    		return $this->balance_at_beginning_of_day($time + 24*60*60);
    	}

    когда окунулся в легаси

    alucas, 28 Января 2020

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

    +2

    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
    // https://www.linux.org.ru/forum/development/15496357
    
    // Нужен нормальный способ сказать компилятору что type aliasing невозможен на некотором участке кода. Минимальный пример:
    
    template<typename T> struct f final {
    	void bad(T v) noexcept { while (b != e) *b++=v; }
    	void good(T v) noexcept {
    		auto tb(b), te(e);
    		while (tb != te) *tb++=v;
    		b=tb;
    		e=te;
    	}
    
    	T* b, * e;
    };
    template struct f<char>;
    /*
    Выхлоп gcc-8:
    
    $ g++ -xc++ -std=c++14 -pedantic-errors -Os -c -of.o f.cc
    $ objdump -Cd f.o
    f.o:     file format elf64-x86-64
    
    
    Disassembly of section .text._ZN1fIcE3badEc:
    
    0000000000000000 <f<char>::bad(char)>:
       0:	48 8b 07             	mov    (%rdi),%rax
       3:	48 3b 47 08          	cmp    0x8(%rdi),%rax
       7:	74 0c                	je     15 <f<char>::bad(char)+0x15>
       9:	48 8d 50 01          	lea    0x1(%rax),%rdx
       d:	48 89 17             	mov    %rdx,(%rdi)
      10:	40 88 30             	mov    %sil,(%rax)
      13:	eb eb                	jmp    0 <f<char>::bad(char)>
      15:	c3                   	retq   
    
    Disassembly of section .text._ZN1fIcE4goodEc:
    
    0000000000000000 <f<char>::good(char)>:
       0:	48 8b 07             	mov    (%rdi),%rax
       3:	48 8b 57 08          	mov    0x8(%rdi),%rdx
       7:	48 39 d0             	cmp    %rdx,%rax
       a:	74 09                	je     15 <f<char>::good(char)+0x15>
       c:	48 ff c0             	inc    %rax
       f:	40 88 70 ff          	mov    %sil,-0x1(%rax)
      13:	eb f2                	jmp    7 <f<char>::good(char)+0x7>
      15:	48 89 07             	mov    %rax,(%rdi)
      18:	48 89 47 08          	mov    %rax,0x8(%rdi)
      1c:	c3                   	retq
    */

    f<char>::bad(char)+0, f<char>::bad(char)+3 и f<char>::bad(char)+d - три раза за итерацию лезет в память. Разумеется, подобный код сливает в тестах производительности. Есть решение лучше, чем локальные переменные заводить каждый раз?

    j123123, 28 Января 2020

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

    −1

    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
    (function(){
      const panel = document.querySelector('.pane-content > ul');
      function appendLink(text, href) {
        const li = document.createElement('li');
        const a = document.createElement('a');
        li.appendChild(a);
        a.setAttribute('href', href);
        a.innerText = text;
        panel.appendChild(li);
      }
      appendLink("Перелогиниться", 'https://govnokod.ru/user/exit/?url=https://govnokod.ru/user/login');
      appendLink("Регистрация", 'https://govnokod.ru/user/exit/?url=https://govnokod.ru/user/register');
    })();

    Кокококое у гк удобне апи )))

    KpunoBblu_nemyx, 28 Января 2020

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

    +2

    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
    #include <iostream>
    using namespace std;
    bool check(int a, int b){
    	int ass[10] = {0}, bass[10] = {0};
    	while(a){
    		ass[a % 10]++;
    		bass[b % 10]++;
    		a /= 10;
    		b /= 10;
    	}
    	for(int i = 0; i < 10; i++){
    		if(ass[i] != bass[i]) return false;
    	}
    	return true;
    }
    int main() {
    	for(int i = 1; i < 10; i++){
    		for(int j = 0; j < 10; j++){
    			for(int k = 0; k < 10; k++){
    				for(int l = 0; l < 10; l++){
    					for(int m = 0; m < 10; m++){
    						for(int n = 0; n < 10; n++){
    							for(int o = 0; o < 10; o++){
    								for(int p = 0; p < 10; p++){
    									for(int r = 1; r < 10; r++){
    											long long a =
    											i * 100000000
    											+ j * 10000000
    											+ k * 1000000
    											+ l * 100000
    											+ m * 10000
    											+ n * 1000
    											+ o * 100
    											+ p * 10
    											+ 3;
    											long long z = r * 10000000
    											+ r * 1000000
    											+ r * 100000
    											+ r * 10000
    											+ r * 1000
    											+ r * 100
    											+ r * 10
    											+ r;
    											if(check(a, a + z)){
    												cout << a << " " << z << endl;
    											}
    									}
    								}
    							}
    						}
    					}
    				}
    			}
    		}
    	}
    }

    Коротко о переборах.

    Verenick, 28 Января 2020

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

    −2

    1. 1
    IT Оффтоп #29

    #1: https://govnokod.ru/18142 https://govnokod.xyz/_18142
    #2: https://govnokod.ru/18378 https://govnokod.xyz/_18378
    #3: https://govnokod.ru/19667 https://govnokod.xyz/_19667
    #4: https://govnokod.ru/21160 https://govnokod.xyz/_21160
    #5: https://govnokod.ru/21772 https://govnokod.xyz/_21772
    #6: https://govnokod.ru/24063 (потёр пидор сракер) https://govnokod.xyz/_24063
    #7: https://govnokod.ru/24538 https://govnokod.xyz/_24538
    #8: https://govnokod.ru/24815 (потёр пидор сракер) https://govnokod.xyz/_24815
    #9: https://govnokod.ru/24867 https://govnokod.xyz/_24867
    #10: https://govnokod.ru/25328 https://govnokod.xyz/_25328
    #11: https://govnokod.xyz/_25436 https://govnokod.ru/25436 (потёр пидор сракер)
    #12: https://govnokod.xyz/_25471
    #13: https://govnokod.xyz/_25590 (потёр пидор сракер)
    #14: https://govnokod.xyz/_25684
    #15: https://govnokod.xyz/_25694
    #16: https://govnokod.xyz/_25725
    #17: https://govnokod.xyz/_25731
    #18: https://govnokod.xyz/_25762
    #19: https://govnokod.xyz/_25767
    #20: https://govnokod.xyz/_25776
    #21: https://govnokod.xyz/_25798
    #22: https://govnokod.xyz/_25811
    #23: https://govnokod.xyz/_25863
    #24: https://govnokod.xyz/_25941
    #25: https://govnokod.xyz/_26026
    #26: https://govnokod.xyz/_26050
    #27: https://govnokod.xyz/_26340
    #28: https://govnokod.xyz/_26372

    syoma, 28 Января 2020

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