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

    +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
    public void Parse(string sqlScript)
    {
    	batches = new List<string>();
    	State state = State.WaitingGO;
    	StartNewBatch();
    	for(position = 0; position < sqlScript.Length; position++)
    	{
    		char c = sqlScript[position];
    		if(state == State.WaitingGO)
    		{
    			PutToBuffer(c);
    			if(IsWhiteSpace(c) || IsEndOfLineCharacter(c)) continue;
    			else if(c == 'g' || c == 'G') state = State.ReadingGO;
    			else
    			{
    				state = State.ReadingBatch;
    				FlushBuffer();
    			}
    		}
    		else if(state == State.ReadingGO)
    		{
    			PutToBuffer(c);
    			if(c == 'o' || c == 'O') state = State.ReadedGO;
    			else if(IsEndOfLineCharacter(c))
    			{
    				state = State.WaitingGO;
    				FlushBuffer();
    			}
    			else
    			{
    				state = State.ReadingBatch;
    				FlushBuffer();
    			}
    		}
    		else if(state == State.ReadedGO)
    		{
    			if(IsWhiteSpace(c) || IsEndOfLineCharacter(c))
    			{
    				state = State.WaitingGO;
    				FinishBatch();
    				StartNewBatch();
    			}
    			else
    			{
    				state = State.ReadingBatch;
    				PutToBuffer(c);
    				FlushBuffer();
    			}
    		}
    		else if(state == State.ReadingBatch)
    		{
    			PutToBatch(c);
    			if(IsEndOfLineCharacter(c)) state = State.WaitingGO;
    		}
    	}
    	if(state != State.ReadedGO) FlushBuffer();
    	FinishBatch();
    }
    
    private enum State
    {
    	WaitingGO,
    	ReadingGO,
    	ReadedGO,
    	ReadingBatch
    }

    Требовалось распарсить string с sql-текстом на отдельные транзакции (т.е. просто разбить текст по go).
    Функции для работы с Batch-ем не привожу и так уйма говнокода

    FedorFo, 02 Июля 2010

    Комментарии (23)
  2. Java / Говнокод #3627

    +96

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public static Entity read(final URI path) {
    	if(!(path.items!= null && (0 < path.items.size()))){
    		assert (false);
    	}
                     //дальше сам метод

    3.14159265, 02 Июля 2010

    Комментарии (4)
  3. C++ / Говнокод #3626

    +144

    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
    #include <iostream>
    #include <string>
    #include <ctime>
    using namespace std;
    
    template <typename T>
    void SwowArray(T arr[], int n); // #A
    
    template <typename T>
    void ShowArray(T * arr[], int n); // #B
    
    struct debts
    {
    	char name[50];
    	double amount;
    };
    int main() 
    {
    	int things[6] = {12, 34, 43, 21, 56, 666};
    	struct debts mr_dick[3] =
    	{
    		{"Pizdabol Ivan", 999.0},
    		{"Xuesos Vasya", 45.0},
    		{"Prostitutka Alla", 548.0}
    	};
    
    	double * pedo[3];
    	for(int i = 0; i < 3; i++)
    	{
    		pedo[i] = &mr_dick[i].amount;
    	}
    	
    	cout << "Trololo Mr.Dick: \n";
    	ShowArray(things, 6);
    	cout << "Listening Debilov: \n";
    	ShowArray(pedo, 3);
    	cin.ignore();
    	cin.get();
    	return 0;
    }
    // #A
    
    template <typename T> void ShowArray(T arr[], int n)
    {
    	cout << "Template A \n";
    	for(int i = 0; i < n; i++)
    		cout <<arr[i]<<" ";
    	cout << endl;
    }
    
    template <typename T> void ShowArray(T * arr[], int n)
    {
    	cout << "Template B \n";
    	for(int i = 0; i<n; i++)
    		cout <<*arr[i]<< " ";
    	cout << endl;
    }

    не могу понять почему выводится ошибка, как бы не должно ее быть, компилятор указывает на 34 строку

    trololo101010, 02 Июля 2010

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function mysql_prep($value)
    {
        if(get_magic_quotes_gpc()){
            $value = stripslashes($value);
        } else {
            $value = addslashes($value);
        }
        return $value;
    }

    "Heres a hassle free function to use to check your query string and before its handed to the db. It will add/remove slashes according to the get_magic_quotes_gpc state"

    http://lt.php.net/manual/en/function.addslashes.php

    Cyanide, 02 Июля 2010

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    ini_set('session.use_cookies','0');
    ini_set('session.use_trans_sid','0');
    
    ...
    
    session_start();

    :D

    DmitryDick, 02 Июля 2010

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

    +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
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>домо окошко</title>
    <link rel="stylesheet" href="tools/style.css" type="text/css" />
    <script type="text/javascript">
    function fMask(){
    	var h = document.getElementById('bodyblock').offsetHeight;
    	document.getElementById('mask').style.height = h + "px";
    	var hmodal = document.getElementById('modalBlock').offsetHeight -6;
    	document.getElementById('modalLeft').style.height = hmodal + "px";
    	document.getElementById('modalRight').style.height = hmodal + "px";
    }
    </script>
    <script type="text/javascript" src="tools/jquery.js"></script>
    <script type="text/javascript" src="tools/select.js"></script>
    <script type="text/javascript">$(document).ready(function(){$('.selectBlock').sSelect();});</script>
    </head>
    <body id="bodyblock" onload="fMask();">
    <div id="mask"></div>
    
    <div id="modal">

    лалала жужужужу я програмлю как могу... из серии не заставляйте верстальщиков применять JS

    nur, 02 Июля 2010

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

    +164

    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
    <?
    
    class с_self_add_form
    {
    var $main="<P>
    <form name=\"add_form\" ENCTYPE=\"multipart/form-data\" method=post
    ....HTML...
    </table></form></P>";
    }
    
    class u_self_add_form
    {
    var $main="<P class=ttext>
    <form name=\"add_form\" ENCTYPE=\"multipart/form-data\" method=post
    ....Другой HTML...
    </table></form></P>";
    }
    
    class d_self_add_form
    {
    var $main="<P class=zag>
    <form name=\"add_form\" ENCTYPE=\"multipart/form-data\" method=post
    ....Третий HTML...
    </table></form></P>";
    }
    
    /* и так далее, и тому подобное */

    самый шикарный формат файла с шаблонами, который я видел.

    Mihard, 02 Июля 2010

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

    +102

    1. 1
    2. 2
    3. 3
    long First = 2* ... ;
    long Second = 2* ... ;
    long Average = (First + Second) / 2

    1.як не треба рахувати середнє арифметичне.
    2.БАЯН.

    O_O, 02 Июля 2010

    Комментарии (16)
  9. Си / Говнокод #3620

    +111

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    double f_x (double x, double y, int nom)
    {
      double f_x[]={x+y, x*y, x*y, sqrt(x*x + y*y), cos(x)/sin(y)};
      return f_x[nom];
    }

    Нужна одна из функций :-)

    Goga, 01 Июля 2010

    Комментарии (26)
  10. PHP / Говнокод #3619

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    for ($i = 0; $i < $count; $i++) {
     if ($links_array['is'][$i]) {
      $link_text .= '[url='.$links_array['href'][$i].']'.$links_array['new_name'][$i].'c ('.link_domain($links_array['href'][$i]).')[/url]';
      if ($links_array['mirror'][$i] != '') {
       $link_text .= "\n".'[url='.$links_array['mirror'][$i].']'.$links_array['new_name'][$i].'c ('.link_domain($links_array['mirror'][$i]).')[/url]'
      }
      $link_text .= ($i + 1 != $count ? "\n" : '');
     }
    }

    dmOx, 01 Июля 2010

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