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

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

    0

    1. 1
    2. 2
    if(services_type == 3) var checked = 1;
    else var checked = 0;

    fellownik, 16 Ноября 2017

    Комментарии (16)
  3. C# / Говнокод #23471

    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
    internal class Log
    	{
    		public static void WriteLine(string methodName, UpdateFile file, Exception e, LogType type = LogType.Success)
    		{
    			using (FileStream fileStream = new FileStream(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\patch.log", FileMode.OpenOrCreate))
    			{
    				using (StreamReader streamReader = new StreamReader(fileStream))
    				{
    					using (StreamWriter streamWriter = new StreamWriter(fileStream))
    					{
    						streamWriter.WriteLine(string.Format("Launcher | {0} | {1} | {2} | {3} | {4}", new object[]
    						{
    							type,
    							methodName,
    							file.FullPath,
    							e,
    							DateTime.Now
    						}), streamReader.ReadToEnd().Length);
    					}
    				}
    			}
    		}
    
    ...

    Как получить размер файла? Правильно, надо прочитать его в память и взять размер данных из памяти :facepalm:
    Зачем получать размер файла, даже не спрашивайте ))

    Источник: hxxp://promo.riseofrunes.com/InstLauncher.zip (C#, декомпилятор).

    luxtau, 31 Октября 2017

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

    +5

    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
    function getadminuserid(){
    	global $wpdb;
        //Get all users in the DB
        $wp_user_search = $wpdb->get_results("SELECT ID, display_name FROM $wpdb->users ORDER BY ID");
    
        //Blank array
        $adminArray = array();
        //Loop through all users
        foreach ( $wp_user_search as $userid ) {
            //Current user ID we are looping through
            $curID = $userid->ID;
            //Grab the user info of current ID
            $curuser = get_userdata($curID);
            //Current user level
            $user_level = $curuser->user_level;
            //Only look for admins
            if($user_level >= 8){//levels 8, 9 and 10 are admin
                //Push user ID into array
                $adminArray[] = $curID;
            }
        }
        return $adminArray;
    }

    1) Get IDs for all users
    2) Iterate over result set to find admin `get_userdata` function = 1 DB call

    outcome:
    1) full RAM
    2) dead DB

    ===
    official woocommerce plugin by company

    tatocaster, 27 Октября 2017

    Комментарии (16)
  5. Python / Говнокод #23456

    +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
    while (1):
        for iterator in range(len(posts)):
            # Для прозрачности вычислений
            time_post_a = datetime.now()
            time_post_a = int(time.mktime(time_post_a.timetuple()))
    
            time_post_b = posts[iterator]['time']
            time_post_b = int(time.mktime(time_post_b.timetuple()))
    
            # Выполнить действие, в случае, если "время пришло" по массиву posts
            if ((time_post_a - time_post_b) == 0):
                print ('Итератор: ' + str(iterator) + ', Новая публикация: ' + str(posts[iterator]['time']))
                time.sleep(1) # Если его убрать, то начинаются дикие пляски
                break

    Планировщик постов

    meridium, 26 Октября 2017

    Комментарии (16)
  6. Си / Говнокод #23421

    +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
    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    //код компилируйте clang-ом, иначе не закомпилится
    int main(int argc, char *argv[])
    {
    	if(argc != 2) {
    		printf("Укажите способ (1,2)\n");
    		_exit(1);
    	}
    	int способ = atoi(argv[1]);
    	int ch;
    	switch(способ)
    	{
    		case 1:
    		{
    			while( (ch=getchar()) != EOF ) {
    				printf("%i", ch);
    			}
    			break;
    		}
    		case 2:
    		{
    			int twoch;
    			char arr[2];
    			int new;
    			while( (ch=getchar()) != EOF ) {
    				twoch = getchar();
    				if(twoch == EOF) break;
    				sprintf(arr, "%c%c", (char)ch, (char)twoch);
    				new = atoi(arr);
    				printf("%c", new); //попытка не пытка
    			}
    			break;
    		}
    		default:
    			printf("Неизвестный способ\n");
    	}
    	return 0;
    }

    без слов

    KoderOT-Boga, 17 Октября 2017

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

    +4

    1. 1
    2. 2
    3. 3
    if (preg_match('/'.preg_quote($subString).'/', $string)) {
        ...
    }

    Проверка, есть ли подстрока в строке.
    Вроде, как минимум несколько лет человек в программировании на PHP.
    Показывает опытность тем, что экранирует спецсимволы в регулярном выражении.
    А можно было использовать простейшую функцию strpos().

    zlsoft, 22 Сентября 2017

    Комментарии (16)
  8. Python / Говнокод #23332

    −7

    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
    import re
    
    def matrix():
        square = [[0 for x in range(7)] for x in range(7)]
        directions = ((1,0), (0,1), (-1,0), (0,-1))
        x, y, d = -1, 0, 0
        
        for i in range(49):
            while True:
                x1, y1 = x + directions[d][0], y + directions[d][1]
                
                if x1 >= 0 and x1 < 7 and y1 >= 0 and y1 < 7 and square[y1][x1] == 0:
                    x, y = x1, y1
                    break
                
                d = (d + 1) % 4
            
            square[y][x] = re.sub(r'\d', lambda n: ' ' * int(n.group()), '9de9mb8nv5yo4aol1rm')[i]
        
        return square
    
    print('\n'.join([''.join(line) for line in matrix()]).strip())

    по мативам http://govnokod.ru/23329#comment389918

    HACTEHbKA, 06 Сентября 2017

    Комментарии (16)
  9. Си / Говнокод #23224

    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
    #include <stdio.h>
    
    typedef int (*FUNC)();
    
    FUNC test (int a, int b){
        int ret(){
            return a + b;
        }
    
        return ret;
    }
    
    int main(){
        printf("%i\n", test(40, 2)());
        return 0;
    }
    
    
    /* Тоже самое на JS */
    function test(a, b){
        function ret(){
            return a + b;
        }
    
        return ret;
    }
    
    alert(test(40, 2)());
    
    
    # Тоже самое на Python
    def test(a, b):
        def ret():
            return a + b
    
        return ret
    
    print test(40, 2)()

    Странно работает компилятор, версия: gcc version 4.7.2

    $ gcc 1.c && ./a.out
    42
    $ gcc -O3 1.c && ./a.out
    Segmentation fault

    j1392184, 28 Июля 2017

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

    0

    1. 1
    https://github.com/catboost/catboost

    Похоже яндекс заопенсорсил свежую версию аркадии. Давайте обсирать эти их велосипеды.

    FrauSchweinhund, 19 Июля 2017

    Комментарии (16)
  11. Си / Говнокод #23156

    −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
    static bool
    do_convert(iconv_t cd, const char * src, int src_len,
               char ** dst, int *dst_len)
      {
      char * ret;
    
      char *inbuf;
      char *outbuf;
      int alloc_size;
      int output_pos;
      size_t inbytesleft;
      size_t outbytesleft;
    
      if(src_len < 0)
        src_len = strlen(src);
    #if 0
      fprintf(stderr, "Converting:\n");
      bgav_hexdump(src, src_len, 16);
    #endif
      alloc_size = src_len + BYTES_INCREMENT;
    
      inbytesleft  = src_len;
    
      /* We reserve space here to add a final '\0' */
      outbytesleft = alloc_size-1;
    
      ret    = malloc(alloc_size);
    
      inbuf  = (char *)src;
      outbuf = ret;
    
      while(1)
        {
    
        if(iconv(cd, (ICONV_CONST char **)&inbuf, &inbytesleft,
                 &outbuf, &outbytesleft) == (size_t)-1)
          {
          switch(errno)
            {
            case E2BIG:
              output_pos = (int)(outbuf - ret);
    
              alloc_size   += BYTES_INCREMENT;
              outbytesleft += BYTES_INCREMENT;
    
              ret = realloc(ret, alloc_size);
              if (ret == NULL)
                {
                cdio_warn("Can't realloc(%d).", alloc_size);
                return false;
                }
              outbuf = ret + output_pos;
              break;
            default:
              cdio_warn("Iconv failed: %s", strerror(errno));
              if (ret != NULL)
                free(ret);
              return false;
              break;
            }
          }
        if(!inbytesleft)
          break;
        }
      /* Zero terminate */
      *outbuf = '\0';
    
      /* Set return values */
      *dst = ret;
      if(dst_len)
        *dst_len = (int)(outbuf - ret);
    #if 0
      fprintf(stderr, "Conversion done, src:\n");
      bgav_hexdump(src, src_len, 16);
      fprintf(stderr, "dst:\n");
      bgav_hexdump((uint8_t*)(ret), (int)(outbuf - ret), 16);
    #endif
      return true;
    }

    https://github.com/pbatard/rufus/blob/edcfd43ed550b17f23f9534f4b3b5cdd7fffdefc/src/libcdio/driver/utf8.c#L170-L248

    А вы тут видите тут баг?

    j123123, 05 Июля 2017

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