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

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

    +122

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    case m of
     1: yy=x[0]+x[1]*i;
     2: yy=x[0]+x[1]*i+x[2]*i*i;
     3: yy=x[0]+x[1]*i+x[2]*i*i+x[3]*i*i*i;
     4: yy=x[0]+x[1]*i+x[2]*i*i+x[3]*i*i*i+x[4]*i*i*i*i;
     5: yy=x[0]+x[1]*i+x[2]*i*i+x[3]*i*i*i+x[4]*i*i*i*i+x[5]*i*i*i*i*i;
     6: yy=x[0]+x[1]*i+x[2]*i*i+x[3]*i*i*i+x[4]*i*i*i*i+x[5]*i*i*i*i*i+x[6]*i*i*i*i*i*i
    end;

    Увидел у одногруппницы в лабе по численным методам (3й курс) вот такое... Интересный подход к степени)))

    darktemplar257, 10 Октября 2011

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

    +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
    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                if (this.cbDocumentComleted.Checked) WriteText("DocumentCompleted " + e.Url.ToString()); ;
    
                if (e.Url.ToString() == "about:blank") return;
                
                this.myCountCompleted++;
                
                if ((this.myCurrentBootState == BootState.FirstBoot) && (this.myCountCompleted == 2))
                {
    
                    this.myCountCompleted = 0;
    		FirstBoot();
    
                }
    
                if((this.myCurrentBootState == BootState.BootAfterChangePageSize) && (this.myCountCompleted == 2))
                {
    
                    this.myCountCompleted = 0;
                    this.myFirstAppStart = false;
                    this.timer3.Start();
    
                }
    
                if ((this.myCurrentBootState == BootState.BootAfterCapcha) && (this.myCountCompleted == 2))
                {
    
                    this.myCountCompleted = 0;
                    this.timer1.Start();
    
                }
    
                if ((this.myCurrentBootState == BootState.BootAfterNavigation) && (this.myCountCompleted == 2))
                {
    
                    this.myCountCompleted = 0;
                    this.timer2.Start();
    
                }
    
            }

    HellMaster_HaiL, 29 Сентября 2011

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

    +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
    internal sealed class FontKeeper
    {
            private static readonly FontConverter s_converter = new FontConverter();
            private static readonly Regex s_font = new Regex(@"^(?<name>\w[\s\w]+);\s*(?<size>\d+)pt\s*(?:;(?<style>.*))?$", RegexOptions.IgnoreCase);
            private static readonly Regex s_style = new Regex(@"^\s*style\s*=\s*([\w\s,]+)$", RegexOptions.IgnoreCase);
            private const int defaultSize = 14;
    
            public FontKeeper(Font font) : this(s_converter.ConvertToString(font)) { }
    
            public FontKeeper(string fontString)
            {
                Match m = s_font.Match(fontString);
                if (!m.Success)
                    throw new ArgumentException("Неверный формат строки");
    
                Name = m.Groups["name"].Value.Trim();
                int sz;
                if (!int.TryParse(m.Groups["size"].Value, out sz))
                    sz = defaultSize;
                Size = sz;
    
                //Флаги стиля
                ParseStyle(m.Groups["style"].Value);
            }
    
            private void ParseStyle(string value)
            {
                Match m = s_style.Match(value);
                if (!m.Success) return;
    
                string[] styles = m.Groups[1].Value.Split(new[] { ',' });
                foreach (var style in styles)
                {
                    try
                    {
                        Style |= (FontStyle)Enum.Parse(typeof(FontStyle), style.Trim(), true);
                    }
                    catch { }
                }
            }
    
            public string Name { get; set; }
            public int Size { get; set; }
            public FontStyle Style { get; set; }
            public float FontFactor
            {
                get { return (float)Size / defaultSize; }
                set { Size = (int)(value * defaultSize); }
            }
    
            public Font CreateFont()
            {
                return new Font(Name, Size, Style);
            }
    }

    Небольшой класс для хранения и динамического изменения шрифтов

    lomomike, 10 Июня 2011

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

    +122

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    var rl2 = _vf.AddNewRouteLine(BusStation.Instance.GetRoute(
    BusStation.Instance.FindSettlement(БарановичиcheckBox6.Content.ToString()),
    BusStation.Instance.FindSettlement(БобруйскcheckBox17.Content.ToString()))[0],
    БарановичиcheckBox6, БобруйскcheckBox17, Upd);
    canvas1.Children.Add(rl2.Line);

    dotnetdeveloper, 12 Мая 2011

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

    +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
    switch (item.Value.ModuleConfiguration.SystemModule) // у свойства SystemModule тип bool, а не bool?
    {
           case true:
           {
                CreateModuleDomain<ISystemModuleProxy>(moduleContainer);
                (moduleContainer.ModuleProxy as ISystemModuleProxy).Init(moduleContainer.ModuleConfiguration, this as ISystemCoreProvider);
                   
                 break;
           }
           case false:
           {
                CreateModuleDomain<IBusinessModuleProxy>(moduleContainer);
                (moduleContainer.ModuleProxy as IBusinessModuleProxy).Init(moduleContainer.ModuleConfiguration, this as ICoreProvider);
    
                break;
           }
           default:
                break;
    }

    Фрагмент кода официального Senior Developer. Пример абсолютно надежного кода, который умеет обрабатывать даже будущие состояния булевого типа (default: break;) Будет надежен даже, если Microsoft неожиданно расширит тип состояниями, например MayBeTrue, OfCourseFalse, DontUnderstand и т.п. :)

    anzu, 05 Мая 2011

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

    +122

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    private bool validDir(DirectoryInfo dir)
    {
    	return dir.Attributes == FileAttributes.Directory &&
    	dir.Attributes != FileAttributes.Hidden &&
    	dir.Attributes != FileAttributes.NotContentIndexed &&
    	dir.Name != "Windows";
    }

    GoodTalkBot, 04 Мая 2011

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

    +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
    static void Main(string[] args)
    {
        int count = 4096;
        int w = int.MaxValue / count;
        int h = 10;
        int argb = 0;
        Directory.CreateDirectory("test");
        for (int bj = 0; bj < count; ++bj)
        {
            Console.WriteLine("Processing bitmap #{0} of {1}...\t{2,3}%",
                              bj + 1, count, (int)(100f * ((float)(bj + 1) / (float)count)));
            using (Bitmap bmp = new Bitmap(w, h))
            {
                Console.Write("Done   0%");
                using (Graphics gr = Graphics.FromImage(bmp))
                    for (int x = 0; x < w; ++x, argb++)
                    {
                         gr.DrawLine(new Pen(Color.FromArgb(argb)), x, 0, x, h);
                         Console.Write("\b\b\b\b{0,3}%", (int)(100f * ((float)(x + 1) / (float)w)));
                    }
                    Console.Write("\nSaving bitmap...\n{0}", new string('-', 80));
                    bmp.Save(string.Format("test\\#{0}.bmp", bj + 1), ImageFormat.Bmp);
            }
        }
    }

    Если Вам нечего делать и есть лишние 80 гигов на харде...

    FMB, 24 Марта 2011

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

    +122

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    http://developers.face.com/docs/api/faces-detect/
    Обратите внимание:
    confirmed: false
    но
    value: "false"

    Душевно так, не? :)

    wvxvw, 23 Марта 2011

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

    +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
    <?php require_once "db_config.php";
     
     class db extends db_config {
     
      private $connection;
      
      function __construct(){
       $this->open_connection();
    //   echo "Соединение установлено ";
      }
      
      private function open_connection(){
       $this->connection=mysql_connect($this->DB_HOST,$this->DB_USER,$this->DB_PASS);
       if (!$this-connection){
        die("Соедитение с базой данных не установлено: ".mysql_error());
       } else {
        $db_select=mysql_select_db($this->DB_NAME);
    	if (!$db_select){
    	 die("База данных не определена: ".mysql_error());
    	}
       }
       mysql_query("set names utf8")or die("set name utf8 failed");
       mysql_query("set lc_time_names=ru_RU");
      }
      
      public function sql($query){
       $result=mysql_query($query,$this->connection);
       if (!result){
        die("Запрос не выполнен: ".mysql_error());
       }
       return $result;
      }
     }
     $db = new db();?>

    Типа сингелтон

    Vasiliy, 10 Марта 2011

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