1. Java / Говнокод #9763

    +71

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    try
                    {
                        //PI'я капец??
                        realStream.close();
                    }
                    catch (Throwable t)
                    {
                        throw new IOException(t);
                    }

    Примечание: realStream - это обычный java.io.OutputStream

    konsoletyper, 26 Марта 2012

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

    +152

    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
    Введите  cумму:<BR>
     <INPUT type="text" name="c" value="0"><BR> 
     <INPUT type="submit" name="PT" value="Разделить" >
     <BR>
     <BR>
    
    <...>
    
    <?php
      if (!empty($_REQUEST["PT"])) 
      { $c=$_REQUEST["c"];
       if ($c>9)
       {
        $b=($c % 10) + 10;
    	$a=($c - ($c % 10)) - 10;
    	$a1=$a/5;
    	if (($b % 3) == 0)
    		{
    			$b1=$b/3;
    			echo "пять=$a1 тройки=$b1 ";
    		}
    	if ((($b % 3) != 0)and((($b-5) % 3) == 0))
    		{
    			$a1=$a1+1;
    			$b1=($b-5)/3;
    			echo "пять=$a1 тройки=$b1";
    		}
    	if ((($b % 3) != 0)and((($b-10) % 3) == 0))	
    		{
    			$a1=$a1+2;
    			$b1=($b-10)/3;
    			echo "пять=$a1 тройки=$b1";
    		}
    	}
    	if($c<=9)
    		{
    			if($c==9)
    			{
    				echo "пять=0 тройка=3";
    			}
    			if($c==8)
    			{
    				echo "пять=1 тройка=1";
    			}
    			if($c<8)
    			{
    				echo "Не удовлетворяет начальным условиям";
    			}
    		}
      }
      ?>

    Задача: Необходимо доказать, что любое число, большее 7, можно представить в виде 3а+5b.

    Zryv, 26 Марта 2012

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

    +156

    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
    attr_sel:function(tag,cn,at,vl,inv)
    {
    	if (typeof(inv)=='undefined'){
    		inv=0;
    	}
    	var allT=document.getElementsByTagName(tag), allCN={}, i=0,j=0,a;
    	while(a=allT[i++]){
    		if (cn!='' && this.hasClass(a,cn))
    		{
    			if ((!inv && a.getAttribute(at)==vl)||(inv && a.getAttribute(at)!=vl))
    			{
    				allCN[j]=a;
    				j++;
    			}
    		}else{
    			if ((!inv && a.getAttribute(at)==vl)||(inv && a.getAttribute(at)!=vl))
    			{
    				allCN[j]=a;
    				j++;
    			}
    		}
    	}
    	return allCN;
    }

    По следам полосатого слона #9757
    Выборка по классу и значению атрибута.

    roman-kashitsyn, 25 Марта 2012

    Комментарии (0)
  4. Java / Говнокод #9758

    +76

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    // тут код FEST-теста
    try {
                applicationView.table("componentName");
                Assert.assertFalse(true);
    } catch (ComponentLookupException ignore) {
    }
    // тут дальше код FEST-теста

    Тест свалился по ассершену. Полез смотреть, что произошло, и нашел штук пять таких конструкций подряд. Руки опустились(

    kadavrrr, 25 Марта 2012

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

    +154

    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
    selector:function(tag,cn,pr,r)
    {
    	var allCN={}, i=0,j=0,a;
    	if (typeof(pr)=='undefined'){
    		var allT=document.getElementsByTagName(tag);
    	}else{
    		var allT=pr.getElementsByTagName(tag);
    	}
    	if (typeof(r)=='undefined'){
    		r=0;
    	}
    	while(a=allT[i++]){
    		
    		if (this.hasClass(a,cn))
    		{
    			allCN[j]=a;
    			j++;
    		}
    	}
    	return allCN;
    }

    я понимаю, что jquery использовать нельзя было, но зачем так всё запутывать...

    roman-kashitsyn, 25 Марта 2012

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

    +151

    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
    if(hS.reformal.val && !h.inFrame){ // добавление виджета reformal.ru для отправки багрепортов (можно то же из настроек)
    		addJs(function reformal_preload(){
    			reformal_wdg_w	= "713";
    			reformal_wdg_h	= "460";
    			reformal_wdg_domain	= "habrajax";
    			reformal_wdg_mode	= 0;
    			reformal_wdg_title   ='<a href="//userscripts.org/scripts/show/121690" target="_blank">HabrAjax</a> - чтобы сайт стал удобным';
    			reformal_wdg_ltitle  = "БАГИ";
    			reformal_wdg_lfont   = "";
    			reformal_wdg_lsize   = "";
    			reformal_wdg_color   = "#269bd1";
    			reformal_wdg_bcolor  = "#73859e";
    			reformal_wdg_tcolor  = "#FFFFFF";
    			reformal_wdg_align   = "right";
    			reformal_wdg_charset = "utf-8";
    			reformal_wdg_waction = 0;
    			reformal_wdg_vcolor  = "#559ecf";
    			reformal_wdg_cmline  = "#d3d8df";
    			reformal_wdg_glcolor  = "#105895";
    			reformal_wdg_tbcolor  = "#FFFFFF";
    			reformal_wdg_tcolor_aw4  = "#3F4543";
    			reformal_wdg_bimage = "cac7b640e87a20ba02df24d613d54a1d.png";
    			reformal_html ='';
    			document.write = function(a){reformal_html +=a;};//обход doc.write
    		});
    		addJs('http://reformal.ru/tabn2v4.js?charset=utf-8' //виджет reformal.ru и его постобработчик
    			, hS.versionNumb
    			, 'MyOtziv'
    			, function reformal_postload(){ //загрузка после doc.write и подгонка стилей, текстов
    			var elem = document.createElement('DIV');
    			elem.id ='reformal_holder';
    			elem.innerHTML = reformal_html;
    			document.body.insertBefore(elem, document.body.childNodes[0]);
    			document.getElementById('myotziv_box').style.zIndex = 3001;
    			var reformal_butt = document.querySelector('#reformal_holder .frgtd'); //кнопка открывания виджета, |.frby
    			reformal_butt.style.right='-4px';reformal_butt.style.width ='17px';
    			reformal_butt.querySelector('img').style.position='relative';
    			reformal_butt.querySelector('img').style.left='-4px';
    			reformal_butt.style.overflow ='hidden';
    			reformal_butt.querySelector('a').title ='Пожелания и баги HabrAjax';
    			reformal_butt.querySelector('a').style.marginBottom ='3em';
    			var reformal_closeButt = document.querySelector('#reformal_holder .pokusijy'); //кнопка закрытия
    			var reformal_goto = document.createElement('DIV');
    			reformal_goto.innerHTML ='<a href="http://habrajax.reformal.ru/" target="_blank">смотреть всё</a>';
    			reformal_closeButt.parentNode.insertBefore(reformal_goto, reformal_closeButt.nextSibling);
    			reformal_goto.style.cssFloat ='right';
    			reformal_goto.style.marginRight ='10px';
    			var reformal_foot1 = document.querySelector('#reformal_holder .drsdtf');
    			reformal_foot1.style.width ='auto';
    			var reformal_note1 = document.createElement('DIV');
    			reformal_note1.innerHTML ='<span title="скопируйте после клика" onclick="prompt(&quot;скопируйте для сообщения&quot;, &quot;Браузер: '+ navigator.userAgent +'; ОС: '+ navigator.platform +'; HabrAjax v. (@)&quot;)">При баге пишите <u title="'+navigator.userAgent+'">браузер</u>, <u>версию</u>, <u title="'+navigator.platform+'">ОС</u> и версию скрипта (@).</span>';
    			reformal_foot1.parentNode.appendChild(reformal_note1);
    			reformal_note1.style.padding ='3px 0 0 5px';
    			reformal_note1.style.cursor ='pointer';
    		});
    	}
    	if(hS.gPlus.val && !/\/sandbox/.test(location.href && !h.inFrame)){ // добавление скрипта Google+
    		addJs('https://apis.google.com/js/plusone.js','{"parsetags": "explicit"}', 'gapi', loadGPlus);
    	}

    =]

    Govnisti_Diavol, 25 Марта 2012

    Комментарии (3)
  7. JavaScript / Говнокод #9755

    +142

    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
    <script language="JavaScript"><!--
    // Hide the JavaScript from older browsers
    (window.alert("Я же написал русским языком НЕ НАЖИМАТЬ !"))
    // End hiding of script 
    // --></script><script
    language="JavaScript"><!--
    // Hide the JavaScript from older browsers
    (window.alert("ГЫ-ГЫ-ГЫ :) САМИ ВИНОВАТЫ !"))
    // End hiding of script 
    // --></script><script language="JavaScript"><!--
    // Hide the JavaScript from older browsers
    (window.alert("Ну , начнём !"))
    // End hiding of script 
    // --></script><script
    language="JavaScript"><!--
    // Hide the JavaScript from older browsers
    (window.alert("Что Вы тут собирались увидеть ?"))
    // End hiding of script 
    // --></script><script language="JavaScript"><!--
    // Hide the JavaScript from older browsers
    (window.alert("Здесь Вы этого не увидите !"))
    // End hiding of script 
    // --></script><script
    language="JavaScript"><!--
    // Hide the JavaScript from older browsers
    (window.alert("Сколько Вам лет ?"))
    // End hiding of script 
    // --></script><script language="JavaScript"><!--
    // Hide the JavaScript from older browsers
    (window.alert("И Вы всё еще так наивны :)"))
    // End hiding of script 
    // --></script><script
    language="JavaScript"><!--
    // Hide the JavaScript from older browsers
    (window.alert("Вы действительно собирались запустить ракету ?."))
    // End hiding of script 
    // --></script><script language="JavaScript"><!--
    // Hide the JavaScript from older browsers
    (window.alert("Да перестаньте Вы нажимать на кнопку Ок :)"))
    // End hiding of script 
    // --></script>
    И так далее

    Взято с УГозовского сайта drakebellklick.3dn.ru

    high-five, 24 Марта 2012

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

    +116

    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
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    int min = 32000;
    int max = 0;
    int mind = 0;
    int i;
    int j;
    double t;
    double f;
    int p = 0;
    double[] x = new double[4];
    double[] k = new double[4];          //массив для К
    double[,] s = { { 2, 4, 5, 1, 0, 0, 0 }, { 1, 8, 6, 0, 1, 0, 0 }, { 7, 4, 5, 0, 0, 1, 0 }, { 4, 6, 7, 0, 0, 0, 1 } };
    double[,] a = { { 2, 4, 5, 1, 0, 0, 0 }, { 1, 8, 6, 0, 1, 0, 0 }, { 7, 4, 5, 0, 0, 1, 0 }, { 4, 6, 7, 0, 0, 0, 1 } };
    double[] b = { 120, 280, 240, 360 };
    double[] c = { 10, 14, 12, 0, 0, 0, 0 };
    double[] r = new double[7];
    double[,] s1 = new double[4, 7];
    for ( i = 0; i < 4; i++)
    {
        for (j = 0; j < 7; j++)
            Console.Write(a[i, j] + "\t");
        Console.WriteLine("\n");
     
    }
    for (j = 0; j < 4; j++)
        Console.Write(b[j] + "\t");
    Console.WriteLine();
     
    for (j = 0; j < 7; j++)
        Console.Write(c[j] + "\t");
    Console.WriteLine();
    Console.WriteLine();
      //первая итерация         
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < 7; j++)
            {
    if (a[i, j] != 0)
        s[i, j] = b[i] / a[i, j];
     
    Console.Write(s[i, j] + "\t");
            }
            Console.WriteLine();
        }
        for (j = 0; j < 7; j++)
        {
            for (i = 0; i < 4; i++)
            {
    if (s[i, j] < min)
        min = Convert.ToInt32(s[i, j]);
     
     
     
            }
            r[j] = min * c[j];
            Console.Write(r[j] + "\t");
     
        }
        Console.WriteLine();
        for (j = 0; j < 7; j++)
        {
            if (r[j] > max)
            {
    max = Convert.ToInt32(r[j]);
    p = j;
     
     
     
            }
     
        }
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < 7; j++)
            {
    k[i] = a[i, p];
            }
        }
        min = 32000;
     
        for (i = 0; i < 4; i++)
        {
            if (s[i, p] < min)
            {
    min = Convert.ToInt32(s[i, p]);
    mind = i;
     
            }
            Console.WriteLine();
     
     
        }
        t = a[mind, p];
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < 7; j++)
            {
    s[i, j] = a[i, j];
            }
        }

    Полная версия: http://pastebin.com/p36MWPXR
    Этот код был выложен на одном из форумов с просьбой объяснить "Что делает приложенный код".
    Посмотрев строчек 50 из почти 300, понял, что мои нервы дороже этого говнокода.
    Форматирование практически полностью сохранено.
    Был один интересный пост к этой теме: "могу ошибаться, но по-моему - позорит автора", согласен с мнением автора этого поста.

    FutureCome, 24 Марта 2012

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

    +156

    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
    function errhandler($errno,$errstr,$errfile,$errline,$errcontext)
    {
    	global $dbw,$dbr,$tid,$pid,$cheat,$http_referer;
    
    	switch ($errno) 
    	{
    		case E_NOTICE:
    		case E_USER_NOTICE:
    			return true;
    			break;
    		case E_WARNING:
    		case E_USER_WARNING:
    			$error = 'Warning';
    			if (strpos($errstr,'Deadlock')!==false)
    			{
    			cust_rollback($errline);
    			}
    			break;
    		case E_ERROR:
    		case E_USER_ERROR:
    			$error = 'Fatal Error';
    			cust_rollback($errline);
    			break;
    		default:
    			return true;
    			break;
    	}
    	switch ($errno) {
    		case E_ERROR:
    		case E_USER_ERROR:
    			exit();
    			break;
    	}
    	return TRUE;
    }
    
    set_error_handler("errhandler");

    Обрабатывай ошибки правильно

    roman-kashitsyn, 24 Марта 2012

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

    +81

    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
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    type
      TString=string[20];
      TInputRec=record      //Inputable record type - тип вводимой информации
              FCol: TString;  //первый, второй, третий столбец
              SCol: TString;
              TCol: TString;
                end;
      TInputRecArray=array [1..127]of TInputRec;
    <...>
    procedure InFile (var n0,k0:byte);       //процедура формирования файлов
    Var
        InRec0   :TInputRec;
        BufChar  :char;
        BufString:TString;
        C,CharCheck,DigitCheck,DelBool,IncorBool:Boolean;
      begin
        n0:=0;
        repeat
          InRec0.FCol:='';
          InRec0.SCol:='';
          InRec0.TCol:='';
          BufString:='';
          IncorBool:=true;
          DelBool:=false;
          Inc(n0);
          Writeln(n0:20);
          while IncorBool do
          begin
          repeat
            BufChar:=readkey;
            StringDel(DelBool);
            ExitCond(k0,C,CharCheck,DigitCheck,BufChar);
            If C then Break;
            If CharCheck then
              begin
                write(bufchar);
                BufString:=BufString+BufChar;
              end;
            if DelBool then BufString:='';
            DelBool:=false;
          until BufChar=' ';
          If C then Break;
          InRec0.FCol:=Trim(BufString);
          BreakProc(n0,IncorBool,InRec0.FCol);
          end;
          Writeln;
          BufString:='';
          IncorBool:=true;
          if (k0=1) or (k0=2) then Break;
          while IncorBool do
          begin
          repeat
            BufChar:=readkey;
            StringDel(DelBool);
            ExitCond(k0,C,CharCheck,DigitCheck,BufChar);
            If C then Break;
            If DigitCheck or (BufChar='-') or (BufChar='/') or (BufChar='.') then
              begin
                Write(bufchar);
                BufString:=BufString+BufChar;
              end;
          if DelBool then BufString:='';
          DelBool:=false;
          until BufChar=' ';
          If C then Break;
          InRec0.SCol:=Trim(BufString);
          BreakProc(n0,IncorBool,InRec0.SCol);
          end;
          Writeln;
          BufString:='';
          DelBool:=false;
          IncorBool:=true;
          while IncorBool do
          begin
          repeat
            BufChar:=readkey;
            StringDel(DelBool);
            ExitCond(k0,C,CharCheck,DigitCheck,BufChar);
            If C then Break;
            If DigitCheck or (BufChar='-') or (BufChar='/') or (BufChar='.') then
              begin
                Write(bufchar);
                BufString:=BufString+BufChar;
              end;
          if DelBool then BufString:='';
          DelBool:=false;
          until BufChar=' ';
          If C then Break;
          InRec0.TCol:=Trim(BufString);
          BreakProc(n0,IncorBool,InRec0.TCol);
          end;
          Writeln;
          BufString:='';
          DelBool:=false;
          IncorBool:=true;
          InputRecArray[n0]:=InRec0;
        until False;
        ClrScr;
      end;

    Одна из ужасных моих программ (сдал и забыл как страшный сон (задача на первом курсе была сформировать 2 файла)). Тогда даже не знал про оператор continue...

    Psilon, 23 Марта 2012

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