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

    +135

    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
    public static List<string[]> Compose(List<string> list_eng, List<string> list_tar, string divider = ";")
            {
                List<string[]> composed = new List<string[]>();
                for (int i = 0; i < list_eng.Count - 1; i++)
                {
                    string[] tokens = new string[3];
                    string[] temp = list_eng[i].Split(new string[] { divider }, StringSplitOptions.None);
    
                    if (temp.Length != 2)
                    {
                        Console.WriteLine("1." + i + " : expected 2 tokens, found " + temp.Length);
                        continue;
                    }
    
                    tokens[0] = temp[0];
                    tokens[1] = temp[1];
    
                    composed.Add(tokens);
                }
    
                for (int i = 0; i < list_tar.Count - 1; i++)
                {
                    string[] tokens = list_tar[i].Split(new string[] { divider }, StringSplitOptions.None);
    
                    if (tokens.Length != 2)
                    {
                        Console.WriteLine("2." + i + " : expected 2 tokens, found " + tokens.Length);
                        continue;
                    }
    
                    int eq = composed.FindIndex(a => a[0] == tokens[0]);
    
                    if (eq == -1)
                        continue;
                    else
                        composed[eq][2] = tokens[1];
                }
                return composed;
            }

    Парсит csv в колонки.

    chebyrashka, 01 Июля 2014

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

    +134

    1. 1
    IEventDetails evt = logger.GetEvent((Int32)((Object[])msg.ID)[0], (Int64)((Object[])msg.ID)[1]);

    Нашёл свой код бородатой давности в одном решении, в котором присутсвует дедлок, а лезть в код не хотелось.
    Вот теперь думаю, ковырять компонент дальше или пусть себе с дедлоком живёт.....

    TauSigma, 01 Июля 2014

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

    +130

    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
    class ProducerConsumer
        {
            private static Semaphore semaphore = new Semaphore(1, 2);
            static object locker = new object();
            static int product = 0;
            private static bool work = true;
            private static bool valueSet = false; // why??
    
            private static void Producer() // производитель
            {
                while (work)
                {
                    Console.WriteLine("Thread Producer start");
                    int sqr = 0;
                    semaphore.WaitOne(); // декрементируем счётчик семафора
                    for (int i = 0; i < 15; i++)
                    {
                        sqr = i * i;
                    }
                    lock (locker) // error
                    {
    
                        while (valueSet)
                        {
                            Thread.Yield();
                        }
                        product += sqr;
                        valueSet = true;
                        Console.WriteLine("Product put: " + sqr);
                        Console.WriteLine("Product now: " + product);
                    }
                    semaphore.Release(); // выход из семафора
                    Thread.Sleep(5000);
                }
            }
    
            private static void Consumer() // потребитель
            {
                const int MAX = 5;
                int[] arr = new int[MAX];
                int result = 0;
                Random rand = new Random();
    
                while (work)
                {
                    Console.WriteLine("Thread Consumer start");
                    semaphore.WaitOne(); 
                    for (int i = 0; i < 5; i++)
                    {
                        arr[i] = rand.Next(0, 1024);
                    }
                    for (int i = 0; i < 5; i++)
                    {
                        result += arr[i];
                    }
                    result /= 5;
                    while (!valueSet)
                    {
                        Thread.Yield();
                    }
                    lock (locker)
                    {
                        if (product - result > 0) // исключаем отриц.кол-ва продуктов
                        {
                            product -= result;
                            Console.WriteLine("Product get: " + result);
                        }
                        else 
                        {
                            Console.WriteLine("Product < 0");
                        }
                        valueSet = false;
                        Console.WriteLine("Product now: " + product);
                    }
                    semaphore.Release();
                    Thread.Sleep(5000);
                }
            }
    
            public static void Main()
            {
                Thread threadProducer = new Thread(Producer);
                threadProducer.Start();
    
                Thread threadConsumer = new Thread(Consumer);
                threadConsumer.Start();
    
                Thread.Sleep(5000);
    
                Console.WriteLine("Main thread start.");
                String str = System.Console.ReadLine();
                Console.ReadKey();
            } 
    }

    Корявый пример решения задачи "Producer-Consumer".

    qstd, 29 Июня 2014

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

    +143

    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
    using System;
    using System.Text;
    public class Test
    {
    	public static void Main()
    	{
    		object obj = "Suck my balls";
    		string str1 = "Suck my balls";
    		string str2 = new StringBuilder().Append("Suck my ").Append("balls").ToString();
    		Console.WriteLine(obj==str1);//True
    		Console.WriteLine(str2==str1);//True
    		Console.WriteLine(obj==str2);//False
    	}
    }

    Нетранзитивный дотнет или головоломка на ночь

    kegdan, 27 Июня 2014

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

    +133

    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
    public class OctetString 
    {
            private byte[] m_bDataArray = null;
    
            public OctetString(byte[] data_i)
            {
                //copy input data
                m_bDataArray = new byte[data_i.Length];
                data_i.CopyTo(m_bDataArray, 0);
           }
    	
    	//...
    	//checks if a bit on a specfied position is set
    	public bool CheckIfBitOnPositionIsSet(int iPosition)
    	{
    		if (m_bDataArray.Length * 8 < iPosition)
    		{
    			return false;
    		}
    
    		int iByte = iPosition / 8;
    		
    		int iBit = iPosition % 8;
    
    		byte bData = m_bDataArray[iByte];
    
    		if((bData & (0x1 << iBit)) != 0)
    		{
    			return true;
    		}
    		else
    		{
    			return false;
    		}
    	}
    }
    
    
    byte[] data = { 0xFF, 0x3F };
    OctetString octetString = new OctetString(data);
    
    Assert.AreEqual(false, octetString.CheckIfBitOnPositionIsSet(8));

    Пащимуууу!!!
    Как можно упароцца так?
    m)

    blackhearted, 25 Июня 2014

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

    +132

    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
    private object N(Func<object> func)
            {
                try
                {
                    return func();
                }
                catch (NullReferenceException)
                {
                    return null;
                }
            }
    
    ...
    
    int? val = (int?)N(() => oldAttr.parent_value.Analyses_attribute);
    
    ...

    Мощный метод для поддержки паровозов.

    MainGovnokoder, 25 Июня 2014

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

    +140

    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
    protected override void HandleImpl( DeleteTrashModel model )
    {
    	switch( model.TableName )
    	{
    		case DeleteTrashTablesEnum.AuthenticationTicket:
    			this.DeleteTrash( DeleteTrashTablesEnum.AuthenticationTicket, model.DaysCount );
    			break;
    		case DeleteTrashTablesEnum.ResetPasswordTicket:
    			this.DeleteTrash( DeleteTrashTablesEnum.ResetPasswordTicket, model.DaysCount );
    			break;
    		case DeleteTrashTablesEnum.Notification:
    			this.DeleteTrash( DeleteTrashTablesEnum.Notification, model.DaysCount );
    			break;
    		case DeleteTrashTablesEnum.Event:
    			this.DeleteTrash( DeleteTrashTablesEnum.Event, model.DaysCount );
    			break;
    	}
    }

    Если есть Enum - нужен switch!

    sickphilosopher, 25 Июня 2014

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

    +139

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    var program = allProjects.FirstOrDefault(item => item.IsProgram && item.ProgramName == project.ProgramName && item.PortfolioName == PortfolioName);
    if (program != null)
    {
         return program.PortfolioName == project.PortfolioName && program.ProgramName != project.ProgramName;
    }
    
    return false;

    Годный метод всегда возвращать false.

    boades, 24 Июня 2014

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

    +143

    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
    return string.Format(templateStr, "",
                    _p1_Tb.Text,
                    _p2_Tb1.Text + ", " + _p2_Tb2.Text,
                    _p3_Tb.Text,
                    "",//_p4_Tb.Text,
                    _p5_Tb1.Text + " / " + _p5_Tb2.Text,
                    _p6_Tb.Text,
                   RblTxt(_p7_Rbl) + " " + _p7_Tb.Text,
                    b("Построен в ") + _p8_Tb1.Text + " году, в " + _p8_Tb2.Text + " году произведен "
                    + _p8_Tb3.Text + " ремонт. " + _p8_Tb4.Text + ", Количество корпусов " + _p8_Tb4.Text + ", Количество этажей в каждом корпусе " + _p8_Tb5.Text
                    + (_p8_Ch1.Checked ? (", " + _p8_Ch1.Text) : "")
                    + (_p8_Ch2.Checked ? (", " + _p8_Ch2.Text) : "")
                    + (_p8_Ch3.Checked ? (", " + _p8_Ch3.Text) : "") ,
                    FillTbl9() ,
                    b("Уровень средства размещения: ") + _p10_Tb.Text,
                    b("Объект находится рядом с ") + _p11_Tb.Text,
                    "принимаются  с " + _p12_Tb1.Text + " лет, " + _p12_Tb2.Text,
                    _p13_Tb.Text,
                    b("Период работы: ") + (_p14_Rb1.Checked ? ("С " + _p14_Tb1.Text + " По " + _p14_Tb2.Text) : "Круглогодично"),
                    "к " + _p15_Tb1.Text + " до " + _p15_Tb2.Text,
                    _p16_Tb.Text
                    + (_p16_Ch1.Checked ? ("<br/> От аэропорта " + _p16_Tb1.Text + " автобусом № " + _p16_Tb2.Text + " до остановки" + _p16_Tb3.Text) : "")
                    + (_p16_Ch2.Checked ? ("<br/> От жд вокзала " + _p16_Tb4.Text + " автобусом № " + _p16_Tb5.Text + " до остановки" + _p16_Tb6.Text) : "")
                    + (_p16_Ch3.Checked ? ("<br/> Другое " + _p16_Tb7.Text) : "")
                    ,
                    b("Типы номеров: ") + _p17_Tb.Text,
                    b("В номере: ")
                     ((_p23_Ch1.Checked ? (" " + _p23_Ch1.Text + ",") : "")
                    + (_p23_Ch2.Checked ? (" " + _p23_Ch2.Text + ",") : "")
                    + (_p23_Ch3.Checked ? (" " + _p23_Ch3.Text + ",") : "")
                    + (_p23_Ch4.Checked ? (" " + _p23_Ch4.Text + ",") : "")
                    + (_p23_Ch5.Checked ? (" " + _p23_Ch5.Text + ",") : "")
                    + (_p23_Ch6.Checked ? (" " + _p23_Ch6.Text + ",") : "")
                    + (_p23_Ch7.Checked ? (" " + _p23_Ch7.Text + ",") : "")
                    + (_p23_Ch8.Checked ? (" " + _p23_Ch8.Text + ",") : "")
                    + (_p23_Ch9.Checked ? (" " + _p23_Ch9.Text + ",") : "")
                    + (_p23_Ch10.Checked ? (" " + _p23_Ch10.Text + ",") : "")
                    + (_p23_Ch11.Checked ? (" " + _p23_Ch11.Text + ",") : "")
                    + (_p23_Ch12.Checked ? (" " + _p23_Ch12.Text + ",") : "")
                    + (_p23_Ch13.Checked ? (" " + _p23_Ch13.Text + ",") : "")
                    + (_p23_Ch14.Checked ? (" " + _p23_Ch14.Text + ",") : "")
                    + (_p23_Ch15.Checked ? (" " + _p23_Ch15.Text + ",") : "")
                    + (_p23_Ch16.Checked ? (" " + _p23_Ch16.Text + ",") : "")
                    + (_p23_Ch17.Checked ? (" " + _p23_Ch17.Text + ",") : "")
                    + (_p23_Ch18.Checked ? (" " + _p23_Ch18.Text + ",") : "")
                    + (_p23_Ch19.Checked ? (" " + _p23_Ch19.Text + ",") : "")
                    + (_p23_Ch20.Checked ? (" " + _p23_Ch20.Text + ",") : "")
                    + (_p23_Ch21.Checked ? (" " + _p23_Ch21.Text + ",") : "")
                    + (_p23_Ch22.Checked ? (" " + _p23_Ch22.Text + ",") : "")
                    + (_p23_Ch23.Checked ? (" " + _p23_Ch23.Text + ",") : "")
                    + (_p23_Ch24.Checked ? (" " + _p23_Ch24.Text + ",") : "")
                    + (_p23_Ch25.Checked ? (" " + _p23_Ch25.Text + ",") : "")
                    + (_p23_Ch26.Checked ? (" " + _p23_Ch26.Text + ",") : "")
                    + (_p23_Ch27.Checked ? (" " + _p23_Ch27.Text + ",") : "")
                    + (_p23_Ch28.Checked ? (" " + _p23_Ch28.Text + ",") : "")
                    + (_p23_Ch29.Checked ? (" " + _p23_Ch29.Text + ",") : "")
                    + (_p23_Ch20.Checked ? (" " + _p23_Ch30.Text + ",") : "")
                    + (_p23_Ch31.Checked ? (" " + _p23_Ch31.Text + ",") : "")
                    + (_p23_Ch32.Checked ? (" " + _p23_Ch32.Text + ",") : "")
                    + (_p23_Ch33.Checked ? (" " + _p23_Tb.Text) : "")).TrimEnd(new char[] { ' ', ',' }),
                    ((_p24_Ch1.Checked ? (" " + _p24_Ch1.Text + ",") : "")
                    + (_p24_Ch2.Checked ? (" " + _p24_Ch2.Text + ",") : "")
                    + (_p24_Ch3.Checked ? (" " + _p24_Tb.Text) : "")).TrimEnd(new char[] { ' ', ',' }),
                    FillTbl25(),
                    RblTxt(_p26_Rbl1) + " " + _p26_Tb.Text + ". " + RblTxt(_p26_Rbl2),
                    ((_p27_Ch1.Checked ? (" " + _p27_Ch1.Text + ",") : "")
                    + (_p27_Ch2.Checked ? (" " + _p27_Ch2.Text + ",") : "")
                    + (_p27_Ch3.Checked ? (" " + _p27_Ch3.Text + ",") : "")
                    + (_p27_Ch4.Checked ? (" " + _p27_Ch4.Text + ",") : "")
                    + (_p27_Ch5.Checked ? (" " + _p27_Ch5.Text + ",") : "")
                    + (_p27_Ch6.Checked ? (" " + _p27_Ch6.Text + ",") : "")
                    + (_p27_Ch7.Checked ? (" " + _p27_Tb.Text) : "")).TrimEnd(new char[] { ' ', ',' }),
                    _p28_Tb.Text,
                    b("Минимальная продолжительность заезда ") + _p29_Tb.Text + " дней",
                    "от " + _p30_Tb1.Text + " до " + _p30_Tb2.Text + " лет " + _p30_Tb3.Text,
                    ((_p31_Ch1.Checked ? (" " + _p31_Ch1.Text + " " + _p31_Tb1.Text) : "")
                    + "<br/>" + (_p31_Ch2.Checked ? (" " + _p31_Ch2.Text + " " + _p31_Tb2.Text) : "")
                    + "<br/>" + (_p31_Ch3.Checked ? (" " + _p31_Ch3.Text + " " + _p31_Tb3.Text) : "")

    Бэкенды крупнейшего российского туроператора. На отдел разработки уходит 1500000 рб/мес.

    tablecell, 23 Июня 2014

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

    +138

    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
    foreach (var table in group_tables)
                            {
                                foreach (var line in table.lines)
                                {
                                    for (int i = 0; i < group_tables.Count; i++)
                                    {
                                        for (int j = 0; j < group_tables[i].lines.Count; j++)
                                        {
                                            if (line.stream == group_tables[i].lines[j].stream && line.discipline_name == group_tables[i].lines[j].discipline_name &&
                                                line.discipline_type == group_tables[i].lines[j].discipline_type)
                                            {
                                                group_tables[i].lines[j].teacher_name = line.teacher_name;
                                                group_tables[i].lines[j].time = line.time;
                                                group_tables[i].lines[j].auditory_number = line.auditory_number;
                                                group_tables[i].lines[j].day_index = line.day_index;
                                            }
                                        }
                                    }
                                }
                            }

    Не знаю на сколько это говнокод, но вот прям чую что именно он.

    GreatMASTERcpp, 23 Июня 2014

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