1. Си / Говнокод #12447

    +110

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    int strnlen(const char *s, int size)
    {
            int i;
            for(i=0; i<size; i++) if(!*s) break;
            return i;
    }

    tz-lom, 18 Января 2013

    Комментарии (36)
  2. C# / Говнокод #12446

    +139

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    List<string> duplicities = new List<string>();
    
          foreach (var localItem in FileCollectionLocal)
          {
            foreach (var remoteItem in FileCollectionRemote)
            {
              if (localItem.FileName == remoteItem.FileName)
              {
                duplicities.Add(localItem.FileName);
              }
            }
          }

    taburetka, 18 Января 2013

    Комментарии (10)
  3. Куча / Говнокод #12445

    +129

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    > echo 1 >1.cp
    > echo 1 >1.cpp
    > echo 1 >1.cppp
    > dir /b *.cp
    1.cp
    > dir /b *.cpp
    1.cpp
    1.cppp

    Баг в FindFirstFile/FindNextFile, показан на виндовом dir для простоты демонстрации. Призрак DOS'а жив даже в семерке...

    bormand, 18 Января 2013

    Комментарии (38)
  4. SQL / Говнокод #12444

    −161

    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
    create temp table data (id serial, o1 money(16,2) default 0, o2 money(16,2) default 0,
    o3 money(16,2) default 0, o4 money(16,2) default 0, o5 money(16,2) default 0,
    o6 money(16,2) default 0, o7 money(16,2) default 0, o8 money(16,2) default 0,
    o9 money(16,2) default 0, o10 money(16,2) default 0, o11 money(16,2) default 0,
    o12 money(16,2) default 0, o13 money(16,2) default 0, o14 money(16,2) default 0,
    o15 money(16,2) default 0, o16 money(16,2) default 0, o17 money(16,2) default 0,
    o18 money(16,2) default 0, o19 money(16,2) default 0, o20 money(16,2) default 0,
    o21 money(16,2) default 0, o22 money(16,2) default 0, o23 money(16,2) default 0,
    o24 money(16,2) default 0, o25 money(16,2) default 0, o26 money(16,2) default 0,
    o27 money(16,2) default 0, o28 money(16,2) default 0, o29 money(16,2) default 0,
    o30 money(16,2) default 0, o31 money(16,2) default 0, f1 money(16,2) default 0,
    f2 money(16,2) default 0, f3 money(16,2) default 0, f4 money(16,2) default 0,
    f5 money(16,2) default 0, f6 money(16,2) default 0, f7 money(16,2) default 0,
    f8 money(16,2) default 0, f9 money(16,2) default 0, f10 money(16,2) default 0,
    f11 money(16,2) default 0, f12 money(16,2) default 0, f13 money(16,2) default 0,
    f14 money(16,2) default 0, f15 money(16,2) default 0, f16 money(16,2) default 0,
    f17 money(16,2) default 0, f18 money(16,2) default 0, f19 money(16,2) default 0,
    f20 money(16,2) default 0, f21 money(16,2) default 0, f22 money(16,2) default 0,
    f23 money(16,2) default 0, f24 money(16,2) default 0, f25 money(16,2) default 0,
    f26 money(16,2) default 0, f27 money(16,2) default 0, f28 money(16,2) default 0,
    f29 money(16,2) default 0, f30 money(16,2) default 0, f31 money(16,2) default 0,
    ftot money(16,2) default 0)

    ... must be funny in the rich man's world ...

    bormand, 18 Января 2013

    Комментарии (6)
  5. 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)
  6. C++ / Говнокод #12442

    +14

    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
    /*!
     * \brief Checks for a file existence
     */
    inline bool IsFolderExist( const boost::filesystem::path &path )
    {
        return boost::filesystem::exists( path ) && boost::filesystem::is_directory( path );
    }
    
    
    /*!
     * \brief Checks for a folder existence
     */
    inline bool IsFileExist( const boost::filesystem::path &path )
    {
        return boost::filesystem::exists( path ) && boost::filesystem::is_regular_file( path );
    }

    Нашёл у себя в проекте. Кручу верчу - обмануть хочу). Про то, что даже правильные комментарии тут нафиг не нужны - я уже молчу.

    suc-daniil, 17 Января 2013

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

    +49

    1. 1
    2. 2
    3. 3
    4. 4
    If($z["timeout"]==1 || $z['timeout']==3 || $z['timeout']==4 || $z['timeout']==5 || $z['timeout']==7 || $z['timeout']==10) { 
    }  else {
         $z['timeout'] = 3;
    }

    '<>' и 'or' ? неее, не слышали!

    RickMan, 17 Января 2013

    Комментарии (9)
  8. bash / Говнокод #12440

    −113

    1. 1
    http://lab.madscience.nl/oo.sh.txt

    ООП-фаги, набигайте!

    byss, 17 Января 2013

    Комментарии (8)
  9. Куча / Говнокод #12439

    +121

    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
    #Creates an array with the frequencies from C2 to C5, 37 notes in all
    for j from 1 to 37
    	if j = 1 
    	notes [j] = 65.41 # лёгкие пути не нужны
    	endif
    	if j = 2
    	notes [j] = 69.30
    	endif
    # ...дальше понятно...
    endfor
    
    # <...>
    
    #Determining whether or not the scale contains C
    #This determines how many notes of the 37 possible must be included.
    noCList [1] = 3 # опа, а вот тут уже научились числовые индексы использовать
    noCList [2] = 5
    noCList [3] = 7
    noCList [4] = 10
    noCList [5] = 12
    noC = 0
    for n from 1 to 5
    	if 'starter' = noCList['n']
    		noC = 1
    	endif
    endfor
    #If there is a C...
    if noC = 0
    #The for loop mathematically selects the scale notes to use
    for m from 1 to 22
    	if 'm' = 1
    		noteind = 'starter'
    	endif
    	if 'm' = 2
    		noteind = 'starter' + 2
    		if 'noteind' > 37
    			noteind = 'noteind' - 36
    		endif
    	endif
    # ...ага-ага...
    	scalenotes ['m'] = notes['noteind']
    endfor
    #If there is not a C...
    else
    for m from 1 to 21
    	if 'm' = 1
    		noteind = 'starter'
    	endif
    	if 'm' = 2
    		noteind = 'starter' + 2
    		if 'noteind' > 37
    			noteind = 'noteind' - 36
    		endif
    	endif
    # ...так точно...
    	scalenotes ['m'] = notes['noteind']
    endfor
    endif
    
    # <...>
    
    #Add new pitch information
    #For each point, we move the freq to the closest scale note
    for q from 1 to 'numPoints'
    	#The original freq of pitch
    	currentfreq = pitches['q']
    	#A starting threhold for difference between original and a musical note
    	diff = 50
    	#If there is C in the scale, making 22 possible notes to tune to...
    	if 'noC' = 0
    	#For loop finds the lowest difference between original pitch and a musical note
    	for c from 1 to 22
    		diff2 = abs('currentfreq' - scalenotes['c'])
    		if 'diff2' < 'diff'
    			diff = 'diff2'
    			noteindex = 'c'
    		endif
    	endfor
    	#Otherwise if there is not a C...
    	else
    	for c from 1 to 21
    		diff2 = abs('currentfreq' - scalenotes['c'])
    		if 'diff2' < 'diff'
    			diff = 'diff2'
    			noteindex = 'c'
    		endif
    	endfor
    	endif
    	#Add point at the original time with the new pitch
    	Add point... times['q'] scalenotes['noteindex']
    endfor

    http://schyzm.wordpress.com/2012/12/05/fun-with-praat-a-script-for-auto-tune/
    Скрипт питч-коррекции для речевого анализатора Praat на встроенном языке сценариев. Не знаю, это афтар так жжот или язык располагает к черезжопию, но что-то тут воняет однозначно.

    telnet, 17 Января 2013

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

    +12

    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
    int n, a[n]; //n - количество элементов
    void qs(int* s_arr, int first, int last) {
      int i = first, j = last, x = s_arr[(first + last) / 2]; 
      do   {
        while (s_arr[i] < x) i++;
        while (s_arr[j] > x) j--; 
        if(i <= j)  {
          if (i < j) swap(s_arr[i], s_arr[j]);
          i++;
          j--; }}
      while (i <= j);
      if (i < last) {
        qs(s_arr, i, last);  }
      if (first < j)  {
        qs(s_arr, first,j); }}

    Оттуда

    LispGovno, 17 Января 2013

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