1. Си / Говнокод #23534

    −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
    #include <stdio.h>
    #include <stdlib.h>
    
    int * ptr;
    
    int * getptr()
    {
      puts("getptr");
      return ptr;
    }
    
    int jump()
    {
      puts("jump");
      ptr = (int*)malloc(sizeof(int));
      return 1337;
    }
    
    int main()
    {
      ptr = (int*)malloc(sizeof(int));
      *ptr = 0;
    
      *( getptr() ) = 1;
      printf( "*ptr = %i\n\n", *ptr );
    
      *( getptr() ) = (jump(), 100);
      printf( "*ptr = %i\n\n", *ptr );
    
      *( getptr() ) = jump();
      printf( "*ptr = %i\n\n", *ptr );
    
      return 0;
    }

    ШИКАРНО:

    Start

    getptr
    *ptr = 1

    jump
    getptr
    *ptr = 100

    getptr
    jump
    *ptr = 0

    0

    Finish

    bugspawn, 15 Ноября 2017

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

    +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
    ...
        private enum CSPTitle {
            CONTENT_SECURITY_POLICY, X_CONTENT_SECURITY_POLICY, X_WEBKIT_CSP;
    
            public String getName() {
                return WordUtils.capitalizeFully(this.name(), new char[] { '_' }).replace('_', '-');
            }
        }
    ...
       public Map<String, String> getHeaders(boolean disableXWebkitCspHeader, StringBuilder cspHeaderBodyBuilder){
            Map<String, String> cspHeaders = new HashMap<>();
            for (CSPTitle cspTitle : CSPTitle.values()) {
                if (disableXWebkitCspHeader && CSPTitle.X_WEBKIT_CSP.equals(cspTitle)) {
                    continue;
                }
    
                String cspHeaderBody = cspHeaderBodyBuilder.toString();
                if (CSPTitle.X_CONTENT_SECURITY_POLICY.equals(cspTitle)) {
                    cspHeaderBody = processXCSPHeader(cspHeaderBody);
                }
                cspHeaders.put(cspTitle.getName(), cspHeaderBody.trim());
            }
            return cspHeaders;
      }
    ....

    reizy, 14 Ноября 2017

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

    0

    1. 1
    PYTHONPATH=$(pwd) LANG=C.UTF-8 pipenv run ./scripts/script

    Как работает виртуализация в Питоне.

    wvxvw, 14 Ноября 2017

    Комментарии (15)
  4. 1C / Говнокод #23531

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    ВЫБРАТЬ
      SEO.титл КАК Титл,
      SEO.Описание КАК дескриптионс,
      SEO.Кейворд КАК Кейворд,
      SEO.Ссылка КАК сео
    ИЗ
      Справочник.SEO КАК SEO

    импортозамещение...

    OdinAsss, 14 Ноября 2017

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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private static int CalcCheckSum(byte[] BinFile)
    {
          int length = ((IEnumerable<byte>) BinFile).Count<byte>();
          if (length > 0)
          {
                int num = 0;
                for (int index = 0; index < length; ++index)
                      num = num + (int) BinFile[index] & (int) ushort.MaxValue;
          }
          return num;
    }

    Израильский инновационный вариант rolling hash'а :facepalm:
    Здесь есть всё: и альтернативное определение длины массива, и обилие приведений к инту, и придающая особую таинственность битовая операция &
    На первый взгляд может показаться, что результатом будет простая сумма всех байт, но не дайте себя обмануть! Результат - это суперсекретная(!!!11) сумма всех байт.

    PsychoTeras, 14 Ноября 2017

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public ReadFile(string path)
    {
          byte[] BinFile = File.ReadAllBytes(path);
          if (((IEnumerable<byte>) BinFile).Count<byte>() <= 25)
            return;
          this._Version = BinFile[0].ToString() + "." + BinFile[1].ToString() + "." + BinFile[2].ToString();
    }

    Я вам тут израильского инжиниринга принёс. Читаем файл, читаем версию.
    В этом коде прекрасно всё...

    PsychoTeras, 14 Ноября 2017

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

    0

    1. 1
    2. 2
    3. 3
    https://github.com/VKCOM/bot-example-php/blob/master/html/bot/bot.php
    
    В великом и недосягаемом "ВКонтакте" переменные в текст по-прежнему включают с помощью фигурных скобок.

    COWuTEJIbTBOEuMAMKu, 14 Ноября 2017

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

    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
    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
    function checkAnswer(lastId, connectionString, success, unsuccess, installationNumber) {
      var result;
      for(var i=0;i<3*15/*15min*/;i++) {
        Delay(periodCheckingComponentsInstalled, "Waiting components to be installed");
        result = getDataFromDB(connectionString, lastId);
        var k = [];
        for(var i=0;i<success.length; i++) {
          k.push(false);
        }
        
        for(var i=0;i<success.length;i++) {
          if ((success[i] == "RemoteSuccess") ||  (success[i] == "RemoteUnSuccess")) {
            k[i] = true;
            break;
          }
          else {
            for(var j=0;j<result.length ; j++) {
              if (result[j].length > 40) {
                k[i] = includeArray(result, success[i]);//40 symb
                if (includeArray(result, unsuccess[i])) Log.Error("error while installing, number installation = " + installationNumber);
              }
            }
          }
        }
        var bool = true;
        for (var i=0;i<success.length; i++) {
          bool = bool&&k[i];
        } 
        if (bool) return true; else continue;
        return false;
      }
    }

    Остался скрипт от тестировщика. Блядь, и такого там с мегабайт.

    fluttr, 13 Ноября 2017

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

    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
    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
    /**
     * Queries the DOM for the HTML element based on selector string passed.
     * @param {String} selector Selector we are querying for.
     * @param {String} [parent] Parent is optional, if passed the function will look for a child element of that parent.
     * @param {Boolean} [returnEmptyList] If set to true the function won't throw an error even if the element is not found.
     * @return {Array} HTML objects.
     */
    function getEl( selector, parent, returnEmptyList )
    {
        var classOnly,
            match,
            elPrefix,
            selPrefix,
            context,
            safeNode,
            nodes;
    
        classOnly = /^\.([\w\-]+)$/;
        match = classOnly.exec( selector );
        elPrefix = '.js-';
        selPrefix = selector.substring( 0, 4 );
    
        if ( ( selPrefix !== elPrefix || !typeCheck.isString( selector ) ) && match !== null )
        {
            throw new Error( 'Please make sure you input a valid class name that begins with a proper prefix.' );
        }
    
        if ( typeCheck.isString( parent ) )
        {
            context = document.getElementsByClassName( parent.substring( 1 ) )[ 0 ];
        }
        else if ( typeCheck.isElement( parent ) )
        {
            context = parent;
        }
        else
        {
            context = document;
        }
    
        nodes = match === null ? context.querySelectorAll( selector ) : context.getElementsByClassName( match[ 1 ] );
    
        safeNode = nodes.length > 0 && nodes;
    
        if ( safeNode || !safeNode && returnEmptyList )
        {
            return [].slice.call( nodes ); //converts it to a proper array.
        }
        else
        {
            throw new Error( 'Element with selector "' + selector + '" does not exist on the page.' );
        }
    }

    Koren, 13 Ноября 2017

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

    +5

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    // PHP при делении может неявно конвертировать целые в плавающие, и всех этих int-ограничений для него не существует
    echo 12 / 5; // 2.4
    
    // Было бы логично предположить, что другие операторы работают так же, но эта камбала неявно кастует уже плавающее к целому в соседнем операторе
    echo 9 % 0.9;
    
    PHP Fatal error:  Uncaught DivisionByZeroError: Modulo by zero in Command line code:1
    Stack trace:
    #0 {main}
      thrown in Command line code on line 1

    Fike, 13 Ноября 2017

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