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

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

    +122

    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
    public class ASyncFileHashAlgorithm
    	{
    		protected HashAlgorithm hashAlgorithm;
    		protected byte[] hash;
    		protected bool cancel = false;
    		protected int bufferSize = 4096;
    		public delegate void FileHashingProgressHandler (object sender, FileHashingProgressArgs e);
    		public event FileHashingProgressHandler FileHashingProgress;
    
    		public ASyncFileHashAlgorithm(HashAlgorithm hashAlgorithm)
    		{
    			this.hashAlgorithm = hashAlgorithm;
    		}
    
    		public byte[] ComputeHash(Stream stream)
    		{
    			cancel = false;
    			hash = null;
    			int _bufferSize = bufferSize; // this makes it impossible to change the buffer size while computing
    
    			byte[] readAheadBuffer, buffer;
    			int readAheadBytesRead, bytesRead;
    			long size, totalBytesRead = 0;
    
    			size = stream.Length;
             	readAheadBuffer = new byte[_bufferSize];
                readAheadBytesRead = stream.Read(readAheadBuffer, 0, readAheadBuffer.Length);
    
                totalBytesRead += readAheadBytesRead;    
    
                do
                {
                    bytesRead = readAheadBytesRead;
                    buffer = readAheadBuffer;    
    
                    readAheadBuffer = new byte[_bufferSize];
                    readAheadBytesRead = stream.Read(readAheadBuffer, 0, readAheadBuffer.Length);
    
                    totalBytesRead += readAheadBytesRead;    
    
                    if (readAheadBytesRead == 0)
                        hashAlgorithm.TransformFinalBlock(buffer, 0, bytesRead);
                    else
                        hashAlgorithm.TransformBlock(buffer, 0, bytesRead, buffer, 0);
    
    				FileHashingProgress(this, new FileHashingProgressArgs(totalBytesRead, size));
                } while (readAheadBytesRead != 0 && !cancel);
    
    			if(cancel)
    				return hash = null;
    
        		return hash = hashAlgorithm.Hash;
    		}
    
    		public int BufferSize
    		{
    			get
    			{ return bufferSize; }
    			set
    			{ bufferSize = value; }
    		}
    
    		public byte[] Hash
    		{
    			get
    			{ return hash; }
    		}
    
    		public void Cancel()
    		{
    			cancel = true;
    		}
    
    		public override string ToString ()
    		{
    			string hex = "";
    			foreach(byte b in Hash)
    				hex += b.ToString("x2");
    
    			return hex;
    		}
    	}

    Очень интересная реализация "асинхронного" хэширования.

    martin, 31 Августа 2011

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

    +163

    1. 1
    $style = (preg_match('#linux|windows|Yahoo|Rambler|Yandex|Google|bsd|bsd|unix|macos|macintosh#i', $_SERVER['HTTP_USER_AGENT'])) ? 'web' : 'wap';

    Вот так нужно определять, что же отдать клиенту - веб- или вап-версию.

    7ion, 31 Августа 2011

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

    +153

    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
    // ...
    if (m_parent->GetState() == Disconnected)
    {
    	CString login;
    	CString password;
    	m_login.GetWindowText(login);
    	m_password.GetWindowText(password);
    
    	if (login.IsEmpty()
    		|| password.IsEmpty())
    	{
    		::MessageBox(this->m_hWnd, _T("Please enter login and password"), _T("Input error"),MB_OK);
    		return;
    	}
    		
    	if (CheckString(login)
    		|| CheckString(password))
    	{
    		::MessageBox(this->m_hWnd, _T("You have entered unsupported symbol."), _T("Input error"), MB_OK);
    		m_login.SetWindowText(login);
    		m_password.SetWindowText(password);
    		
    		return;
    	}
    
    	SaveConfig();
    }
    
    // ...
    
    
    bool CheckString(CString& string)
    {
    	bool res = false;
    	CString checked = _T("<>,!()[]{}~`#$%^&*+=/\\\"|;:'");
    	for (int i = 0; i < checked.GetLength(); ++i)
    	{
    		if (string.Find(checked[i]) != -1)
    		{
    			res = true;
    			string = _T("");
    			break;
    		}
    	}
    
    	return res;
    }

    Проверка допустимых символов

    kandul, 31 Августа 2011

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

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    function getCountComment($ent_id = null)
    {
        if(empty($ent_id))
        {
            return false;
        }
    ...
    }

    123qweasdzxc, 30 Августа 2011

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

    +158

    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
    $email = $_POST['email'];
    $pass = $_POST['pass'];
    $name = $_POST['name'];
    $famname = $_POST['famname'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $date = date('Y-m-d [H:i:s]');
    
    if($_GET['reg'] == 'good' && $email!="" && $name!="" && $famname!="" && $pass!="" ) {
         if(!@mysql_connect('localhost', 'root', '')) {
              echo 'ѥ䩱򰠶鿠㱥񻑭塤ﲲ󯭠';
              exit();
         }
         mysql_select_db('efimov');
         $number = 0;
         $query = "select count(uid) as c from users";
         $res = mysql_query($query);
         while($row = mysql_fetch_array($res)) {
              $number = $row['c'] + 1;
         }	
         if(mysql_query("insert into users values ('$number', '$name','$famname','$email','$pass','$ip','$date')")) { 
              echo "$name, hello"; 
         }
    }
    echo '<script type="text/javascript">'.
    'alert("fuuu")'.
    '</script>';

    Регистрация пользователя ;)

    substr, 30 Августа 2011

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

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    int main(int argc, char* argv[])
    {
      std::cout<<"Good testing!\n";
      system("PAUSE"); 
      return 0;
    }

    http://www.gamedev.ru/code/forum/?id=151702

    Привет!
    Есть окно на DX9, как вывести текст?
    Делаю так:
    Создал файл txt.cpp.
    В итоге выводит только окно.
    Как вывести текст в DirectX 3D или можно по-другому?

    CPPGovno, 28 Августа 2011

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

    −88

    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
    #-----------view:
    
    
    def catalog(request):
    	subcatalog_list = SubCatalog.objects.all().order_by('index')
    	objects_list = Object.objects.all().order_by('subcatalog')
    	t = loader.get_template('catalog.html')
    	c = RequestContext(request, {
        	'subcatalog_list': subcatalog_list,
        	'objects_list': objects_list,
        })
    	return HttpResponse(t.render(c))
    
    
    #-----------template:
    		{% if subcatalog_list %}
        		{% for subcatalog in subcatalog_list %}
        			<div class="section_name clear">{{ subcatalog.name }}</div>
    				<div class="clear"></div>
    				{% if objects_list %}
        				{% for obj in objects_list %}
        					{% if obj.subcatalog.id == subcatalog.id %}
    						<div class="section">
    							<a class="clear" href="{{ obj.link }}/">{{ obj.name }}</a>
    							{% if obj.description %}
    							<div class="description">{{ obj.description|safe }}</div>
    							{% endif %}
    						{% if forloop.counter0|divisibleby:3 %} 
    						{% endif %}
    	    				{% endif %}
        				{% endfor %}
    				{% else %} 
        				<h2>No objects available.</h2>
        			{% endif %}
        		{% endfor %}
        	{% else %}
        		<h1>No subcatalogs available.</h1>
        	{% endif %}
    
    
    #-------И еще печенька напоследок:
    <a onclick="window.location = '/create/' + {{ subcatalog.id }} + '/'"></a>

    Django

    дико, дико.

    alexeypav, 28 Августа 2011

    Комментарии (7)
  9. Ruby / Говнокод #7659

    −95

    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
    loop do
      client = server.accept
      otvet = []
    
      while line = client.gets
        otvet << line
         break if line == "\r\n"
      end
    
      client.print "HTTP/1.1 200/OK\n"
      client.print "Content-type: text/html\n\n"
      client.print '"<meta http-equiv="refresh" content="0; url=http://www.google.ru">"' # переадресация
      client.close
      puts otvet
      File.open('log.txt', 'a'){ |f| f.puts("#{otvet}")} # запись лога
    end

    творние юного кулхацкера

    wapoo!11, 26 Августа 2011

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

    +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
    33. 33
    34. 34
    35. 35
    <?php
    
    header('content-type: application/x-javascript; charset=windows-1251');
    
    function utf8win1251($s){
      $out=""; $c1=""; $byte2=false;
      for ($c=0;$c<strlen($s);$c++){
        $i=ord($s[$c]); if ($i<=127) $out.=$s[$c];
        if ($byte2) { $new_c2=($c1&3)*64+($i&63); $new_c1=($c1>>2)&5;
          $new_i=$new_c1*256+$new_c2;
          if ($new_i==1025) $out_i=168; else
          if ($new_i==1105) $out_i=184; else $out_i=$new_i-848;
          $out.=chr($out_i); $byte2=false; }
        if (($i>>5)==6) {$c1=$i;$byte2=true; } }
     return $out; }
    
     
    $src = file_get_contents("http://letopisi.ru/index.php/%D0%A8%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD:%D0%97%D0%BD%D0%B0%D0%B5%D1%82%D0%B5_%D0%BB%D0%B8_%D0%B2%D1%8B");
    
     $tmp = preg_replace('/.*<ul><li>(.*)<\/ul>.*<div class="printfooter">.*/s', '$1', $src);
     $tmp = trim(preg_replace('/href="/', 'href="http://letopisi.ru', $tmp));
     $matches = explode('</li>', $tmp);
    
     if (sizeof($matches) > 1) {
       $trans = Array("\x0D" => "", "\x0A" => " ");
       do { 
         $quote = trim($matches[rand(0, sizeof($matches)-2)]); 
       } while (empty($quote));
       $quote = str_replace('<li>', '', utf8win1251(strtr($quote, $trans)));
       $quote = preg_replace('/<div class="thumb.*<\/div>/', '', $quote);
       $quote = str_replace('"', '\"', $quote);
       print 'document.write("' . $quote . '");';
     }
    
     ?>

    Аа, блин, надо было сразу все кидать.
    Нужна возможность удалять свои коды в течение 10 минут.

    7ion, 25 Августа 2011

    Комментарии (7)
  11. Pascal / Говнокод #7647

    +100

    1. 1
    2. 2
    3. 3
    4. 4
    case
       0: FilterList.Add('RCHECK = '+''''+'+'+'''');
       1: FilterList.Add('RCHECK = '+''''+'-'+'''');
    ...

    Автор кода жжот. Код реально работает. Но прочитать такое даже автор по прошествии года не сможет.

    Можно было проще
    0:FilterList.Add('RCHECK = ''+''');

    siqel, 25 Августа 2011

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