1. C# / Говнокод #10006

    +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
    public static bool IpCheck(String ip)
            {
                String [] octs = ip.Split(new char[] { '.' });
    
                try
                {
    
                    for (int n = 0; n < 4; n++)
                    {
                        byte b = Convert.ToByte(octs[n]);
                    }
    
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }

    Индуский валидатор IP - адреса

    dens, 21 Апреля 2012

    Комментарии (3)
  2. Си / Говнокод #10005

    +128

    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
    Unsigned long int getset (void)
    {unsigned long int a; int k; h=0;
    While (‘<не конец файла>==<читать число в k>’);
    {switch k
    {case 1: h = h/0x 0001; break;
    case 2: h = h/0x 0002; break;
    case 3: h = h/0x 4; break;
    case 4: h = h/0x 8; break;
    case 5: h = h/0x 10; break;
    case 6: h = h/0x 20; break;
    case 7: h = h/0x 40; break;
    case 8: h = h/0x 80; break;
    …
    case 30: h = h/0x 2000 0000; break;
    case 31: h = h/0x 4000 0000; (- 1 на 31 месте) break;
    case 32: h = h/0x 8000 0000; (- 1 на 32 месте) break;
    }
    }
    return (h)
    }

    Мне кажется или весь смысл сводиться к h = h/2^(k-1)

    ApeNN, 21 Апреля 2012

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

    +100

    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
    procedure interpretation;
    var
    s,f:string;
    i,m,v:integer;
    
    begin
    s:=#0;
    
    for I:=0 to form9.Memo2.Lines.Count-1 do begin
      s:=form9.Memo2.Lines.Strings[i];//ïðîñìîòð ñòðîê èäåò
      //ñâåðõó âíèç
    
      if s='hex' then hex;
      if s='acsii' then acsii;
    
      if (s[1]='a') and (s[2]='d') and (s[3]='d') then begin
      form9.Edit6.Text:=s[5];
      form9.Edit5.Text:=s[7];
      peredsim;
      end;
    
      if (s[1]='s') and (s[2]='a') and (s[3]='m') then begin
      form9.Edit2.Text:=s[5];
      form9.Edit4.Text:=s[7];
      samsimbyl;
      end;
    
      if (s[1]='d') and (s[2]='e') and (s[3]='l') then begin
      form9.Edit3.Text:=s[5];
      for v:=1 to length(s) do
      deletesimbyl;
      end;
    
      if (s[1]='d') and (s[2]='e') and (s[3]='l') and (s[4]='s') then begin
      form9.Edit3.Text:=s[6];
      dels;
      end;
    
      if (s[1]='i') and (s[2]='n') and (s[3]='f') then begin
      form9.Memo1.Text:=s[5]+form9.Memo1.Text;
      end;
    
      if (s[1]='f') and (s[2]='n') and (s[3]='i') then begin
      form9.Memo1.Text:=form9.Memo1.Text+s[5];
      end;
    
      if (s[1]='p') and (s[2]='h') and (s[3]='e') then RapsrRedel;
    
    
      if (s[1]='n') and (s[2]='a') and (s[3]='b') then PerstNO;
    
    
      if (s[1]='a') and (s[2]='t') and (s[3]='s') then acsiitosim;
      if (s[1]='h') and (s[2]='t') and (s[3]='s') then hextosim;
      if (s[1]='h') and (s[2]='t') and (s[3]='a') then hextoacsii;
      if (s[1]='a') and (s[2]='t') and (s[3]='h') then acsiitohex;
    end;
    end;

    Нужно было быстро накодить интерпретатор, которым никто пользоваться не будет, кроме собственно автора программы, для создания простеньких скриптов (сами понимаете семантический анализатор писать, в данном случае не улыбалось). Потому получился такой МегОАдЪовый говнокод!

    Kerny, 21 Апреля 2012

    Комментарии (1)
  4. JavaScript / Говнокод #10001

    +159

    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
    function line( x0, y0, x, y, elmId ) {
    
    	var sx = x-x0, sy = y-y0, dir = (sx>sy), adir = (Math.abs(sx)>Math.abs(sy));
    
    	if ( (x0>x&&y0<=y&&adir)||(x0<=x&&y0>y&&!adir)||(x0>x&&y0>y) ) return line(x, y, x0, y0, elmId); // black magic!
    
    	var d1 = dir? x0:y0, d2 = dir? y0:x0, b1 = dir? sx:sy, b2 = dir? sy:sx, k = b2/b1;
    
    		for( var i=0; i<=b1;i++ ){
    
    			if ( dir ) plot( d1, Math.floor(d2), elmId );
    			else plot( Math.floor(d2), d1, elmId );
    
    			d1++;d2+=k;
    		}
    	return true;
    }
    /* ... */
    function plot(x, y, elmId) {
    
    	var div = document.createElement('div');
    	div.className = 'dot' + (!!elmId? ' dot-'+elmId:'' ) ;
    	div.style.left = x + 'px';
    	div.style.top = y + 'px';
    
    	document.getElementsByTagName('BODY')[0].appendChild(div);
    }

    Опачки...

    istem, 20 Апреля 2012

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

    +99

    1. 1
    http://img.ponibooru.org/images/4e/4e688d1fa583ab735ea3974cdb855897

    bot-minurast, 20 Апреля 2012

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

    +64

    1. 1
    http://i.imgur.com/z30k3.png

    bot, 20 Апреля 2012

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

    +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
    function translit ($out='') {
    
    		$out = iconv('UTF-8', 'CP1251', $out);
    		
    		$eval = '
    		$out = strtr($out,
    			"абвгдезийклмнопрстуфхцыэАБВГДЕЗИЙКЛМНОПРСТУФХЦЫЭ№",
    			"abvgdezijklmnoprstufhcieABVGDEZIJKLMNOPRSTUFHCIE#"
    		);
    
    		$out = strtr($out, array(
    			"ё"=>"yo", "ж"=>"zh", "ч"=>"ch", "ш"=>"sh", "щ"=>"shh", "ъ"=>"``", "ь"=>"`", "ю"=>"yu", "я"=>"ya",
    			"Ё"=>"Yo", "Ж"=>"Zh", "Ч"=>"Ch", "Ш"=>"Sh", "Щ"=>"Shh", "Ъ"=>"``", "Ь"=>"`", "Ю"=>"Yu", "Я"=>"Ya"
    			));
    		';
    		$eval = iconv('UTF-8', 'CP1251', $eval);
    
    		eval ($eval);
    
    	return iconv('CP1251', 'UTF-8', $out);
    	}

    bot-minurast, 20 Апреля 2012

    Комментарии (7)
  8. Java / Говнокод #9997

    +73

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    return suffix == ' ' ? ssize : (
                    si ? ssize + suffix : (
                        suffix == ' ' ? ssize + suffix : (
                            ssize + suffix + "iB"
                        )
                    )
            );

    Ведь всего-то навсего
    if (suffix == ' ') return ssize;
    if (si) return ssize + suffix;
    return ssize + suffix + "iB";

    Doctoror, 20 Апреля 2012

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    // добавление элемента в корзину
    public function basketAdd( $id, $product ) {
    	$basket = $this->getBasket( );
    
    	if ( !isset( $basket[$id] ) )
    		$basket[$id] = array( 'id' => $product['id'], 'price' => $product['price'], 'count' => $product['count'] );
    
    	$this->setBasket( $basket );
    }

    Было обнаружено в предрелизе)
    Надо больше спать...

    psycho-coder, 20 Апреля 2012

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

    +958

    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
    public int RomeToArab (string str)
    {
    	int[] arabian = new int[13] { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };
    	strint[] rome = new string[13] { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" };
    	int n = 0;
    	int i = 0;
    	do
    	{
    		if (str.StartsWith(rome[i]))
    		{
    			n = n + arabian[i];
    			str = str.Substring(rome[i].Length, str.Length - rome[i].Length);
    		}
    		if (!str.StartsWith(rome[i])
    			i++;
    	}
    	while (i < 13);
    	return n;
    }

    aleksi, 20 Апреля 2012

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