1. JavaScript / Говнокод #26472

    +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
    var buf = Buffer.allocUnsafe(kexInitSize);
        var p = 17;
    
        buf[0] = MESSAGE.KEXINIT;
    
        if (myCookie !== false)
          myCookie.copy(buf, 1);
    
        writeUInt32BE(buf, kexBuf.length, p);
        p += 4;
        kexBuf.copy(buf, p);
        p += kexBuf.length;
    
        writeUInt32BE(buf, hostKeyBuf.length, p);
        p += 4;
        hostKeyBuf.copy(buf, p);
        p += hostKeyBuf.length;
    
        writeUInt32BE(buf, algos.cipherBuf.length, p);
        p += 4;
        algos.cipherBuf.copy(buf, p);
        p += algos.cipherBuf.length;
    
        writeUInt32BE(buf, algos.cipherBuf.length, p);
        p += 4;
        algos.cipherBuf.copy(buf, p);
        p += algos.cipherBuf.length;
    
        writeUInt32BE(buf, algos.hmacBuf.length, p);
        p += 4;
        algos.hmacBuf.copy(buf, p);
        p += algos.hmacBuf.length;
    
        writeUInt32BE(buf, algos.hmacBuf.length, p);
        p += 4;
        algos.hmacBuf.copy(buf, p);
        p += algos.hmacBuf.length;
    
        writeUInt32BE(buf, algos.compressBuf.length, p);
        p += 4;
        algos.compressBuf.copy(buf, p);
        p += algos.compressBuf.length;
    
        writeUInt32BE(buf, algos.compressBuf.length, p);
        p += 4;
        algos.compressBuf.copy(buf, p);
        p += algos.compressBuf.length;
    
        // Skip language lists, first_kex_packet_follows, and reserved bytes
        buf.fill(0, buf.length - 13);

    Мечтают ли скриптухи об Электросишке?

    https://github.com/mscdex/ssh2-streams/blob/master/lib/ssh.js

    3.14159265, 07 Марта 2020

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

    +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
    > At its core, Swarm implements a distributed content-addressed chunk store. 
    > Chunks are arbitrary data blobs with a fixed maximum size (currently 4KB). 
    > Content addressing means that the address of any chunk is deterministically derived from its content. 
    > The addressing scheme falls back on a hash function which takes a chunk as input and returns a 32-byte long key as output. 
    > A hash function is irreversible, collision free and uniformly distributed (indeed this is what makes bitcoin, and in general proof-of-work, work).
    
    исключая лишнее
    
    > derived from content
    > content = 4KB
    > 32-byte output
    > collision free!

    И еще немного несвежых новостей из мира, где «блокчейн» стал устойчивым синонимом слова «распределенный»

    https://blog.ethereum.org/2016/12/15/swarm-alpha-public-pilot-basics-swarm/

    Fike, 07 Марта 2020

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

    +2

    1. 1
    2. 2
    3. 3
    Global Install
    Installing Yarn 2.x globally is discouraged as we're moving to a per-project install strategy. 
    We advise you to keep Yarn 1.x (Classic) as your global binary by installing it via the instructions you can find here.

    https://yarnpkg.com/getting-started/install

    Мы выпустили вторую версию приложеньки, в которой исправили все недочёты первой.
    Именно поэтому запускать вы её будете через первую версию, которая с вами навсегда.
    Мы проработали другие варианты и пришли к решению, что они все неправильные.

    Сердечно ваши,
    джаваскриптеры.

    Fike, 07 Марта 2020

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

    +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
    #include <iostream>
    #include <iomanip>
    #include <sstream>
     
    int main()
    {
        std::stringstream ss;
        std::string in = "String with spaces, and embedded \"quotes\" too";
        std::string out;
     
        ss << std::quoted(in);
        std::cout << "read in     [" << in << "]\n"
                  << "stored as   [" << ss.str() << "]\n";
     
        ss >> std::quoted(out);
        std::cout << "written out [" << out << "]\n";
    
    // read in     [String with spaces, and embedded "quotes" too]
    // stored as   ["String with spaces, and embedded \"quotes\" too"]
    // written out [String with spaces, and embedded "quotes" too]
    }

    Блядь! В крестостандарте есть стандартная функция для экранирования кавычек!
    Интересно, когда нам ждать std::mysql_real_escape_string()?

    https://en.cppreference.com/w/cpp/io/manip/quoted

    gost, 07 Марта 2020

    Комментарии (108)
  5. C# / Говнокод #26468

    +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
    // Задача: Рисовать в консоли прогресс бар, на сколько дней текущий год завершился
    
    static void ProgressBarOfElapsedDays(DateTime dateTime, bool isRefreshebleat = false)   // рефрешеБЛЕАТ! :))
    {
        int daysOfYear = DateTime.IsLeapYear(dateTime.Year) ? 366 : 365;
        int dayInProcents = daysOfYear * 100 / 100;     // WAT?
        int currentDay = dateTime.DayOfYear * 100;
        int daysOfYearNotElapsed = daysOfYear * 100 - currentDay;  // Сложный матан
        int procent = 100 - (daysOfYear * 100 - currentDay) / dayInProcents; 
        int buffer = 0;
    
        if (isRefreshebleat)
        {
            if (Console.CursorTop >= 1 || Console.CursorLeft >= 1)
            {
                Console.SetCursorPosition(Console.CursorLeft - Console.CursorLeft, Console.CursorTop - Console.CursorTop); // когда Console.SetCursorPosition(0, 0) недостаточно
            }
        }
    
        // остальной код
    }

    isRefreshebleat и всё остальное :))

    adoconnection, 06 Марта 2020

    Комментарии (59)
  6. 1C / Говнокод #26467

    +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
    ОбластьТело.Параметры.Нерабочий = ?(
    	(Месяц(СсылкаНаОбъект.ДатаНачалаСобытия) = 1 И (День(СсылкаНаОбъект.ДатаНачалаСобытия) = 1 
    		ИЛИ День(СсылкаНаОбъект.ДатаНачалаСобытия) = 2 
    		ИЛИ День(СсылкаНаОбъект.ДатаНачалаСобытия) = 3 
    		ИЛИ День(СсылкаНаОбъект.ДатаНачалаСобытия) = 4 
    		ИЛИ День(СсылкаНаОбъект.ДатаНачалаСобытия) = 5 
    		ИЛИ День(СсылкаНаОбъект.ДатаНачалаСобытия) = 6 
    		ИЛИ День(СсылкаНаОбъект.ДатаНачалаСобытия) = 7 
    		ИЛИ День(СсылкаНаОбъект.ДатаНачалаСобытия) = 8))
    	ИЛИ Месяц(СсылкаНаОбъект.ДатаНачалаСобытия) = 2 И День(СсылкаНаОбъект.ДатаНачалаСобытия) = 23
    	ИЛИ Месяц(СсылкаНаОбъект.ДатаНачалаСобытия) = 3 И День(СсылкаНаОбъект.ДатаНачалаСобытия) = 8
    	ИЛИ Месяц(СсылкаНаОбъект.ДатаНачалаСобытия) = 5 И День(СсылкаНаОбъект.ДатаНачалаСобытия) = 1
    	ИЛИ Месяц(СсылкаНаОбъект.ДатаНачалаСобытия) = 5 И День(СсылкаНаОбъект.ДатаНачалаСобытия) = 9
    	ИЛИ Месяц(СсылкаНаОбъект.ДатаНачалаСобытия) = 6 И День(СсылкаНаОбъект.ДатаНачалаСобытия) = 12
    	ИЛИ Месяц(СсылкаНаОбъект.ДатаНачалаСобытия) = 11 И День(СсылкаНаОбъект.ДатаНачалаСобытия) = 4
    	,"праздничный", "выходной");

    Проверочка на соответствие даты действия документа праздничному дню.. не ну а чо бы нет то

    Stipa, 06 Марта 2020

    Комментарии (20)
  7. PHP / Говнокод #26466

    +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
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    <?php
    var lastmsgid=$('.chat-msg:eq(0)',$(this).parent()).data('messageid');
    var lastmsg=$('#chat .chat-msg[data-messageid='+lastmsgid+']');
    var lastmsgscroll=lastmsg.offset().top;
    var lastscroll=$('#chat .messages').scrollTop();
    $(this).attr('disabled','disabled');var button=$(this);$.ajax({
    
              url: '<?=$baseHref;?>chat.php?more=1&user=<?=(int)$_GET['user'];?>&last=<?=(int)$last;?>',
    
              success: function(data) {
            if(data!='err'){
    data=JSON.parse(data);
    button.parent().prepend(data.messages);button.remove();fixdates();
    /*smiles*/$('#chat .messages .chat-msg div:not(.smilesadded)').each(function(){$(this).addClass('smilesadded').html(replacesmiles($(this).html()));});
    if($('#chat .messages').scrollTop()==0)$('#chat .messages').scrollTop(lastscroll-lastmsgscroll+lastmsg.offset().top);//prepend и так это делает. но не всегда
    
    } else {alert('Error');button.removeAttr('disabled');}
              },
              error:  function(xhr, str){
    	    alert('Error: ' + xhr.responseCode);
                   button.removeAttr('disabled');
              }
            });" class="btn-more button" style="margin-top:20px;margin-bottom:20px;"><?_e('Загрузить ещё');?></button><?}
    if(!isset($_GET['checknew']))$messages=array_reverse($messages);
    $user=mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT * FROM users WHERE `id`=".(int)$_GET['user']." LIMIT 1;"));
    foreach($messages as $data){
    if($yourdirection==$data['direction'])$userid=$account['id']; else $userid=(int)$_GET['user'];
    
    
    $fake=0;
    if(substr($data['text'],0,7)==':attach' && substr($data['text'],-1)==':'){$data['attachment']='../no-attach-premium.png?';if($premium)$data['attachment']=substr($data['text'],7,-1);$data['text']='';$fake=1;}
    ?>

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

    soxati, 05 Марта 2020

    Комментарии (18)
  8. PHP / Говнокод #26465

    +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
    <?php
    
      class Pet {
      
        protected $name;
    
        public function __construct($name) {
          echo "Setting name to " . $name . "\n";
          $this->name = $name;
        } 
    
        public function eat() {
          echo $this->name . " is eating.\n";
        }
      }
    
      $var = 30;
      $a_pet = new Pet("Spike"); 
      $a_pet->eat();
    ?>
    
    ---
    
    <?php
    
    function Pet__construct(&$objInst, $name)
    {
        echo 'Setting name to ' . $name . '
    ';
        $objInst['name'] = $name;
    }
    function Pet_eat(&$objInst)
    {
        echo $objInst['name'] . ' is eating.
    ';
    }
    $Pet = array('__vars' => array('name' => null));
    $var = 30;
    $a_pet = array_merge($Pet['__vars'], array('__type' => 'Pet'));
    Pet__construct($a_pet, 'Spike');
    Pet_eat($a_pet);

    Конвертер из ООП в процедурный стиль.
    Make PHP great again.

    https://github.com/PatrickZurekUIC/PHP-OOP-Converter

    Fike, 05 Марта 2020

    Комментарии (215)
  9. Python / Говнокод #26464

    0

    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
    Первой модуль Definition_h содержит переменную с именем хоста
    
    if "COMPUTERNAME" in os.environ:
        UNAME = os.environ["COMPUTERNAME"].upper()
    else:
        UNAME = commands.getoutput("hostname").strip().upper()
        
    Второй модуль содержит функцию поведение которой зависит от имени хоста
    
    def func():
        if Definition_h.UNAME == "HKCFF-AS0301" :
            tab["CODE_INTERBQUE"] = self._supplementaryDetails[5:8]
         else :
            tab["CODE_OPE_BQE"] = self._supplementaryDetails[5:8]

    извращенное сознание

    gaal, 04 Марта 2020

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

    +1

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

    #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: (vanished) https://govnokod.xyz/_24063
    #7: https://govnokod.ru/24538 https://govnokod.xyz/_24538
    #8: (vanished) https://govnokod.xyz/_24815
    #9: https://govnokod.ru/24867 https://govnokod.xyz/_24867
    #10: https://govnokod.ru/25328 https://govnokod.xyz/_25328
    #11: (vanished) https://govnokod.xyz/_25436
    #12: (vanished) https://govnokod.xyz/_25471
    #13: (vanished) https://govnokod.xyz/_25590
    #14: https://govnokod.ru/25684 https://govnokod.xyz/_25684
    #15: https://govnokod.ru/25694 https://govnokod.xyz/_25694
    #16: https://govnokod.ru/25725 https://govnokod.xyz/_25725
    #17: https://govnokod.ru/25731 https://govnokod.xyz/_25731
    #18: https://govnokod.ru/25762 https://govnokod.xyz/_25762
    #19: https://govnokod.ru/25767 https://govnokod.xyz/_25767
    #20: https://govnokod.ru/25776 https://govnokod.xyz/_25776
    #21: https://govnokod.ru/25798 https://govnokod.xyz/_25798
    #22: https://govnokod.ru/25811 https://govnokod.xyz/_25811
    #23: https://govnokod.ru/25863 https://govnokod.xyz/_25863
    #24: https://govnokod.ru/25941 https://govnokod.xyz/_25941
    #25: https://govnokod.ru/26026 https://govnokod.xyz/_26026
    #26: https://govnokod.ru/26050 https://govnokod.xyz/_26050
    #27: https://govnokod.ru/26340 https://govnokod.xyz/_26340
    #28: https://govnokod.ru/26372 https://govnokod.xyz/_26372
    #29: https://govnokod.ru/26385 https://govnokod.xyz/_26385
    #30: https://govnokod.ru/26413 https://govnokod.xyz/_26413
    #31: https://govnokod.ru/26423 https://govnokod.xyz/_26423
    #32: https://govnokod.ru/26440 https://govnokod.xyz/_26440
    #33: https://govnokod.ru/26449 https://govnokod.xyz/_26449
    #34: https://govnokod.ru/26456 https://govnokod.xyz/_26456

    gost, 04 Марта 2020

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