1. Куча / Говнокод #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)
  2. 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)
  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 / Говнокод #12435

    +163

    1. 1
    2. 2
    3. 3
    type = ~~(Math.random()*5);
    if (type == 0) type = 1;
    else type = 0;

    Кручу-верчу, вобщем, как обычно.

    wvxvw, 17 Января 2013

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

    +54

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    // sys
    if ($flag==1) {
            $rr = implode("</B>, <B>",$nks1)."</B> и <B>".implode("</B>, <B>",$nks2);
    } elseif ($flag==2) {
        $rr = implode("</B>, <B>",$nks1)."</B> и <B>".implode("</B>, <B>",$nks2)."";
    } else {
        $rr = implode("</B>, <B>",$nks1)."</B> и <B>".implode("</B>, <B>",$nks2)."";
    }

    Это нашел в движке одной онлайн игры... Три проверки, но 1 и то же действие... Логика, мать её...

    RickMan, 16 Января 2013

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

    +116

    1. 1
    2. 2
    public const string Checked = "☑";
    public const string Unchecked = "☐";

    Чекбокс

    roman-kashitsyn, 16 Января 2013

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

    +55

    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
    <?php
    
    // ... много строк до этого
    
    echo "<table width=100% border=0>";
    if ($row = mysql_fetch_array($result))
    	for ($i = 0; $i < mysql_num_fields($result); $i++):	
    		if (mysql_field_name($result, $i) == "ID" || (mysql_field_name($result, $i) == "info") ||
    				mysql_field_name($result, $i) == "state" || (mysql_field_name($result, $i) == "date_st") ||
    				mysql_field_name($result, $i) == "date" || (mysql_field_name($result, $i) == "email") ||
    				mysql_field_name($result, $i) == "flag" || (mysql_field_name($result, $i) == "limit_time") ||
    				mysql_field_name($result, $i) == "cr_time" || mysql_field_name($result, $i) == "cr_money" ||
    				mysql_field_name($result, $i) == "flag" || (mysql_field_name($result, $i) == "info") ||
    				mysql_field_name($result, $i) == "attention" || mysql_field_name($result, $i) == "location" ||
    				mysql_field_name($result, $i) == "mailflag" || (mysql_field_name($result, $i) == "radio") ||
    				mysql_field_name($result, $i) == "radio30" || (mysql_field_name($result, $i) == "date_num") ||
    				mysql_field_name($result, $i) == "number" || mysql_field_name($result, $i) == "login_i"
    				|| mysql_field_name($result, $i) == "is_juridical")
    		{
    			if (mysql_field_name($result, $i) == "state")
    			{
    				echo "<select name=state style=\"background-color:red;color:white\"><option value=OPEN";
    				if ($row[$i] == "OPEN")
    					echo " selected ";
    				echo ">" . trans("OPEN") . "</option>\n";
    				echo "<option value=CLOSE";
    				if ($row[$i] == "CLOSE")
    					echo " selected ";
    				echo ">" . trans("CLOSE") . "</option></select\n";
    			}
    			elseif (mysql_field_name($result, $i) == "location")
    			{
    				genLeased($row[$i]);
    			}
    			elseif (mysql_field_name($result, $i) == "radio30" || mysql_field_name($result, $i) == "radio" || 
    				 mysql_field_name($result, $i) == "mailflag" )
    			
    			{
    			}
    			elseif (mysql_field_name($result, $i) == "date_st")
    			{
    				$ar = explode("-", $row[$i]);
    				echo "<b id=red>" . $ar[2] . "." . $ar[1] . "." . $ar[0] . "</b></td></tr>\n";
    			}
    			elseif (mysql_field_name($result, $i) == "date_num")
    			{
    				$ar = explode("-", $row[$i]);
    				$dnum = $ar[2] . "." . $ar[1] . "." . $ar[0];
    				
    				echo "<b>" . $dnum . "</b></td></tr><tr><td><a href=\"contracts/index.php?user_id=" . $row['ID'] . "\">контракти</a></td></tr><tr><td colspan=2><hr noshade></td></tr>\n";
    			}
    
    			elseif (mysql_field_name($result, $i) == "date")
    			{
    				$ar = explode("-", $row[$i]);
    				$row[$i] = $ar[2] . "." . $ar[1] . "." . $ar[0];
    				echo "<input type=text name=date value=\"" . $row[$i] . "\"</td></tr>\n";
    			}
    			elseif (mysql_field_name($result, $i) == "info")
    			{
    				echo "<textarea  rows=3 name=" . mysql_field_name($result, $i) . " >" . $row[$i] . "</textarea></td></tr>\n";
    			}
    			elseif (mysql_field_name($result, $i) == "attention")
    			{
    				echo "<textarea id=warn rows=3 name=" . mysql_field_name($result, $i) . " >" . $row[$i] . "</textarea></td></tr>\n";
    			}
    // ... и так обрабатываем далее все поля

    Разработчик сначала запросил результат с помощью mysql_fetch_array,
    потом ищет название каждого поля с помощью mysql_field_name, функцией trans()
    читает файлик со словарем и переводит название каждого поле.

    Писалось не индусами, вариант "для количества" не прокатывает.
    Поэтому я не могу даже предположить, что сподвигло автора на создание сего творения.
    Файл содержит около 1400 строчек.

    rsvasilyev, 16 Января 2013

    Комментарии (2)
  8. Python / Говнокод #12428

    −90

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    def python_3():
        try:
            exec("print ''")
            return False
        except:
            return True

    Python 2: http://ideone.com/z4NADC
    Python 3: http://ideone.com/IcpTUr

    bormand, 16 Января 2013

    Комментарии (22)
  9. SQL / Говнокод #12427

    −139

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    CREATE TABLE `forums_list`(
        `forum_id` int unsigned NOT NULL AUTO_INCREMENT,
         ...
        `created` datetime NOT NULL DEFAULT NULL,
        `updated` datetime NOT NULL DEFAULT NULL,

    Alex_Slubsky, 16 Января 2013

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

    +22

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    int sqr(int n)
    {
      unsigned int result=n>=0?n:-n;
      n=result<<1;
      do result+=n-=2; while(n);
      return result;
    }

    Эта функция считает квадрат числа n. Писал не я, целей создания не знаю.

    ales-hon-ne, 16 Января 2013

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