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

    В номинации:
    За время:
  2. 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)
  3. 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)
  4. 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)
  5. C# / Говнокод #12365

    +134

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

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

    akai_mirror, 26 Декабря 2012

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

    +52

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

    __proto__, 25 Декабря 2012

    Комментарии (5)
  7. Си / Говнокод #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)
  8. PHP / Говнокод #12318

    +39

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

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

    v_anonym, 19 Декабря 2012

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

    +50

    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
    public function getFilename($filename) {
            $string = ereg_replace("ж", "zh", $filename);
            $string = ereg_replace("ё","yo",$string);
            $string = ereg_replace("и", "i",$string);
            ......
    
            $string = ereg_replace("Т","T",$string);
            $string = ereg_replace("Б","B",$string);
            
            $string = ereg_replace(" ","_",$string);
            $filename = preg_replace("/[^\w\.\-_]/","",$string);
            
            return strtolower($filename);
        }

    UnnamedUser, 01 Декабря 2012

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

    +10

    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
    template <typename T, size_t rows, size_t cols>
    class Matrix {
    public:
        Matrix() :
            m_matrix(new T[rows * cols])
        {
            // Make identity matrix, if possible
            if ( rows == cols ) {
                for ( size_t i = 0; i < rows; i++ )
                    m_matrix[i * cols + i] = 1; // FIXME: this is hack
            }
    
        }
    
        // ...
    
        Matrix<T, rows, cols>& operator =(Matrix<T, rows, cols> &&other) {
            if ( this != &other ) {
                delete [] m_matrix;
                m_matrix = other.m_matrix;
    
                other.m_matrix = new T[cols * rows];
                other = static_cast<const Matrix&>(Matrix());
            }
    
            return *this;
        }
    
        // ...
    };

    Издержки move construtor :)

    Прошу внимания к строчкам 19-23

    Elvenfighter, 30 Ноября 2012

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