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

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

    −176

    1. 1
    2. 2
    3. 3
    4. 4
    def reverse(s, rs=''):
        for i in range(1, len(s)):
            rs = rs + s[len(s)-i]
        return rs+s[0]

    Reverse String по-питоновски с говном

    Govnocoder#0xFF, 10 Мая 2011

    Комментарии (28)
  3. PHP / Говнокод #6493

    +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
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    // Подходы различной национальности
    
    /* Первый */
    function filesize_format($bytes, $format = '', $force = ''){
       $force = strtoupper($force);
       $defaultFormat = '%01d %s';
       if (strlen($format) == 0)
       $format = $defaultFormat;
       $bytes = max(0, (int) $bytes);
       $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
       $power = array_search($force, $units);
       if ($power === false)
       $power = $bytes > 0 ? floor(log($bytes, 1024)) : 0;
       return sprintf($format, $bytes / pow(1024, $power), $units[$power]);
    }
    /* Второй */
    function files_size( $size )
    {
        $name = array('Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
        $mysize = $size ? round( $size / pow(1024, ( $i = floor( log( $size, 1024 ) ) ) ), 2) .' ' .$name[$i] : $size.' Bytes';
        return $mysize;
    }
    /* Третий */
       function humanSize($size) {
          $a = array("bytes", "kb", "Mb", "Gb", "Tb", "Pb");
          $pos = 0;
          while ($size >= 1024) {
           $size /= 1024;
           $pos++;
          }
          return round($size,2)." ".$a[$pos];
         }

    Вопрос: Определите географические координаты места написания каждого...

    DoctorHouse, 27 Апреля 2011

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

    +165

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function sorti()
        {
        	if($_GET['where']=='desc'?$where='asc':$where='desc');
        	return 'where='.$where;
        }

    GoodTalkBot, 19 Апреля 2011

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    <table>
         <form method="post" action="/ololo/onatole.html?step={{if $step eq '2'}}3{{else}}6{{/if}}">
         <tr><td><a id="submit">...
    ....

    фаерфокс отлично парсит такие формы внутри таблиц, jQuery(this).closest('form') тоже возвращает все превосходно

    govno, 18 Апреля 2011

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

    +176

    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
    $navChain=array();
       for($i = 0; $i < count($menu); $i++){
    		if (is_array($menu[$i]['subMenu'])) {
    			for($j = 0; $j < count($menu[$i]['subMenu']); $j++){
    				if (is_array($menu[$i]['subMenu'][$j]['subMenu'])) {
    					for($k = 0; $k < count($menu[$i]['subMenu'][$j]['subMenu']); $k++){
    						if (is_array($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'])) {
    							for($l = 0; $l < count($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu']); $l++){
    								if (is_array($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['subMenu'])) {
    									for($m = 0; $m < count($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['subMenu']);$m++){
    										if ($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['subMenu'][$m]['selected']=='1') {
    											$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['subMenu'][$m];
    											$menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['selected']=1;
    											$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l];
    											$menu[$i]['subMenu'][$j]['subMenu'][$k]['selected']=1;
    											$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k];
    											$menu[$i]['subMenu'][$j]['selected']=1;
    											$navChain[]=$menu[$i]['subMenu'][$j];
    											$menu[$i]['selected']=1;
    											$navChain[]=$menu[$i];
    										}
    									} // for
    								}
    								if ($menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l]['selected']=='1') {
    									$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k]['subMenu'][$l];
    									$menu[$i]['subMenu'][$j]['subMenu'][$k]['selected']=1;
    									$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k];
    									$menu[$i]['subMenu'][$j]['selected']=1;
    									$navChain[]=$menu[$i]['subMenu'][$j];
    									$menu[$i]['selected']=1;
    									$navChain[]=$menu[$i];
    								}
    							} // for
    						}
    						if ($menu[$i]['subMenu'][$j]['subMenu'][$k]['selected']=='1') {
    						$navChain[]=$menu[$i]['subMenu'][$j]['subMenu'][$k];
    							$menu[$i]['subMenu'][$j]['selected']=1;
    							$navChain[]=$menu[$i]['subMenu'][$j];
    							$menu[$i]['selected']=1;
    							$navChain[]=$menu[$i];
    						}
    					} // for
    				}
    				if ($menu[$i]['subMenu'][$j]['selected']=='1') {
    					$navChain[]=$menu[$i]['subMenu'][$j];
    					$menu[$i]['selected']=1;
    					$navChain[]=$menu[$i];
    				}
    			} // for
    		}
    		if ($menu[$i][selected] && empty($navChain)) {
    			$navChain[]=$menu[$i];
    		}
    	} // for

    volatile, 09 Апреля 2011

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

    +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
    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
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
    	const int hz_limit = 20000;
    	string str;
    	string str_mass[] = {"a", "b", "ais", "h", "ces", "c", "his", "cis", "des",
    		"d", "dis", "es", "e", "fes", "f", "eis", "fis", "ges", "g", "gis", "as"};
    	begin:
    	while (cin>>str)
    	{
    		for (size_t ix = 0; ix != str.size(); ++ix)
    		{
    			str[ix] = tolower(str[ix]);
    		}
    		size_t f = 0;
    		for (size_t ix = 0; ix != 21; ++ix)
    		{
    			if(str == str_mass[ix])
    			{
    				f = ix;
    			}
    		}
    		if (str != str_mass[f])
    		{
    			goto begin;
    		}
    		double mass[] = {27.500, 29.135, 29.135, 30.868, 30.868, 32.703, 32.703, 34.648, 34.648,
    		36.708, 38.891, 38.891, 41.203, 41.203, 43.654, 43.654, 46.249, 46.249, 48.999, 51.913, 51.913};
    		for (; mass[f] < hz_limit; mass[f] *= 2)
    			{
    				cout<<mass[f]<<" Hz"<<endl;
    			}
    	}
    	return 0;
    }

    Моя первая прога. Выводит частоты на которых находится введенная нота...

    Extrawelt, 21 Марта 2011

    Комментарии (28)
  8. Си / Говнокод #5887

    +105

    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
    #define C_WRONG              -2000
    
    ....
    
    int tttt_atoi(char* p_string){
    
       int result = C_WRONG;
    
       if ( *p_string < '0' || *p_string > '9' )
          return C_WRONG;
    
       result = atoi(p_string);
       return result;
    }
    
    double tttt_atof(char* p_string){
    
       double result = C_WRONG;
       result = atof(p_string);
       if (result!=0){
          return result;
       }
       else{
          if(strcmp(p_string,"0.0")==0 || strcmp(p_string,"0")==0 || strcmp(p_string,"0.")==0){
             return result;
          }
          else{
             return C_WRONG;
          }
       }
    }

    и вы посмейтесь. или facepalm'нитесь. синтакс оригинала.

    Dummy00001, 04 Марта 2011

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

    −131

    1. 1
    ping -q -c 2 -i "0.$ACTN" localhost > /dev/null

    Способ заснуть менее чем на секунду, не дописывая для этого отдельную программу Сишную с использованием nanosleep().

    xaionaro, 21 Февраля 2011

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

    +122

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    catch (TargetInvocationException ex) {
         try {
              throw ex.InnerException;
         }
         catch (EndpointNotFoundException innerEx) {
              factory.Abort();
              throw new InvalidOperationException("Service unreachable", innerEx);
         }
    }

    Обработчик исключений %)

    Guid, 16 Февраля 2011

    Комментарии (28)
  11. PHP / Говнокод #5630

    +157

    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
    if($amount > 0) :
    	if (is_dir($directory)) {
    		if ($open_dir = opendir($directory)) {
    			$a = 0; $b = 0;
    			while (false !== ($file = readdir($open_dir))) {
    				if ($file != "." && $file != ".." && !is_dir($directory."/".$file)) {
    					$a++;
    					if($a > $min) {
    						$b++;
    						echo "<tr id=\"am-list-input\" valign=\"center\" height: 20px;><td align=\"left\" width=\"10%\">";
    						echo " <a href=\"index.php?am=mod[uploader]&delete=$file\"><img src=\"../images/mini_icons/del.png\" /></a> ";
    						if(in_array(strtolower(getExtension($file)), $gud_types)) echo "<span OnClick=\"CaricaFoto('".$directory."/".$file."')\" OnMouseOver=\"Tip('<img style="max-width: 400px" src="".$directory."/".$file."" >')\"><img style=\"cursor: help\" src=\"../images/mini_icons/display.png\" /></span>";
    						if(in_array(strtolower(getExtension($file)), explode(',', strtolower("mp3,wma,waw,amr,ape,bin,flac,m4a,mdi,ram")))) echo "<img src=\"modules/mod[uploader]/assets/type/sound.png\" />";
    						if(in_array(strtolower(getExtension($file)), explode(',', strtolower("3gp,avi,dat,flv,ifo,m4v,mkv,mov,mp4,rm,vob,wmv")))) echo "<img src=\"modules/mod[uploader]/assets/type/video.png\" />";
    						if(!in_array(strtolower(getExtension($file)), explode(',', strtolower("3gp,avi,dat,flv,ifo,m4v,mkv,mov,mp4,rm,vob,wmv,mp3,wma,waw,amr,ape,bin,flac,m4a,mdi,ram,jpg,jpeg,png,gif")))) echo "<img src=\"modules/mod[uploader]/assets/type/all.png\" />";
    						echo "</td><td width=\"70%\"><span style=\"display: block; cursor: pointer; color: #446eb8; font-weight: bold; line-height: 16px;\" onClick=\"document.getElementById('onclick').value='".str_replace("..", $conf_global["base_url"], $directory)."/".$file."'\" />".substr($file, 0, 100)."</span></td><td width=\"20%\">".formatsize(filesize($directory.DS.$file))."</td></tr>";
    						if($b == $max) : break; endif;
    					}
    				}
    			}
    		closedir($open_dir);
    		}
    	}
    endif;

    Грех не посмеятся над своими старыми проектами =)))

    nethak, 11 Февраля 2011

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