1. PHP / Говнокод #7723

    +163

    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
    function getGroupName($numg) {
        global $gname;
        if (is_file('../sys/groups.php')) {
            include ('../sys/groups.php');
        }
        else {
            include ('sys/groups.php');
        }
        if ($numg==0) {
            $gname = $gr['0'];
            return $gname;
        } else if ($numg==1) {
            $gname = $gr['1'];
            return $gname;
        } else if ($numg==2) {
            $gname = $gr['2'];
            return $gname;
        } else if ($numg==3) {
            $gname = $gr['3'];
            return $gname;
        }
    }

    skad0, 31 Августа 2011

    Комментарии (10)
  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 / Говнокод #7721

    +163

    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
    <?php 
    
    function check($str) { 
    
    $str = htmlentities(trim($str), ENT_QUOTES, 'UTF-8'); 
        $str = nl2br($str); 
        $str = strtr($str, array ( 
            chr(0)=> '', 
            chr(1)=> '', 
            chr(2)=> '', 
            chr(3)=> '', 
            chr(4)=> '', 
            chr(5)=> '', 
            chr(6)=> '', 
            chr(7)=> '', 
            chr(8)=> '', 
            chr(9)=> '', 
            chr(10)=> '', 
            chr(11)=> '', 
            chr(12)=> '', 
            chr(13)=> '', 
            chr(14)=> '', 
            chr(15)=> '', 
            chr(16)=> '', 
            chr(17)=> '', 
            chr(18)=> '', 
            chr(19)=> '', 
            chr(20)=> '', 
            chr(21)=> '', 
            chr(22)=> '', 
            chr(23)=> '', 
            chr(24)=> '', 
            chr(25)=> '', 
            chr(26)=> '', 
            chr(27)=> '', 
            chr(28)=> '', 
            chr(29)=> '', 
            chr(30)=> '', 
            chr(31)=> '' 
        )); 
        $str = str_replace("\'", "&#39;", $str); 
        $str = str_replace('\\', "&#92;", $str); 
        $str = str_replace("|", "I", $str); 
        $str = str_replace("||", "I", $str); 
        $str = str_replace("/\\\$/", "&#36;", $str); 
        $str = mysql_real_escape_string($str); 
        return $str; 
    
    } 
    
    ?>

    Хакир не пройдет.

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

    Комментарии (5)
  4. 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)
  5. PHP / Говнокод #7719

    +177

    1. 1
    if($res['ban']==1 && isset($res['ban'])) {

    Так, проверим значение, а после проверим - было ли у чего проверять.

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

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

    +166

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function calc($string){
      $a = create_function("", "return (" . $string . ");" );
      return $a();
    }
    $query[3] = mysql_query("SELECT * FROM `time`");
    while ($fetch = mysql_fetch_array($query[3])) {
      $money = $fetch['money'];
      $money = $money."+0";
      echo calc($money);
    }

    Не сразу понял что за хрень. В общем это якобы суммирование всех цифр в столбце money...

    cthulhu25, 31 Августа 2011

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

    +147

    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
    /* Dimensions */
    /* Widths */
    .w10{width:10px;}
    .w20{width:20px;}
    .w25{width:25px;}
    .w50{width:50px;}
    .w75{width:75px;}
    .w100{width:100px;}
    .w125{width:125px;}
    .w150{width:150px;}
    .w175{width:175px;}
    .w200{width:200px;}
    .w210{width:210px;}
    .w225{width:225px;}
    .w250{width:250px;}
    .w260{width:260px;}
    .w270{width:270px;}
    .w275{width:275px;}
    .w300{width:300px;}
    .w325{width:325px;}
    .w350{width:350px;}
    .w375{width:375px;}
    .w400{width:400px;}
    .w450{width:450px;}
    .w500{width:500px;}
    .w525{width:525px;}
    .w550{width:550px;}
    .w600{width:600px;}
    .w625{width:625px;}
    .w650{width:650px;}
    .w800{width:800px;}
    /* Heights */
    .h15{height:15px;}
    .h20{height:20px;}
    .h25{height:25px;}
    .h50{height:50px;}
    .h75{height:75px;}
    .h100{height:100px;}
    .h125{height:125px;}
    .h150{height:150px;}
    .h175{height:175px;}
    .h200{height:200px;}
    .h225{height:225px;}
    .h250{height:250px;}
    .h275{height:275px;}
    .h300{height:300px;}
    .h325{height:325px;}
    .h350{height:350px;}
    .h375{height:375px;}
    .h400{height:400px;}
    
    /* Padding */
    .noPad{padding:0;}
    .pad2{padding:2px;}
    .pad3{padding:3px;}
    .pad5{padding:5px;}
    .pad10{padding:10px;}
    .padTB5{padding:5px 0;}
    .padTB10{padding:10px 0;}
    .padTB15{padding:15px 0;}
    .padRL5{padding:0 5px;}
    .padRL10{padding:0 10px;}
    .padRL15{padding:0 15px;}
    .padRL20{padding-left:20px; padding-right:20px;}
    
    
    /* Margin */
    .noMar{margin:0;}
    .mar2{margin:2px;}
    .mar3{margin:3px;}
    .mar5{margin:5px;}
    .mar10{margin:10px;}
    .marTB5{margin:5px 0;}
    .marTB10{margin:10px 0;}
    .marTB15{margin:15px 0;}
    .marRL5{margin:0 5px;}
    .marRL10{margin:0 10px;}
    .marRL15{margin:0 15px;}
    .marRL20{margin-right:20px; margin-left:20px;}
    
    /* Visibility */
    .off{display:none;}
    .on{display:block;}

    myspace styleshit

    Lure Of Chaos, 31 Августа 2011

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

    +171

    1. 1
    2. 2
    3. 3
    4. 4
    document.getElementById('DESCRIPTION').onkeypress = function() {
      if ((9 - this.value.length).toString().charAt(0) == '-')
        return false
    }

    maxlength в textarea

    makitka, 31 Августа 2011

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    class OnBeginRequest
    {
    	public static function run( CEvent $event )
    	{
    		Order::model()->onOrderCreate = function( Cevent $event ) {};
    	}
    }

    Cервис на yii framework. Какой сакральный смысл заложен, неизвестно. Скорее всего, какой-то невероятной крутости костыль, типа не срабатывало событие.

    mitallast, 31 Августа 2011

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

    +128

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private static void ListXmlSerialize<T>(List<T> UserList, string Obj, string FileName)
    {
          object obj = new object();
          lock (obj)
          {
               XmlSerializer UserXmlFormat = new XmlSerializer(typeof(List<T>), Obj);
               Stream UserFileStream = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.Write);
               UserXmlFormat.Serialize(UserFileStream, UserList);
               UserFileStream.Close();
         }
    }

    wpfDev, 31 Августа 2011

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