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

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

    +143

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    /**
    * Generates a random number
    */
    function doRand()
    {
      var num;
      now=new Date();
      num=(now.getSeconds());
      num=num+1;
      return num;
    };

    Пожалуй, лучшая функция генерации случайного числа

    u4n, 10 Июня 2015

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

    +143

    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
    System.String origString;
    System.Int32 index;
    System.Console.WriteLine("Введите строку: ");
    origString = System.Console.ReadLine();
    
    System.Int32 length = 0;
    for (int i = 0; i < origString.Length; i++)
        length++;
    
    System.Console.WriteLine("Какую букву вычесть?: ");
    index = System.Console.Read() - 49;
    System.Char[] newString = new System.Char[origString.Length];
    
    for (int i = 0; i < length; i++)
    {
        if (i != index && index != i && i != null && index != null)
        {
            newString[i] = origString[i];   
        }
        if (i == index && index == i && i != null && index != null)
        {
            newString[i] = Convert.ToChar(7);
        }
    }
    
    System.Console.Write("Результат: ");
    
    length = 0;
    for (int i = 0; i < newString.Length; i++)
        length++;
    for(int i = 0; i < length; i++)
        System.Console.Write(newString[i]);
    
    System.Console.ReadLine();
    System.Console.ReadLine();

    Ответ на вопрос на toster.ru
    Как сделать это на c#?
    Вычеркните i-ю букву заданной строки
    https://toster.ru/q/222727

    limited_ed, 06 Июня 2015

    Комментарии (0)
  4. Куча / Говнокод #18286

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    n =: 50000
    f =: 3 : '(a=0 2)*.1=(?2){x{~a=:?3'
    x =: 1 1 0 0 1 0 $~ n, 3 2
    t%+/t=:+/f"2 x

    Abbath, 05 Июня 2015

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

    +143

    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
    if(file.open(QIODevice::ReadOnly))
    {
        QTextStream in(&file);
    
        while(!in.atEnd())
        {
            textString = in.readLine();
            linesText += textString;
            linesText += "\n";
        }
    
        linesText.chop(1);
    }
    else
        try
        {
            throw 20;
        }
        catch (int e)
        {
            cout « "Файл записей не был открыт!" « e « endl;
        }

    В проекте одногруппника

    belozorov63, 03 Июня 2015

    Комментарии (0)
  6. PHP / Говнокод #18265

    +143

    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
    if ($fuck) {
      foreach ($objects as $obj) {
        if (!$obj['CAT_VALUE']) {
          die('У объекта ' . $obj['NAME'] . ' ошибка');
        }
        if (!$obj['DESCR_VALUE']) {
          die('У объекта ' . $obj['NAME'] . ' ошибка');
        }
        if (!$obj['DESCR_VALUE']) {
          die('У объекта ' . $obj['NAME'] . ' ошибка');
        }
        else {
          die('Какая-то ошибка');
        }
      }
    }

    Кусок самописного компонента под Битрикс от предыдущего разработчика (тот еще затейник!). Просто выпилил это, т.к. не понял как это отрефакторить, т.к. $fuck нигде никак не объявлена. Да и вообще ценность этого блока кода и так сильно пахнет.

    Franchesko, 01 Июня 2015

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

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if ($review) {
    	# даем возможность исполнителю оставить свой отзыв
    }else{
    	# заморозила именно администрация
    	echo json_encode(array(
    		'status' => 'error',
    		'message' => 'Задание заморожено Администрацией.',
    	));
    }

    Нам важно ваше мнение

    VokaMut, 01 Июня 2015

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

    +143

    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
    /**
         * Returns the first line of docblock.
         *
         * @param \Reflector $reflection
         * @return string
         */
        protected function parseDocCommentSummary($reflection)
        {
            $docLines = preg_split('~\R~u', $reflection->getDocComment());
            if (isset($docLines[1])) {
                return trim($docLines[1], "\t *");
            }
            return '';
        }
        /**
         * Returns full description from the docblock.
         *
         * @param \Reflector $reflection
         * @return string
         */
        protected function parseDocCommentDetail($reflection)
        {
            $comment = strtr(trim(preg_replace('/^\s*\**( |\t)?/m', '', trim($reflection->getDocComment(), '/'))), "\r", '');
            if (preg_match('/^\s*@\w+/m', $comment, $matches, PREG_OFFSET_CAPTURE)) {
                $comment = trim(substr($comment, 0, $matches[0][1]));
            }
            if ($comment !== '') {
                return rtrim(Console::renderColoredString(Console::markdownToAnsi($comment)));
            }
            return '';
        }

    Yii2, SOLID, очередной класс консольного приложения, который делает все подряд и хуево

    https://github.com/yiisoft/yii2/blob/47bcd020fff582395db8fe9e00598acad0257922/framework/console/Controller.php#L481-L512

    Fike, 29 Мая 2015

    Комментарии (10)
  9. PHP / Говнокод #18253

    +143

    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
    class Security{
        
        private $workFactor, $salt;
        
        public function __construct(){
            $this->setWorkFactor();
            $salt = $this->getSaltBytes();
            $this->setSalt($salt);
        }
        
        public function hash($password, $workFactor = 6){
            $options = [
                'cost' => (int)$workFactor,
                'salt' => $this->getSalt()
            ];
            $hash = password_hash($password, PASSWORD_BCRYPT, $options);
            return $hash;
        }
    
        public function checkHash($password, $passwordHash, $options = []){
            if( isset($options['salt'])){
                $this->setSalt($options['salt']);
            }
            $workFactor = isset($options['workFactor']) ? 
                    $options['workFactor'] : $this->getWorkFactor();
            return $passwordHash === $this->hash($password, $workFactor);
        }
        
        public function isLegacyHash($passwordHash){
            return strlen($passwordHash) === 60;
        }
        
        public function getSalt(){
            return $this->salt;
        }
        
        public function setSalt($salt){
            $this->salt = $salt;
        }
        
        public function getSaltBytes($lenght = 24){
            return $this->getRandomBytes($lenght);
        }
    
        public function getRandomBytes($lenght = 24){
            $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            $charactersLength = strlen($characters);
            $randomString = '';
            for ($i = 0; $i < $lenght; $i++){
                $randomString .= $characters[rand(0, $charactersLength - 1)];
            }
            return $randomString;
        }
        
        public function setWorkFactor($workFactor = 6){
            $this->workFactor = (int)$workFactor;
        }
        
        public function getWorkFactor(){
            return $this->workFactor;
        }
        
    }

    Besmer, 28 Мая 2015

    Комментарии (28)
  10. PHP / Говнокод #18246

    +143

    1. 1
    http://govnokod.ru/comments/18245/rss ru [email protected] (govnokod.ru support) Mzz.Framework v.100500-release Wed, 27 May 2015 21:20:29 +0400 Fatal error: Call to a member function getCreated() on a non-object in /home/striker/applications/govnokod/tmp/templates_c/1563503196.file.export_quote_rss.tpl.php-ru.php on line 21

    http://govnokod.ru/, в чём дело:

    Dev_18, 27 Мая 2015

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

    +143

    1. 1
    fp_env = popen("env", "r");

    не ну я даже не знаю.

    Dummy00001, 27 Мая 2015

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