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

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

    −116

    1. 1
    2. 2
    СтрокаСуммаСРазделителями = Строка(ТекСсылка.СуммаДокумента);
    СтрокаСуммаБезРазделителей = СтрЗаменить(СтрокаСуммаСРазделителями, СимволРазделительСуммы, "");

    Видать, использование "Формат" запрещено внутренней политикой =(

    kovyl2404, 08 Февраля 2013

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

    +160

    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
    $("#pastas").on('change', function () {
                var myString = $("#pastas").val();
                var myArray = myString.split('');
                // display the result in myDiv
                for (var i = 0; i < myArray.length; i++) {
                    if (myArray[i] == "@") {
                        skai++;
                    } else if (myArray[i] == ".") {
                        skai++;
                    }
                }
                if (skai == 2) {
                    $('#pastas').removeClass('blogai');
                    console.log('gerai');
                } else {
                    $('#pastas').addClass('blogai');
                    console.log('blogai');
                }
            });

    Валидность почты по Литовски...

    nonamez, 06 Февраля 2013

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

    +152

    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
    var retriesLeft = 100;
    while (true)
    {
        try
        {
            return SetRestorePoint(0, pointType, enentType, description);
        }
        catch (Win32Exception ex)
        {
            if (ex.NativeErrorCode != ErrorServiceDisabled || retriesLeft < 0)
                throw;
    
            Thread.Sleep(500);
            retriesLeft--;
        }
    }

    abatishchev, 01 Февраля 2013

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

    +128

    1. 1
    2. 2
    wr = new StreamWriter(fs);
    wr.WriteLine(string.Format("{0}", toPrint));

    redrick, 31 Января 2013

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    http://odnoklassniki.ru/dk
    	?cmd=PopLayer
    	&tkn=9739
    	&st.cmd=error
    	&st.stid=anonymPasswordRecovery
    	&st.eclass=java.lang.IllegalStateException
    	&st.layer.cmd=PopLayerSystemError

    Парсер тоже видит ЭТО и предлагает положить в не «Кучу», а в «Java».

    nsauk, 29 Января 2013

    Комментарии (5)
  7. Куча / Говнокод #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)
  8. 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)
  9. 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)
  10. 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)
  11. 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)