1. SQL / Говнокод #12267

    −161

    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
    CREATE TABLE calendar
    (
      caldate date NOT NULL,
      "month" integer NOT NULL,
      month_txt character varying(10) NOT NULL,
      "year" integer NOT NULL,
      CONSTRAINT calendar_pkey PRIMARY KEY (caldate)
    )
    CREATE TABLE holiday
    (
      id numeric(10,0) NOT NULL DEFAULT nextval('holiday_seq'::regclass),
      caldate date NOT NULL,
      region integer,
      CONSTRAINT holidaypk PRIMARY KEY (id),
      CONSTRAINT fk_hday_caldate FOREIGN KEY (caldate)
          REFERENCES calendar (caldate) MATCH SIMPLE
          ON UPDATE NO ACTION ON DELETE NO ACTION,
      CONSTRAINT holidayfk FOREIGN KEY (region)
          REFERENCES region (id) MATCH SIMPLE
          ON UPDATE NO ACTION ON DELETE NO ACTION
    )

    Вот такая вот структура база в проекте в котором я работаю.
    Причём помимо таблицы calendar и дублирование там информации, обратите внимание на таблицу holiday в эту таблицу записи ручками вносятся о выходных днях или о праздниках, как впрочем и в таблицу calendar

    smpl, 10 Декабря 2012

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

    +163

    1. 1
    jQuery("body").trigger( F11 )

    Попытка перейти в полноэкранный режим.. Найдено в недрах одного довольно серьезного проекта.

    diezvl, 10 Декабря 2012

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if(is_dir('install')|| is_dir('migrate')) {
            if (!file_exists(PATH.'/includes/config.inc.php')){
                header('location:/install/');
    			die();
            } else {
                include(PATH.'/core/messages/installation.html');
                die();
            }
        }

    Govnisti_Diavol, 10 Декабря 2012

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

    +15

    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
    LambdaVar<1> X;
    LambdaVar<2> Y;
    // The next line prints 10:
    cout << lambda(X,Y)[ plus[ multiplies[3,X], Y ] ] (3,1) << endl;
    cout << lambda(X,Y)[ (3 %multiplies% X) %plus% Y ] << endl;
    //...
    lambda(X)[ X %plus% getCurrentTime[_*_] ]
    //...
    let[ X == someLambdaExp,
            Y == someOtherLambdaExpWhichMayInvolveX ]
       .in[ someLambdaExpInvolvingXandY ]
    //...
    lambda(X)[ 
          letrec[ F == lambda(Y)[ if1[ Y %equals% 0, 
                                       1, 
                                       Y %multiplies% F[Y %minus% 1] ] ] ]
          .in[ F[X] ] ]
    //...
     Maybe<int> mx = just(2);
       Maybe<int> my = just(3);
       mx = lambda()[ compM<MaybeM>()[ plus[X,Y] | X<=mx, Y<=my, guard[false] ] ]();
       cout << mx << endl;   // Nothing
    //...
    compM<ListM>()[ makePair[X,Y] | X<=list_with(1,2), guard[true], 
              Y<=list_with(3,4), guard[ (Y %divides% X) %equal% 3 ] ] ]

    Грибки отсюда:
    http://people.cs.umass.edu/~yannis/fc++/

    LispGovno, 10 Декабря 2012

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

    +18

    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
    /*
     *      The use of singletons for globals makes globals not
     *      actually be initialized until it is first needed, this
     *      makes the library faster to load, and have a smaller
     *      memory footprint
     */
    
    #define json_global_decl(TYPE, NAME, VALUE)                              \
    class jsonSingleton ## NAME {                                            \
    public:                                                                  \
            inline static TYPE & getValue() json_nothrow {                   \
                    static jsonSingleton ## NAME single;                     \
                    return single.val;                                       \
            }                                                                \
    protected:                                                               \
            inline jsonSingleton ## NAME() json_nothrow : val(VALUE) {}      \
            TYPE val;                                                        \
    }
    
    #define json_global(NAME) jsonSingleton ## NAME::getValue()              \
    
    json_global_decl(json_string, CONST_TRUE, JSON_TEXT("true"));
    json_global_decl(json_string, CONST_FALSE, JSON_TEXT("false"));
    json_global_decl(json_string, CONST_NULL, JSON_TEXT("null"));
    
    /* Использование */
    json_global(ERROR_NULL_IN_CHILDREN)

    Наткнулся на утечку памяти, отловленную Valgrind'ом
    А внутри вот это. И главное, совершенно непонятно, зачем воротить эту свистопляску, если линкеры умеют распознавать "true" по всюду (читаем про ROMability тут: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1396.pdf )
    http://stackoverflow.com/questions/690176/c-c-optimization-of-pointers-to-string-constants

    Сам код отсюда: http://code.google.com/p/wot-replay-parser/source/browse/libjson/Source/JSONGlobals.h

    myaut, 10 Декабря 2012

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

    −85

    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
    by :: Int -> [a] -> [[a]]
    by _ [] = []
    by n xs = take n xs: by n (drop n xs)
     
    words2 :: String -> (String, String)
    words2 str = conc $ words str where
        conc (x:xs) = (x, concat xs)
     
    groupTemplates :: String -> [(String, String)]
    groupTemplates xs = map (words2) (lines xs)
     
    decodeOne :: String -> [(String, String)] -> String
    decodeOne _ [] = ""
    decodeOne str (x:xs) | str == fst x = fst x ++ " " ++ snd x ++ "\n"
    decodeOne str (_:xs) = decodeOne str xs
     
    decode :: [String] -> [(String, String)] -> String
    decode bs ts = concat $ map (\b -> decodeOne b ts) bs
     
    main = do
        bits      <- readFile "bits.txt"
        templates <- readFile "templates.txt"
     
        writeFile "out.txt" $ decode (by 4 bits) (groupTemplates templates)

    http://www.cyberforum.ru/haskell/thread723767.html

    Fai, 09 Декабря 2012

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

    +53

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $this->_requestUri = 0 === strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'])
                ? substr(
                    $_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME'])
                )
                : $_SERVER['REQUEST_URI'];

    __proto__, 08 Декабря 2012

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

    +102

    1. 1
    2. 2
    3. 3
    4. 4
    var usr = Enumerable.Range(1, 1) 
    	.Select(id => new User(1, "FooBar", "desc" + 1, DateTime.UtcNow)) 
    	.ToReadonly() 
    	.GetRandomElement();

    Из юнит-теста. Копипаста рождает чудовищ.

    VasyaMatros, 08 Декабря 2012

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

    +25

    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
    public OnPlayerSpawn(playerid) {
        IsSpawned[playerid]=1;
        if(Team[playerid]==ZOMBIE) { TextDrawSetString(Textdraw9[playerid],"You are a ~r~Zombie~w~. Kill & Infect every Human to complete your mission.");
    	} else if(Team[playerid]==HUMAN) { TextDrawSetString(Textdraw9[playerid],"You are a ~r~Human~w~. Prevent Zombie attacks and survive till the end."); }
        TextDrawHideForAll(Box); TextDrawHideForAll(text_Top5[0]); TextDrawHideForAll(text_Top5[1]);
    	TextDrawShowForPlayer(playerid, Textdraw0);	 TextDrawShowForPlayer(playerid, Textdraw1);
    	TextDrawShowForPlayer(playerid, Textdraw2);	 TextDrawShowForPlayer(playerid, Textdraw3);
    	TextDrawShowForPlayer(playerid, Textdraw4);	 TextDrawShowForPlayer(playerid, Textdraw5);
    	TextDrawShowForPlayer(playerid, Textdraw6);	 TextDrawShowForPlayer(playerid, Textdraw7);
    	TextDrawShowForPlayer(playerid, Textdraw9[playerid]);
    	TextDrawShowForPlayer(playerid, Textdraw15); TextDrawShowForPlayer(playerid, Textdraw16[playerid]);
    	SetTeam(playerid); SetClass(playerid); 
    	if(Infection==1) {
            Infection=0;
            if(Totalplayers>=2) {
    			SetTimer("InfectionLoad",0,0);
    		} else if(Totalplayers>=10) {
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    		}else if(Totalplayers>=10) {
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    		}else if(Totalplayers>=20) {
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    		}else if(Totalplayers>=30) {
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    		}else if(Totalplayers>=45) {
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    		}else if(Totalplayers>=60) {
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    		}else if(Totalplayers<=75) {
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    			SetTimer("InfectionLoad",0,0);
    		}
    	} return 1; }

    Серьезно?

    d3n4, 08 Декабря 2012

    Комментарии (25)
  10. ActionScript / Говнокод #12258

    −90

    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
    public static function findNeighbourEmpty(cx:int, cy:int, checkDebris:Boolean = true):Cell {
        var cell:Cell = Cell.getCell(cx, cy);
        var i:int = 0;
        var distance:int = 1;
        var n:int = 8;
        while(!cell || !cell.accessible || (checkDebris && !isEmptyTile(cell))) {
            if (i < n * distance / 4) {
                cell = Cell.getCell(cx + Math.min(i, distance), cy + Math.min(distance * 2 - i, distance));
            } else if (i < n * distance / 2) {
                cell = Cell.getCell(cx + Math.min(distance * 2 - i + n * distance / 4, distance), cy + Math.max(n * distance / 4 - i, -distance));
            } else if (i < 3 * n * distance / 4) {
                cell = Cell.getCell(cx + Math.max(n * distance / 2 - i, -distance), cy + Math.max(-distance * 2 + i - n * distance / 2, -distance));
            } else if (i < n * distance) {
                cell = Cell.getCell(cx + Math.max(-distance * 2 + i - 3 * n * distance / 4, -distance), cy + Math.min(i - 3 * n * distance / 4, distance));
            } else {
                i = 0;
                distance++;
                if (distance > MAX_NEIGHBOUR_CELL_DISTANCE) {
                    return findNeighbourEmpty(cx, cy, false);
                }
                continue;
            }
            i++;
        }
        return cell;
    }

    Какой милый метод...

    kyzi007, 06 Декабря 2012

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