1. PHP / Говнокод #16844

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (in_array($str, array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'))) {
        return TRUE;
    } else {
        $this->error = "Значение поля 'Месяц' содержит некорректное значение";
        return FALSE;
    }

    AgentSIB, 13 Октября 2014

    Комментарии (4)
  2. SQL / Говнокод #16843

    −123

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    l_space   varchar2(100) := '               ';
        l_space_1 varchar2(100) := '                    ';
        l_space_2 varchar2(100) := '                         ';
        l_space_3 varchar2(100) := '                               ';
        l_space_4 varchar2(100) := '                                         ';

    n1919, 13 Октября 2014

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    public function get($idUser, User $user, Request $request)
     {
            return new Result($this->getAccounts($this->user, $this->slim->request()->getIp()));
     }

    dimkich, 13 Октября 2014

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

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if(count($colors)>1){
        if($i==2){
            $col = $colors[1];
        }else{
            $col = $colors[0];
        }
    }else{
        $col=$colors[0];
    }

    Вот где не надо - тьма тернарных операторов, а где их логичнее всего ожидать - вот такой огород из IF/ELSE

    Khvorostin, 13 Октября 2014

    Комментарии (17)
  5. Java / Говнокод #16840

    +119

    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
    static void writeInternal(byte type, Object object, ObjectOutput out) throws IOException {
        out.writeByte(type);
        switch (type) {
            case DURATION_TYPE:
                ((Duration) object).writeExternal(out);
                break;
            case INSTANT_TYPE:
                ((Instant) object).writeExternal(out);
                break;
            ...
            <snip>
            ...
            case PERIOD_TYPE:
                ((Period) object).writeExternal(out);
                break;
            default:
                throw new InvalidClassException("Unknown serialized type");
        }
    }

    JDK 8. java.time.Ser.

    Вот что происходит, когда в языке есть только public-наследование. Без рефлексии короче написать нельзя.

    someone, 12 Октября 2014

    Комментарии (10)
  6. bash / Говнокод #16839

    −115

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    ls -laF /usr/lib/x86_64-linux-gnu/libcurl.so.4.2.0
    if [ "$?" -ne 0 ]; then
        current_location=$PWD
        gzip -dc < curl-7.22.0.tar.gz | tar -xf -
        cd curl-7.22.0
        ./configure --prefix=/usr
        make
        make install
        cd $current_location
    else
        echo "libcurl.so.4.2.0 already exist!"
    fi

    Ключ -f? Нет, не слышали.

    codemonkey, 12 Октября 2014

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

    +133

    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
    /*Checks whether the path exists and the path is directory, otherwise creates a new directory*/
    RET_VALS check_create_directory(const char* const dir_path, void (*print_func)(int, char *,...))
    {
    	RET_VALS ret_val;
    	struct stat sb;
    
    	ret_val = RET_OK;
    	if (NULL != dir_path)
    	{
    		if(NULL != print_func)
    		{
    			print_func(DBG_INFO, "%s - Checking %s existence\n", __FUNCTION__, dir_path);
    		}
    		else
    		{
    			dbgprintln("Checking %s existence", dir_path);
    		}
    		if (0 != stat(dir_path, &sb) || (false == S_ISDIR(sb.st_mode)))
    		{
    			ret_val |= RET_DIR_MISSING;
    			if(NULL != print_func)
    			{
    				print_func(DBG_INFO, "%s - %s is missing\n", __FUNCTION__, dir_path);
    			}
    			else
    			{
    				dbgprintln("%s is missing", dir_path);
    			}
    			errno = 0;
    			if (0 == mkdir(dir_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
    			{
    				ret_val |= RET_DIR_CREATE_OK;
    				if(NULL != print_func)
    				{
    					print_func(DBG_INFO, "%s - %s is successfully created\n", __FUNCTION__, dir_path);
    				}
    				else
    				{
    					dbgprintln("%s is successfully created", dir_path);
    				}
    			}
    			else
    			{
    				char err_msg[_K];
    
    				sprintf(err_msg, "Failed to create %s, error %04d - %s", dir_path, errno, strerror(errno));
    				ret_val |= RET_DIR_CREATE_FAILED;
    				//dbg_ffln(DBG_ERROR, "Failed to create %s", dir_path);
    				if(NULL != print_func)
    				{
    					print_func(DBG_INFO, "%s - %s\n", __FUNCTION__, err_msg);
    				}
    				else
    				{
    					dbgprintln("%s", err_msg);
    				}
    			}
    		}
    		else
    		{
    			ret_val |= RET_DIR_ALREADY_EXIST;
    			if(NULL != print_func)
    			{
    				print_func(DBG_INFO, "%s - %s already exists\n", __FUNCTION__, dir_path);
    			}
    			else
    			{
    				dbgprintln("%s already exists", dir_path);
    			}
    		}
    	}
    	else
    	{
    		ret_val = RET_DIR_MISSING;
    		if(NULL != print_func)
    		{
    			print_func(DBG_ERROR, "%s - No directory name is provided", __FUNCTION__);
    		}
    		else
    		{
    			dbgprintln("No directory name is provided");
    		}
    	}
    	return ret_val;
    }

    Продолжаем раскопки. Вообще весь .с файл можно сюда выложить.

    codemonkey, 12 Октября 2014

    Комментарии (3)
  8. PHP / Говнокод #16837

    +157

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    'errorHandler' =>
        class yii\console\ErrorHandler#6 (6) {
          public $discardExistingOutput =>
          bool(true)
          public $memoryReserveSize =>
          int(262144)
          public $exception =>
          NULL
          private $_memoryReserve =>
          string(262144) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"...

    Где-то в недрах Yii2. Я, кажется, понимаю, что это и зачем (хотя не уверен, что это работает, когда памяти уже не хватило), но выглядит просто адово.

    Fike, 12 Октября 2014

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

    −124

    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
    SELECT * FROM (
        SELECT `comments`.`user`,
                       `comments`.`time`,
                       `comments`.`topic`,
                       `comments`.`id` AS `commid`,
                       `topic`.`name`,
                       `topic`.`id`,
                       `topic`.`translit`,
                       `topic`.`blog`,
                       `user`.`login`
        FROM `comments`, `topic`, `user`
        WHERE
        `comments`.`topic` IN (
            SELECT DISTINCT `topic`
            FROM `comments`
            ORDER BY `time` DESC)
            AND `topic`.`id` = `comments`.`topic`
            AND `user`.`id` = `comments`.`user`
            ORDER BY `comments`.`time` DESC
        ) `data`
        GROUP BY `data`.`topic`
        ORDER BY `data`.`time` DESC
        LIMIT 10

    Говнокод или необходимость?
    Не нашел способов сделать это одним запросом.

    Efog, 11 Октября 2014

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

    +134

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    #ifdef __APPLE__
    #define OPENGL_LIBRARY "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
    #else
    #define OPENGL_LIBRARY "libGL.so"
    #endif

    А вообще, у мака есть переменные окружения?

    Pythoner, 10 Октября 2014

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