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

    В номинации:
    За время:
  2. Куча / Говнокод #12476

    +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
    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
    buildTree sentence graph =
        (M.lookup (0, length sentence - 1, DirLeft) finalGraph, finalGraph)
        where finalGraph = execState runEisner (M.fromList elementaryPathes)
              elementaryPathes =
                 map (\(i, word) -> ((i, i, DirLeft), elementaryPath DirLeft word)) indexed ++
                 map (\(i, word) -> ((i, i, DirRight), elementaryPath DirRight word)) indexed
              indexed = zip [0..] sentence
    
              runEisner = do
                  let len = length sentence
                  forM_ [1 .. len - 1] $ \l -> do
                      forM [0 .. len - 1 - l] $ \i -> do
                          matrix <- get
                          let j = i + l
                          let w1 = sentence !! i
                          let w2 = sentence !! j
    
                          let buildConcat dir = (catMaybes $ (zipWith (\p1 p2 -> join $ (liftM2 concatenatePath) p1 p2)
                                                [M.lookup (i, k, dir) matrix | k <- [i + 1 .. j - 1]]
                                                [M.lookup (k, j, dir) matrix | k <- [i + 1 .. j - 1]])) :: [Path]
    
                          let buildJoin dir key = fromMaybe [] $ M.lookup key graph >>= \link ->
                                                  return (catMaybes (zipWith (\p1 p2 -> join $ (liftM2 (\f c -> joinPath f c link)) p1 p2)
                                                  [M.lookup (i, k, dir) matrix | k <- [i .. j - 1]]
                                                  [M.lookup (k, j, rev dir) matrix | k <- [i + 1 .. j]]))
    
                          let posR = (buildConcat DirRight ++ buildJoin DirRight (w1, w2)) :: [Path]
    
                          let newMatrix = if (not . null) posR
                                              then M.insert (i, j, DirRight) (minimumBy compWeight posR) matrix
                                              else matrix
    
                          let posL = buildConcat DirLeft ++ buildJoin DirRight (w2, w1)
    
                          let newMatrix' = if (not . null) posL
                                               then M.insert (i, j, DirLeft) (minimumBy compWeight posL) matrix
                                               else newMatrix
    
                          put newMatrix'

    Кусок из диплома по NLP. Yuuri неделю как познал монаду State и сделал двумерный императивный цыкл.

    Yuuri, 25 Января 2013

    Комментарии (5)
  3. SQL / Говнокод #12454

    −167

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    SELECT
    	slave.*,
             -- ...
    	FROM
    		(SELECT * FROM driver WHERE id = '$driverID') as slave
    	LEFT JOIN
             -- ...

    Отыскал в работающем проекте

    et, 21 Января 2013

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

    +54

    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
    <?php
    
        class ArrObj implements ArrayAccess, Countable, Iterator
        {
    
            protected $_data = array();
            protected $_indexes = array();
            protected $_pos = 0;
    
            public function __construct($data = array())
            {
                $this->_data = $data;
            }
    
            public function offsetGet($name)
            {
                if($isset = isset($this->_data[$name])) return $this->_data[$name];
                $this->_data[$name] = new self();
                return $isset ? $this->_data[$name] : null;
            }
    
            public function offsetSet($name, $value)
            {
                if(is_array($value)) $value = new self($value);
                $this->_data[$name] = $value;
                $this->_indexes[] = $name;
                return $value;
            }
    
            public function offsetUnset($name)
            {
                unset($this->_data[$name]);
                $this->_indexes = array_merge(array_diff($this->_indexes, array($name)));
            }
    
            public function offsetExists($name)
            {
                return isset($this->_data[$name]);
            }
    
            public function count()
            {
                return count($this->_data);
            }
    
            public function rewind()
            {
                $this->_pos = 0;
            }
    
            public function current()
            {
                return $this->_data[$this->_indexes[$this->_pos]];
            }
    
            public function key()
            {
                return $this->_indexes[$this->_pos];
            }
    
            public function next()
            {
                ++$this->_pos;
            }
    
            public function valid()
            {
                return isset($this->_indexes[$this->_pos]);
            }
    
        }
    
    ?>

    Sarkian, 18 Января 2013

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

    +42

    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
    function test($method)
    {
      $picfile = 'pic1.png';
      $bgfile = 'output.png';
      $background = 'pic2.png';
      $foreground = 'pic3.png';
    
      if ($method == 'Imagick') {
        $img = new Imagick($picfile);
    
        $mask = new Imagick($background);
        $img->compositeImage($mask, imagick::COMPOSITE_COPYOPACITY, 0, 0);
        $mask->destroy();
    
        $overlay = new Imagick($foreground);
        $img->compositeImage($overlay, imagick::COMPOSITE_OVER, 0, 0);
        $overlay->destroy();
    
        $img->setImageFormat('png');
        file_put_contents($bgfile, $img->getImageBlob()); // $img->writeImage($bgfile) работает медленнее
        $img->destroy();
      } else if ($method == 'Wand') {
        $img = NewMagickWand();
        MagickReadImage($img, $picfile);
    
        $mask = NewMagickWand();
        MagickReadImage($mask, $background);
        MagickCompositeImage($img, $mask, MW_CopyOpacityCompositeOp, 0, 0);
        DestroyMagickWand($mask);
    
        $overlay = NewMagickWand();
        MagickReadImage($overlay, $foreground);
        MagickCompositeImage($img, $overlay, MW_OverlayCompositeOp , 0, 0);
        DestroyMagickWand($overlay);
    
        MagickSetImageFormat($img, 'png');
        file_put_contents($bgfile, MagickGetImagesBlob($img)); // ditto
        DestroyMagickWand($img);
      } else {
        $cmdline = 'convert -compose copy-opacity ' . $picfile . ' ' . $background . ' -composite';
        $cmdline .= ' -compose src-over ' . $foreground . ' -composite ' . $bgfile;
        exec($cmdline);
      }
    }
    
    $methods = array('Imagick', 'Wand', 'Command line');
    foreach ($methods as $m) {
      $start_time = microtime(true);
      for ($i = 0; $i < 4; $i++) {
        test($m);
      }
      $elapsed_time = microtime(true) - $start_time;
      echo 'Method: ' . $m . '; elapsed ' . strval($elapsed_time) . PHP_EOL;
    }

    Результаты выполнения на локальной машине:
    Method: Imagick; elapsed 0.45...
    Method: Wand; elapsed 0.82...
    Method: Command line; elapsed 0.87...
    Результаты выполнения на VPS:
    Method: Imagick; elapsed 79.64...
    Method: Wand; elapsed 151.64...
    Method: Command line; elapsed 46.49...

    Что-то тут не так...

    inkanus-gray, 17 Января 2013

    Комментарии (5)
  6. JavaScript / Говнокод #12373

    +155

    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
    function moveAll(objectFrom, objectTo)
    {
        var list_len = objectFrom.length;
        if (list_len > 0)
        {
            // i is 0 all the time in the loop
            for (i=0; objectFrom.length>0;)
            {
                var new_option = new Option (objectFrom[i].text, objectFrom[i].value);
                objectTo[objectTo.length] = new_option;
                objectFrom[i] = null;
            }
        }
    }

    Литералы — для лузеров (я имею в виду objectForm[0])!

    wissenstein, 28 Декабря 2012

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

    +134

    1. 1
    int y = (int)Math.Floor((decimal)(block_number / w));

    все переменные - int

    akai_mirror, 26 Декабря 2012

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

    +52

    1. 1
    2. 2
    3. 3
    } catch (\Exception $e) {
                echo "<h1>Noooooooooooooooooooo!!!!!!</h1>"; 
            }

    __proto__, 25 Декабря 2012

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    i = 0;
      while ((p_c = strchr(&str[i], c)) != NULL) {
        k = p_c - str;           
        for (j = 0;  j < k - i;  j++)
          putchar(' ');
        putchar('*');              
        i = k + 1;               
      }
      putchar('\n');

    очень простой способ подчеркнуть определённые символы в массиве знаков

    taburetka, 22 Декабря 2012

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

    +39

    1. 1
    2. 2
    3. 3
    4. 4
    function getTextLabel($labelName)
    {
    	return $labelName;
    }

    Зачем плодить такие фейки?

    v_anonym, 19 Декабря 2012

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

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    if ((frequency < config->frequency_max) || (frequency > config->frequency_min)) {
          printk(KERN_ERR "%s: Frequency beyond limits, frequency=%d\n", __func__, frequency);
          return -EINVAL;
        }

    Коллега отыскал где-то в недрах dvb подсистемы, в драйвере mopll'ки TDA6651.

    Necromant, 12 Декабря 2012

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