1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. PHP / Говнокод #12257

    +140

    1. 1
    2. 2
    Здравствуйте, господа!
    Кто знает, как выяснить свободный порт виртуальной машины средствами PHP?

    Govnisti_Diavol, 06 Декабря 2012

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

    +49

    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
    function preDispatch() {
            
    		
    		
    		
    		// Validate and redirect
            try {
                $this->_DB = Zend_Db_Table::getDefaultAdapter();
                $time = $this->_DB->query('SELECT time FROM `CapturesList` WHERE InnerLink = \'' . $_SERVER['REQUEST_URI'] . '\' LIMIT 0,1;')->fetchAll();
    
    
    		@$this->view->time = $time[0]['time'];
    
    
                if ($time[0]['time'] != NULL) {
                    $times = split(', ', $time[0]['time']);
                    if (strtotime(($times[1]) . '/' . ($times[2]) . '/' . $times[0] . ' ' . $times[3] . ":00") < (int) (mktime())) {
                        if (strtotime(($times[1]) . '/' . ($times[2]) . '/' . $times[0] . ' ' . $times[3] . ":00") > 1347032555) {
                            $count = $this->_DB->query('SELECT *, COUNT(time) AS counts FROM `CapturesList` WHERE time IS NOT NULL;')->fetchAll();
                            $count = $count[0]['counts'];
                            @$newdate = strftime("%G, %m, %d, %H", strtotime(($times[1]) . '/' . ($times[2]) . '/' . $times[0] . ' ' . $times[3] . ":00 +" . ((int)($count / 2) + 1) . " weeks"));
                            @$this->_DB->query('UPDATE `CapturesList` SET `time` = \'' . ($newdate) . '\' WHERE InnerLink = \'' . $_SERVER['REQUEST_URI'] . '\';');
                            @$this->view->time = $newdate;
                        }
                        else{@$this->view->time = $time[0]['time'];}
                    } else {
                        @$this->view->time = $time[0]['time'];
                    }
                } else {
                    @$this->view->time = "NULL";
                }
            } catch (Exception $exc) {
                echo $exc->getTraceAsString();
                @$this->view->time = "NULL";
            }
    
    
    
            header('Refer: ' . $this->view->linktofunnel);
            if (session_id() == '')
                session_start();
            if ($this->_getParam('action') != 'save') {
                $_SESSION["domain"] = $this->view->domain;
                $_SESSION["owner"] = $this->OwnerData;
            }
        }

    Более говнокодного я давно не писал. Кажется я схожу с ума

    Stud, 06 Декабря 2012

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

    +79

    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
     private static String dbl2str(Object obj) {
            String value;                        
            String str = obj.toString();
            if (str.indexOf('E') != -1) {
                //System.out.print("1  ");
                String[] qwe = str.split("E");
                String newstr = "";
                int step = Integer.parseInt(qwe[1]);
                for (int ind = 0; ind < qwe[0].length(); ind++) {
                    if (step > 0) {
                        if ((ind == (step + 2)) && (ind != qwe[0].length())) {
                            newstr = newstr + '.';
                        }
    
                        if (str.charAt(ind) != '.') {
                            newstr = newstr + str.charAt(ind);
                        }
                        if ((ind == qwe[0].length() - 1) && (ind <= step)) {
                            for (int ind2 = 0; ind2 < (step + 1 - ind); ind2++) {
                                newstr = newstr + "0";
                            }
                        }
                    } else {
                        if (ind == 0) {
                            newstr = newstr + "0.";
                            for (int ind3 = 0; ind3 > step + 1; ind3--) {
                                newstr = newstr + "0";
                            }
                        }
                        if (str.charAt(ind) != '.') {
                            newstr = newstr + str.charAt(ind);
                        }
                    }
                }
                value = newstr;
            } else {
                value = obj.toString();
            }
             return value;                       
        }

    жгем, товарищи! Double to String!

    orion, 06 Декабря 2012

    Комментарии (9)
  9. JavaScript / Говнокод #12253

    +169

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if(navigator.appName == "Microsoft Internet Explorer") {
    	for(var i=0;i<$('.product_documents').length;i++)  if( ( (firstLaunch_onChangeDocs) && ($('.product_documents')[i].selectedIndex==0)) || (!firstLaunch_onChangeDocs) )
    	{
    	  document.getElementById($('.product_documents')[i].id).innerHTML = '';
    	  document.getElementById($('.product_documents')[i].id).outerHTML = document.getElementById($('.product_documents')[i].id).outerHTML.replace("</SELECT>", jsInternalDocuments + '</select>')
    	}
      } else
    	for(var i=0;i<$('.product_documents').length;i++)  if( ( (firstLaunch_onChangeDocs) && ($('.product_documents')[i].selectedIndex==0)) || (!firstLaunch_onChangeDocs) )
    	  $('.product_documents')[i].innerHTML = jsInternalDocuments;

    Очень альтернативная техника использования jquery.

    clauclauclau, 06 Декабря 2012

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

    −118

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    Если (ЕстьНомен.НайтиЗначение(Док.Номенклатура) > 0)
    	ИЛИ (ЕстьНомен.НайтиЗначение(Док.Номенклатура.Родитель) > 0) 
    	ИЛИ (ЕстьНомен.НайтиЗначение(Док.Номенклатура.Родитель.Родитель) > 0) 
    	ИЛИ (ЕстьНомен.НайтиЗначение(Док.Номенклатура.Родитель.Родитель.Родитель) > 0) 
    	ИЛИ (ЕстьНомен.НайтиЗначение(Док.Номенклатура.Родитель.Родитель.Родитель.Родитель) > 0) 
    	ИЛИ (ЕстьНомен.НайтиЗначение(Док.Номенклатура.Родитель.Родитель.Родитель.Родитель.Родитель) > 0) Тогда
    		ИтогоРМ = ИтогоРМ+Док.Сумма;
    КонецЕсли;

    ЕстьНомен - это элемент формы Список, т.е. код можно упростить до:

    Если ЕстьНомен.Принадлежит(Док.Номенклатура) =1 Тогда
    ИтогоРМ = ИтогоРМ+Док.Сумма;
    КонецЕсли;

    взято из конфигурации одного автодилера.

    VladC, 06 Декабря 2012

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