1. Куча / Говнокод #23280

    −5

    1. 1
    Никто не в курсе где сейчас  Clerk с wasm.

    tyrin, 18 Августа 2017

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

    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
    //10  процентов  от  ширины  блока
    var blockPercent = ($(".prod").width() / 100) * 10;
    
    //наведение мышью на блок
    $('.prod').mouseenter(function(cursor){
        //Добавление стиля для определения текущего блока
        $(this).addClass('selected-prod');
    
        var offset = $(this).offset();
    
        //left-right
        if (cursor.pageX - offset.left < blockPercent) {
            $('.selected-prod .prod-description').css({'height': '100%','left':'0px'});
            $('.selected-prod .prod-description').animate({'width': '100%'},200);
        }
    
        //right-left
        if (cursor.pageX - offset.left > $(this).width() - blockPercent) {
            $('.selected-prod .prod-description').css({'height': '100%', 'right':'0px'});
            $('.selected-prod .prod-description').animate({'width': '100%'},200);
        }
        
        //top-down
        if (cursor.pageY - offset.top < blockPercent) {
            $('.selected-prod .prod-description').css({'width': '100%'});
            $('.selected-prod .prod-description').animate({'height': '100%'},200);
        }
        
        //down-top
        if (cursor.pageY - offset.top > $(this).height() - blockPercent) {
            $('.selected-prod .prod-description').css({'width': '100%'});
            $('.selected-prod .prod-description').animate({'height': '100%','bottom':'0px'},200);
        }
    });

    Наткнулся на проекте. Первая мысль: "Оно слишком быстро работало!"

    ikenfin, 18 Августа 2017

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

    +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
    // https://github.com/julycoding/The-Art-Of-Programming-By-July/blob/master/ebook/code/c/1.1%EF%BC%9A%E5%B7%A6%E6%97%8B%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2.c
    
    #include <stdio.h>
    #include <string.h>
    //字符串旋转问题,例如abcdef 左旋2位 变成 cdefab
    
    //暴力移位法
    void leftShift1(char * arr, int n)
    {
        size_t tmpLen = strlen(arr);
        char tmpChar;
        int i, j;
        if (n >= 0)
        {
            for (i = 0; i < n; i++)
            {
                tmpChar = *arr;
                for (j = 0; j < tmpLen - 1; j++)
                {
                    *(arr + j) = *(arr + j + 1);
                }
                *(arr + tmpLen - 1) = tmpChar;
            }
        }
        else
        {
            for (i = 0; i < -n; i++)
            {
                tmpChar = *(arr + tmpLen - 1);
                for (j = tmpLen - 1; j > 0; j--)
                {
                    *(arr + j) = *(arr + j - 1);
                }
                *arr = tmpChar;
            }
        }
    }

    Копаясь в гитхабе, нашел я тут The Art Of Programming By July, написанный каким-то китайцем.
    https://github.com/julycoding/The-Art-Of-Programming-By-July

    j123123, 18 Августа 2017

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

    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
    62. 62
    63. 63
    64. 64
    public static int index(string word, char comp)
            {
                int k = -1;
                for (int i = 0; i < word.Length; i++)
                    if (word[i] == comp)
                    {
                        k = i;
                        break;
                    }
                return k;
            }
    
            public static char[] strtocharr(string str)
            {
                char[] tmp = new char[str.Length];
                for (int i = 0; i < tmp.Length; i++)
                    tmp[i] = str[i];
                return tmp;
            }
    
            public static string charrtostr(char[] charr)
            {
                string tmp = null;
                for (int i = 0; i < charr.Length; i++)
                    tmp = String.Format("{0}{1}", tmp, charr[i]);
                return tmp;
            }
    
            public static char maskfromword(string word)
            {
                return word[word.Length - 1];
            }
    
            public static string maskfromword(string word, int n)
            {
                string mask = null;
                for (int i = 0; i < n; i++)
                    mask = String.Format("{0}{1}", mask, word[word.Length - 1]);
                return mask;
            }
    
            public static char Counter(char crnt, string word)
            {
                if (crnt != maskfromword(word))
                    crnt = word[index(word, crnt) + 1];
                else
                    crnt = word[0];
                return crnt;
            }
    
            public static string Counter(string prev, string word, int k)
            {
                char[] tmp = strtocharr(prev);
                if (k >= prev.Length - 1)
                    k = prev.Length - 1;
                else
                    for (int i = k + 1; i < prev.Length; i++)
                        tmp[i] = word[0];
                if (tmp[k] == maskfromword(word))
                    return MultiCounter(prev, word, k - 1);
                else
                    tmp[k] = Counter(tmp[k], word);
                return charrtostr(tmp);
            }

    Список методов, позволяющие сделать счетчик по словарю (полезно для генераторов словарей) на любое количество символов.

    Vero92, 18 Августа 2017

    Комментарии (36)
  5. 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)
  6. Си / Говнокод #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)
  7. PHP / Говнокод #23274

    0

    1. 1
    2. 2
    3. 3
    4. 4
    if($category_id!='')
            $this->db->where('group_category =', $category_id);
            if($group_by == TRUE)
            $this->db->group_by('blog_cat_name');

    У меня создалось впечатление, что здесь специально замаскировали все ифы. Чтобы читающий думал, что это линейный код. На скобках - экономят, на пробелах - экономят.

    gorsash, 17 Августа 2017

    Комментарии (5)
  8. 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)
  9. Си / Говнокод #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)
  10. Си / Говнокод #23271

    +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
    #include <stdio.h>
    main(t,_,a)
    char
    *
    a;
    {
     return!
    0<t?
    t<3?
    main(-79,-13,a+
    main(-87,1-_,
    main(-86, 0, a+1 )
    +a)):
    1,
    t<_?
    main(t+1, _, a )
    :3,
    main ( -94, -27+t, a )
    &&t == 2 ?_
    <13 ?
    main ( 2, _+1, "%s %d %d\n" )
    :9:16:
    t<0?
    t<-72?
    main( _, t,
    "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#;\
    #q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/+k#;\
    q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ){nl]!/n{n#'; \
    r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#\
    \
    n'wk nw' iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c ;;\
    {nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;\
    #'rdq#w! nr'/ ') }+}{rl#'{n' ')# }'+}##(!!/")
    :
    t<-50?
    _==*a ?
    putchar(31[a]):
    main(-65,_,a+1)
    :
    main((*a == '/') + t, _, a + 1 )
    :
    0<t?
    main ( 2, 2 , "%s")
    :*a=='/'||
    main(0,
    main(-61,*a, "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry")
    ,a+1);}

    виверни свой мозк, бро !

    bahamot, 16 Августа 2017

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