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

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

    +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
    <!doctype html>
    <html>
    <head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta charset="utf-8" />
    <?
    $title = filter_var($_REQUEST["title"], FILTER_SANITIZE_STRING);
    $image = filter_var($_REQUEST["image"], FILTER_SANITIZE_STRING);
    $text = filter_var($_REQUEST["text"], FILTER_SANITIZE_STRING);
    ?>
    <meta property="og:type" content="article" />
    <meta property="og:title" content="<?=$_REQUEST['title'];?>" />
    <meta property="og:description" content="<?=$_REQUEST['text'];?>" />
    <meta property="og:image" content="<?=$_REQUEST['image']?>" />
    <?$d = 'Некий URL?title='.urlencode($title).'&image='.urlencode($image).'&text='.urlencode($text);?>
    <meta property="og:url" content="<?=$d?>" />
    
    <title><?=$_REQUEST['title'];?></title>
    <script type="text/javascript">    
        window.location = "Еще один захардкоженый URL";
    </script>
    
    </head>
    
    <body>
        <img src="<?=$_REQUEST['image']?>" />
    </body>
    </html>

    все секурно

    sh7, 18 Августа 2017

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

    +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
    static inline void set0b (const uint8_t at, uint64_t bm[static 4])
    {
      bm[at / 64] &= ~(1ULL << (at % 64));
    }
    
    static inline  void set1b (const uint8_t at, uint64_t bm[static 4])
    {
      bm[at / 64] |= 1ULL << (at % 64);
    }
    
    static inline void inv_b (const uint8_t at, uint64_t bm[static 4])
    {
      bm[at / 64] ^= 1ULL << (at % 64);
    }
    
    
    static inline uint8_t find_empt_pos (const uint64_t bm[static 4])
    {
      if (bm[0] != UINT64_MAX)
      {
        return __builtin_ctzll(~bm[0]) + 64 * 0;  // __builtin_ctzll - https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
      }
      if (bm[1] != UINT64_MAX)
      {
        return __builtin_ctzll(~bm[1]) + 64 * 1;
      }
      if (bm[2] != UINT64_MAX)
      {
        return __builtin_ctzll(~bm[2]) + 64 * 2;
      }
      if (bm[3] != UINT64_MAX)
      {
        return __builtin_ctzll(~bm[3]) + 64 * 3;
      }
      fprintf(stderr, "ERROR! No empty space!\n");
      exit (-1);
    }
    
    static inline uint8_t allocate_ll (uint64_t bm[static 4])
    {
      uint8_t tmp = find_empt_pos (bm);
      set1b (tmp, bm);
      return tmp;
    }
    
    static inline void inject(const uint8_t prev_p, const uint8_t next_p, const uint8_t at, struct ll_data a[static 256])
    {
      a[next_p].ll.prev = at;
      a[prev_p].ll.next = at;
    
      a[at].ll.prev = prev_p;
      a[at].ll.next = next_p;
    }
    
    static inline void remove_betw(const uint8_t prev_p, const uint8_t next_p, struct ll_data a[static 256])
    {
      a[prev_p].ll.next = next_p;
      a[next_p].ll.prev = prev_p;
    }
    
    static inline void remove_at(const uint8_t at, struct ll_data a[static 256], uint64_t bm[static 4])
    {
      uint8_t prev_t = a[at].ll.prev;
      uint8_t next_t = a[at].ll.next;
    
      set0b (at, bm);
    
      a[at].ll.prev = next_t;
      a[at].ll.next = prev_t;
    }
    
    
    void add_elem_next (struct ll_all *a, const uint8_t elm, const int value)
    {
      uint8_t pos = allocate_ll (a->bm);
      inject(elm, a->arr[elm].ll.next, pos, a->arr);
      set_elm (pos, value, a->arr);
    }
    
    void add_elem_prev (struct ll_all *a, const uint8_t elm, const int value)
    {
      uint8_t pos = allocate_ll (a->bm);
      inject(a->arr[elm].ll.prev, elm, pos, a->arr);
      a->arr[pos].data = value;
    }
    
    void rem_elem_next (struct ll_all *a, const uint8_t elm)
    {
      set0b (a->arr[elm].ll.next, a->bm);
      remove_betw (elm, a->arr[a->arr[elm].ll.next].ll.next, a->arr);
    }
    
    void rem_elem_prev (struct ll_all *a, const uint8_t elm)
    {
      set0b (a->arr[elm].ll.next, a->bm);
      remove_betw (a->arr[a->arr[elm].ll.prev].ll.prev, elm, a->arr);
    }

    Тру-царская неанскилльная реализация двусвязного списка внутри массива.
    К сожалению, весь код не помещается, см https://wandbox.org/permlink/Ky8fnuqyE0Ahxftm

    j123123, 18 Августа 2017

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function is_tor_network($ip)
        {
            $tor = array(
    '101.142.102.237' => 1,'101.98.134.31' => 1,'103.246.244.1' => 1,'106.187.34.237' => 1,'106.187.36.183' => 1,'106.187.36.240' => 1,'106.187.37.158' => 1, /* ... Такой длинный код врядли может быть смешным. Пожалуйста, ограничьтесь сотней строк и 6000 символами. */
            );
            return isset( $tor[$ip]) ? true : false;
        }

    Почему бы не захардкодить тор?..

    Stallman, 17 Августа 2017

    Комментарии (3)
  5. Си / Говнокод #23272

    +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
    // GetBlockingMode возвращает: 1 - nonblocking | 0 - blocking | -1 - error | -2 - timeout reseted!
    
    int GetBlockingMode(int Sock)
    {
    	int iSize, iValOld, iValNew, retgso;
    	iSize = sizeof(iValOld);
    	retgso = getsockopt(Sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&iValOld, &iSize); // Save current timeout value
    	if (retgso == SOCKET_ERROR) return (-1);
    	iValNew = 1;
    	retgso = setsockopt(Sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&iValNew, iSize); // Set new timeout to 1 ms
    	if (retgso == SOCKET_ERROR) return (-1);
    	
    	// Ok! Try read 0 bytes.
    	char buf[1]; // 1 - why not :)
    	int retrcv = recv(Sock, buf, 0, MSG_OOB); // try read MSG_OOB
    	int werr = WSAGetLastError();
    	
    	retgso = setsockopt(Sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&iValOld, iSize); // Set timeout to initial value
    	if (retgso == SOCKET_ERROR) return (-2);
    
    	if (werr == WSAENOTCONN) return (-1);
    	if (werr == WSAEWOULDBLOCK) return 1;
    	return 0;
    }

    cykablyad, 17 Августа 2017

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

    +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
    #if !__has_builtin(__make_integer_seq) || defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
    namespace __detail {
    
    template<typename _Tp, size_t ..._Extra> struct __repeat;
    template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<__integer_sequence<_Tp, _Np...>, _Extra...> {
      typedef __integer_sequence<_Tp,
                               _Np...,
                               sizeof...(_Np) + _Np...,
                               2 * sizeof...(_Np) + _Np...,
                               3 * sizeof...(_Np) + _Np...,
                               4 * sizeof...(_Np) + _Np...,
                               5 * sizeof...(_Np) + _Np...,
                               6 * sizeof...(_Np) + _Np...,
                               7 * sizeof...(_Np) + _Np...,
                               _Extra...> type;
    };
    
    template<size_t _Np> struct __parity;
    template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {};
    
    template<> struct __make<0> { typedef __integer_sequence<size_t> type; };
    template<> struct __make<1> { typedef __integer_sequence<size_t, 0> type; };
    template<> struct __make<2> { typedef __integer_sequence<size_t, 0, 1> type; };
    template<> struct __make<3> { typedef __integer_sequence<size_t, 0, 1, 2> type; };
    template<> struct __make<4> { typedef __integer_sequence<size_t, 0, 1, 2, 3> type; };
    template<> struct __make<5> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4> type; };
    template<> struct __make<6> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; };
    template<> struct __make<7> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4, 5, 6> type; };
    
    template<> struct __parity<0> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type> {}; };
    template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; };
    template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; };
    template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; };
    template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
    template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
    template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
    template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
    
    } // namespace detail

    Накопипащенная параша из стандартной библиотеки плюсов для clang/llvm, имеющая отношение к реализации integer_sequence и tuple

    https://github.com/llvm-mirror/libcxx/blob/191f075c6fe7440659781f2603088b2df337c06a/include/__tuple#L101-L139

    https://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20160627/163531.html

    j123123, 14 Августа 2017

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    void* createMap() {
        mp = new Map();    //it's a global variable
        return reinterpret_cast<void*> (new Map());
    }

    ooki2day, 10 Августа 2017

    Комментарии (0)
  8. SQL / Говнокод #23253

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    SUM(
      CAST (
        SUBSTRING(CAST([PercentAmount] AS VARCHAR),1, CHARINDEX ('.',[PercentAmount])-1) 
        + '.'
        + SUBSTRING(CAST([PercentAmount] AS VARCHAR),CHARINDEX('.',[PercentAmount])+1, 2+CHARINDEX ('.',[PercentAmount])) 
    AS MONEY))

    А как вы достигаете точности в 2 знака после запятой?

    dreamca4er, 10 Августа 2017

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

    +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
    switch (DAEMONS_ENV) {
                case "development": {
                    break;
                }
    
                case "staging": {
                    break;
                }
    
                case "production": {
                    break;
                }
    
                default: {
                    break;
                }
            }

    hack3p, 09 Августа 2017

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

    +1

    1. 1
    2. 2
    3. 3
    CoolIntf::GetInstance().DoSomething();
    CoolIntf::GetInstance().DoSomethingElse();
    CoolIntf::GetInstance().DoAnything()

    для случая когда GetInstance() не инлайнится, кто-нибудь в крестах какое решение (без ручного введения временной переменной) для такого кода придумал?
    единственное что нашел это вот это: https://stackoverflow.com/a/2279253 .
    потому что "with" слишком общее слово которое в ж не гуглится.

    Dummy00001, 04 Августа 2017

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    service() {                                                        
            [ -f "/etc/init.d/$1" ] || {           
                    echo "service "'"'"$1"'"'" not found, the following services are available:"
                    ls "/etc/init.d"                                                            
                    return 1                                      
            }                                         
            /etc/init.d/$@                                                                      
    }

    Случайно заметил дивное экранирование $1 в конфиге openwrt /etc/profile. Обожаю баш.

    fluttr, 02 Августа 2017

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