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

    +111

    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
    public const string Message = "messagebox";
                public const string Message_Error = "messagebox.error";
                public const string Message_Question = "messagebox.question";
    
            public void ProcessUrl(string url, object urlContext, EventHandler<ProcessUrlArgs> callback)
            {
                switch (url)
                {
                    case Url.Message:
                        urlArgs.Result = XtraMessageBox.Show((string) urlContext, captionText, MessageBoxButtons.OK,
                                                             MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                        callback(this, urlArgs);
                        return;
                    case Url.Message_Error:
                        urlArgs.Result = XtraMessageBox.Show((string) urlContext, captionText, MessageBoxButtons.OK,
                                                             MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                        callback(this, urlArgs);
                        return;
                    case Url.Message_Question:
                        urlArgs.Result = XtraMessageBox.Show((string) urlContext, captionText, MessageBoxButtons.OKCancel,
                                                             MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                        callback(this, urlArgs);
                        return;
                }
     
         // дальше идет уже ручная разборка Url

    Человек изобрел своего диспетчера контролов внутри формы. Вместо специфических методов вызывающий формирует строку вида
    "command.subcommand.parameter1.parameter 2", передается диспетчеру а он уже парсит это обратно.
    К примеру "prefix.persons.view.23.all" означает что нужно создать юзер контрол PersonDetail для персоны с id 23 и показать все опции. Но можно передать и "message" тогда покажется messagebox. Все это происходит внутри одного UI модуля, и все классы internal. более того, этих usercontrols всего 4 разных и все это говно можно заменить на 4 метода с парой параметров в каждом. Но там было бы слишком просто и легко отслеживать что откуда вызывается. А в случае единственного метода ProcessUrl (который не url :) ) все гораздо веселее.

    eval_2009, 30 Марта 2011

    Комментарии (5)
  2. C# / Говнокод #6125

    +115

    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
    columnDomain.Visible =
     (grid.MainView.RowCount >
    0
    &&
     !String.IsNullOrEmpty(
         ((ListItem)
      grid.MainView.
         GetRow(0)).Domain)
    &&
      ((ListItem)
     grid.MainView.GetRow(0))
          .Domain !=
     ((ListItem)
     grid.MainView.GetRow(0))
         .DisplayName);

    Это реальное форматирование кода, очевидно сделанное для удобства чтения на узком и высокои мониторе :) И такого многие и многие экраны

    eval_2009, 29 Марта 2011

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

    +136

    1. 1
    particleEmitter.particleEmitter.particleEmitter.particleEmitter.particleEmitter.particleEmitter.particleEmitter.particleEmitter.particleEmitter.emit = Mathf.Sin(Random.value*Mathf.PI*2) <= 1;

    Строчка из кода в Unity3D.

    semens, 28 Марта 2011

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

    +134

    1. 1
    string relativedir = Directory.GetParent(Directory.GetParent(Directory.GetParent(Directory.GetCurrentDirectory()).ToString()).ToString()).ToString()+@"\Webapplication2\App_Data\";

    ссылка на базу данных в другой папке

    oldnavy1989, 27 Марта 2011

    Комментарии (57)
  5. C# / Говнокод #6099

    +117

    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Caeser_method
    {
        class Program
        {
            static void Main(string[] args)
            {
                int n = 3;
                Console.Write("Input string to encoding: ");
                string input = Console.ReadLine();
                Csr enc = new Csr(n,input);
               // Csr dec;
                enc.encrypt();
                Console.WriteLine(enc);
               // dec = new Csr(n, input);
                enc.decrypt();
                
                Console.WriteLine(enc);
                Console.ReadLine();
            }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Caeser_method
    {
        class Csr
        {
            public int n;
            public string phraze,outputphr;
            public Csr(int n, string phraze) 
            {
                this.n = n;
                this.phraze = phraze;
                this.outputphr = "";
            }
    
            
            public void encrypt() 
            {
                foreach (char c in this.phraze)
                    if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
                    {
                        if (char.IsLetter(c)) this.outputphr += (char)(char.IsUpper(c) ?
                                                                          (c + this.n > 'Z' ? ('A' + ((c -'Z'  + (this.n - 1)))) : (c + this.n)) :
                                                                          (c + this.n > 'z' ? ('a' + ((c - 'z' + (this.n - 1)))) : (c + this.n)));
                        else this.outputphr += c;
                    }
                    else
                    {
                        if (char.IsLetter(c)) this.outputphr += (char)(char.IsUpper(c) ?
                                                                          (c + this.n > 'Я' ? ('А' + ((c - 'Я' + (this.n - 1)))) : (c + this.n)) :
                                                                          (c + this.n > 'я' ? ('а' + ((c - 'я' + (this.n - 1)))) : (c + this.n)));
                        else this.outputphr += c;
                    }
            }
    
    
            public void decrypt()
            {
                this.phraze = this.outputphr;
                this.outputphr = "";
                foreach (char c in this.phraze)
                    if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
                    {
                        if (char.IsLetter(c)) this.outputphr += (char)(char.IsUpper(c) ?
                                                                          (c - this.n < 'A' ? ('Z' - (('A' - c + (this.n - 1)))) : (c - this.n)) :
                                                                          (c - this.n < 'a' ? ('z' - (('a' - c + (this.n - 1)))) : (c - this.n)));
                        else this.outputphr += c;
                    }
                    else
                    {
                        if (char.IsLetter(c)) this.outputphr += (char)(char.IsUpper(c) ?
                                                                          (c - this.n < 'А' ? ('Я' - (('А' - c + (this.n - 1)))) : (c - this.n)) :
                                                                          (c - this.n < 'а' ? ('я' - (('а' - c + (this.n - 1)))) : (c - this.n)));
                        else this.outputphr += c;
                    }
            }
    
            public override string ToString()
            {
                return string.Format("Encoded string: {0}",this.outputphr);
            }
    
        }
    }

    Реализация шифрования методом Цезаря

    rybaki, 27 Марта 2011

    Комментарии (14)
  6. 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)
  7. C# / Говнокод #6066

    +134

    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
    /// <summary>
            /// попытка парсинга потока в bool {true,false,1,0} поддерживатеся любой регистр 
            /// </summary>
            /// <param name="lpwcstr">указатель текущую позицию потока</param>
            /// <param name="result">результат</param>
            /// <returns>см. ParseSucces</returns>
            static public ParseSuccess TryParse(ref char* lpwcstr, out bool result)
            {
                char* cur = lpwcstr;
            to_begin:
                switch (*cur++)
                {
                    case ' ':
                    case '\t':
                    case '\n':
                    case '\r':goto to_begin;
                    case '0': lpwcstr = cur; goto to_fail;
                    case '1': lpwcstr = cur; result = true; return ParseSuccess.Success;
                    case 't':
                    case 'T':
                        switch (*cur++)
                        {
                            case 'r':
                            case 'R': switch (*cur++)
                                {
                                    case 'u':
                                    case 'U': switch (*cur++)
                                        {
                                            case 'e':
                                            case 'E': lpwcstr = cur; result = true; return ParseSuccess.Success;
                                            default: result = false; return (ParseSuccess)(lpwcstr - cur + 1);
                                        }
                                    default: goto to_fail;
                                }
                            default: goto to_fail;
                        }
                    case 'f':
                    case 'F': switch (*cur++)
                        {
                            case 'a':
                            case 'A': switch (*cur++)
                                {
                                    case 'l':
                                    case 'L': switch (*cur++)
                                        {
                                            case 's':
                                            case 'S': switch (*cur++)
                                                {
                                                    case 'e':
                                                    case 'E': lpwcstr = cur; result = false; return ParseSuccess.Success;
                                                    default: goto to_fail;
                                                }
                                            default: goto to_fail;
                                        }
                                    default: goto to_fail;
                                }
                            default: goto to_fail;
                        }
                    default: goto to_fail;
                }
            to_fail:
                result = false; 
                return (ParseSuccess)(lpwcstr - cur + 1);
            }

    FMB, 23 Марта 2011

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

    +134

    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
    using System;
    namespace ConsoleApplication_Square
    {
        class Program
        {
            static void Main()
            {
                var n = Console.ReadLine();
                if (n.Length >= 5)
                {
                    var t = false;
                    for (var i = 0; i < n.Length-4; i++)
                    {
                        if(n[i]=='h')
                        {
                            for (var j = i + 1; j < n.Length-3; j++)
                            {
                                if(n[j]=='e')
                                {
                                    for (var l = j + 1; l < n.Length-2; l++)
                                    {
                                        if(n[l]=='l')
                                        {
                                            for (var m = l + 1; m < n.Length-1; m++)
                                            {
                                                if (n[m]=='l')
                                                {
                                                    for (var o = m + 1; o < n.Length; o++)
                                                    {
                                                        if (n[o]=='o')
                                                        {
                                                            t = true;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }  
                                }
                            }
                        }
                    }
                    Console.Write(t?"YES":"NO");
                }
                else
                {
                    Console.Write("NO");
                }
            }
        }
    }

    Нашел в качестве решения задачи на CodeForces.ru

    http://codeforces.ru/problemset/problem/58/A

    Moldabekov, 21 Марта 2011

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

    +125

    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
    public void BindBanners()
            {
                StringBuilder obj1 = new StringBuilder();
                
                obj1.Append("<div class='contentdiv'>");
                obj1.Append("<div class='showHideDivContent' style='width:275px;'>");
                obj1.Append(" </div>");
                obj1.Append("<img src='"+ Page.ResolveUrl("portals/_default/Skins/Life2Good/Images/tabSlide1.jpg") +"' alt='' usemap='#MaptabSlide1' />");
                obj1.Append("</div>");
             
             ........... 
    
                string[] objArray = new string[10];
                objArray[0] = obj1.ToString();
                objArray[1] = obj2.ToString();
                objArray[2] = obj3.ToString();
                objArray[3] = obj4.ToString();
                objArray[4] = obj5.ToString();
                objArray[5] = obj6.ToString();
                objArray[6] = obj7.ToString();
                objArray[7] = obj8.ToString();
                objArray[8] = obj9.ToString();
                objArray[9] = obj10.ToString();
                objArray[10] = obj11.ToString();
                //objArray[11] = obj12.ToString();
                //objArray[12] = obj13.ToString();
                //objArray[13] = obj14.ToString();
                //objArray[14] = obj15.ToString();
                SetBanners(objArray);
                //Response.Write(LitContentdiv1.Text + LitContentdiv2.Text + LitContentdiv3.Text + LitContentdiv4.Text + LitContentdiv5.Text);
            }
    
    public void SetBanners(string[] objArray)
            {
                OLOLOProj.Modules.ManageHomePageBanners.ManageHomePageBannersController  objBannerController = new OLOLOProj.Modules.ManageHomePageBanners.ManageHomePageBannersController();
                List<OLOLOProj.Modules.ManageHomePageBanners.ManageHomePageBannersInfo> objBannerInfo = objBannerController.GetActiveHomeBanners();
                for (int i = 0; i < objBannerInfo.Count; i++)
                {
                    if (i == 0)
                    {
                        LitContentdiv1.Text = objArray[objBannerInfo[i].ItemId - 1];
                    }
                    if (i == 1)
                    {
                        LitContentdiv2.Text = objArray[objBannerInfo[i].ItemId - 1];
                    }
    
                    if (i == 2)
                    {
                        LitContentdiv3.Text = objArray[objBannerInfo[i].ItemId - 1];
                    }
    
                    if (i == 3)
                    {
                        LitContentdiv4.Text = objArray[objBannerInfo[i].ItemId - 1];
    
                    }
                    if (i == 4)
                    {
                        LitContentdiv5.Text = objArray[objBannerInfo[i].ItemId - 1];
                    }
                    if (i == 5)
                    {
                        LitContentdiv6.Text = objArray[objBannerInfo[i].ItemId - 1];
                    }
                    if (i == 6)
                    {
                        LitContentdiv7.Text = objArray[objBannerInfo[i].ItemId - 1];
                    }
                    if (i == 7)
                    {
                        LitContentdiv8.Text = objArray[objBannerInfo[i].ItemId - 1];
                    }
    
                    //Mukesh
                    if (i == 8)
                    {
                        LitContentdiv9.Text = objArray[objBannerInfo[i].ItemId - 1];
                    }
    
                    if (i == 9)
                    {
                        LitContentdiv10.Text = objArray[objBannerInfo[i].ItemId - 1];
                    }
    
                    if (i == 10)
                    {
                        LitContentdiv11.Text = objArray[objBannerInfo[i].ItemId - 1];
                    }
    
                }
                }

    поддержка одного интернет магазина. мне нужно добавить еще один баннер на сайт, а там такое....

    DJm00n, 21 Марта 2011

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

    +107

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    static void Main(string[] args)
            {
                int a = int.Parse(Console.ReadLine());
                int b = int.Parse(Console.ReadLine());
                int c = int.Parse(Console.ReadLine());
                Math.Cos(double x) = (b * b + c * c - a * a) / (2 * b * c);
                Math.Cos(double x)=i;
                if(-1>i>0) Console.WriteLine("Треугольник тупоугольный");
                if()
            }

    Не столько смешно, сколько хочется плакать от тупоугольности таких вот студентов...

    FMB, 20 Марта 2011

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