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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    string str3 = Strings.Trim(ID);
     do
     {
         num2 = (short) Strings.InStr(str3, " ", CompareMethod.Binary);
         if (num2 > 0)
         {
                str3 = str3.Substring(0, num2 - 1) + Strings.Mid(str3, num2 + 1);
         }
    }
    while (num2 > 0);

    А зачем нам str3.Replace(" ", string.Empty) ?

    inickvel, 25 Ноября 2015

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

    +2

    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
    bool isLiveLine = false;
    bool isQALine = false;
    
    if (lineInfo.IndexOf("QL") != -1)
    {
     isLiveLine = true;
     isQALine = true;
    }
    else if (lineInfo.IndexOf("Q") != -1)
    {
     isLiveLine = false;
     isQALine = true;
    }
    else if (lineInfo.IndexOf("L") != -1)
    {
     isLiveLine = true;
     isQALine = false;
    }
    else
    {
     isLiveLine = false;
     isQALine = false;
    }

    pro687, 24 Ноября 2015

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

    +2

    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
    public static byte[] HMACSHA256(ProtectedData key, byte[] data)
    {
        using (var _key = key.Get())
        using (var hmac = new HMACSHA256(_key))
            return hmac.ComputeHash(data);
    }
    
    public static byte[] HMACSHA256(ProtectedData key, Stream stream)
    {
        using (var _key = key.Get())
        using (var hmac = new HMACSHA256(_key))
            return hmac.ComputeHash(stream);
    }
    
    public static byte[] HMACSHA256(byte[] key, byte[] data)
    {
        using (var hmac = new HMACSHA256(key))
            return hmac.ComputeHash(data);
    }
    
    public static byte[] HMACSHA256(byte[] key, Stream stream)
    {
        using (var hmac = new HMACSHA256(key))
            return hmac.ComputeHash(stream);
    }
    
    public static byte[] MD5(byte[] data)
    {
        using (var h = System.Security.Cryptography.MD5.Create())
        { return h.ComputeHash(data); }
    }
    
    public static byte[] MD5(Stream stream)
    {
        using (var h = System.Security.Cryptography.MD5.Create())
        { return h.ComputeHash(stream); }
    }
    
    public static byte[] SHA1(byte[] data)
    {
        using (var h = System.Security.Cryptography.SHA1.Create())
            return h.ComputeHash(data);
    }
    
    public static byte[] SHA1(Stream stream)
    {
        using (var h = System.Security.Cryptography.SHA1.Create())
            return h.ComputeHash(stream);
    }
    
    public static byte[] SHA256(byte[] data)
    {
        using (var h = System.Security.Cryptography.SHA256.Create())
            return h.ComputeHash(data);
    }
    
    public static byte[] SHA256(Stream stream)
    {
        using (var h = System.Security.Cryptography.SHA256.Create())
            return h.ComputeHash(stream);
    }
    
    public static byte[] SHA384(byte[] data)
    {
        using (var h = System.Security.Cryptography.SHA384.Create())
            return h.ComputeHash(data);
    }
    
    public static byte[] SHA384(Stream stream)
    {
        using (var h = System.Security.Cryptography.SHA384.Create())
            return h.ComputeHash(stream);
    }
    
    public static byte[] SHA512(byte[] data)
    {
        using (var h = System.Security.Cryptography.SHA512.Create())
            return h.ComputeHash(data);
    }
    
    public static byte[] SHA512(Stream stream)
    {
        using (var h = System.Security.Cryptography.SHA512.Create())
            return h.ComputeHash(stream);
    }

    Психанул

    yourmom, 20 Ноября 2015

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

    +2

    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
    using Microsoft.VisualBasic;
    
            public string ConvertEnoviaNameForDB1(string name, char Separ = '%')
            {
                string functionReturnValue = null;
                functionReturnValue = name;
                //input filename
                //check ENOVIA filenames (example c0234244 --.catpart or c0234244--.catpart)
                //output filename in DB format for operator LIKE(c0234244 --.catpart -> c0234244%.catpart)
                int i = 0;
                int loc1 = Strings.InStr(name, ".CATP", CompareMethod.Text);
                bool NeedToConvert = false;
                char Chr1 = '1';
                char ChrBefore1 = '1';
                //check catparts and catproducts ONLY
                if (loc1 > 0)
                {
                    int NumSymbols = loc1 - 2;
                    if (NumSymbols > 6)
                        NumSymbols = 6;
                    string tmpstr1 = Strings.Mid(name, loc1 - NumSymbols - 1, NumSymbols);
                    //analyse 4 chars max
                    for (i = 0; i <= loc1 - 2; i++)
                    {
                        Chr1 = name[loc1 - 2 - i];
                        //3-string array start from 0(position = count-1)
                        if ((Strings.Asc(ChrBefore1) >= 65 & Strings.Asc(ChrBefore1) <= 90))
                        {
                            if (Chr1 == ' ')
                            {
                                i = i + 2;
                                break; // TODO: might not be correct. Was : Exit For
                            }
                            else if (Chr1 == '-')
                            {
                                ChrBefore1 = Chr1;
                                //means can be  two chars (ex. "AA") max
                            }
                            else if ((Strings.Asc(Chr1) >= 65 & Strings.Asc(Chr1) <= 90) & i < 2)
                            {
                                ChrBefore1 = Chr1;
                            }
                            else
                            {
                                break; // TODO: might not be correct. Was : Exit For
                            }
                        }
                        else if (ChrBefore1 == '-')
                        {
                            if (Chr1 == ' ')
                            {
                                i = i + 2;
                                break; // TODO: might not be correct. Was : Exit For
                                // And i < 3 Then 'means can be "---" - not more
                            }
                            else if (Chr1 == '-')
                            {
                                //ChrBefore1 = Chr1
                            }
                            else
                            {
                                i = i + 1;
                                break; // TODO: might not be correct. Was : Exit For
                            }
                            //ChrBefore1 = Chr1
                            // means start
                        }
                        else if (ChrBefore1 == '1')
                        {
                            if (Chr1 == '-' | (Strings.Asc(Chr1) >= 65 & Strings.Asc(Chr1) <= 90))
                            {
                                ChrBefore1 = Chr1;
                            }
                            else
                            {
                                i = i + 1;
                                break; // TODO: might not be correct. Was : Exit For
                            }
    
                        }
                    }
                    functionReturnValue = Strings.Left(name, loc1 - i) + Separ + Strings.Right(name, Strings.Len(name) - loc1 + 1);
                }
                return functionReturnValue;
            }

    Наличие комментария в 7ой строчке приводит в неописуемый восторг.
    Без него понимать поведение функции пришлось бы с болью.
    И да, в RegExp могут не только лишь все. Мало кто может.

    Szer, 20 Ноября 2015

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

    +3

    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
    public class Logger
    	{
    		public static string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.log");
    
    		public static void Write(string message)
    		{
    			using (var sw = File.AppendText(filePath))
    			{
    				sw.WriteLine(DateTime.Now);
    				sw.WriteLine(message);
    				sw.WriteLine();
    				sw.Flush();
    			}
    		}
    
    		public static void Write(Exception exception)
    		{
    			using (var sw = File.AppendText(filePath))
    			{
    				sw.WriteLine(DateTime.Now);
    				sw.WriteLine("ERROR:");
    				sw.WriteLine(exception.Message);
    				sw.WriteLine(exception.StackTrace);
    				sw.WriteLine();
    				sw.Flush();
    			}
    		}
    	}

    Нафига готовые решения? Вот - образец велосипедостроения! (И, тссс! Не вздумайте использовать его в многопоточной среде ;) А именно там он и используется по факту :) )

    PS угадайте какой фортель выкинет сеё чудо при race condition

    leon_mz, 18 Ноября 2015

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

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    private void KbkButtonAvailabilityCheck()
    {
       bttAddKbk.Enabled = !string.IsNullOrWhiteSpace(string.Format("{0}{1}{2}{3}{4}", txtChapter.Text, txtSection.Text, txtArticle.Text, txtKind.Text, txtKOSGU.Text));
    }

    Проверяем, есть ли данные хотя бы в одной строке

    Psilon, 18 Ноября 2015

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

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public bool AddCellImage(Image Img, BaseAnalysisObjectsClassification AnAttr)
    {
        bool bRes = false;
        for (; ; )
        {
            AddCell(Img, AnAttr);
            bRes = true;
            break;
        }
        return bRes;
    }

    whirlwind, 17 Ноября 2015

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

    +2

    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
    #include <fstream>
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    void main()
    	ifstream in("D:\\MetATetratronicLessonsABberation\\LibraryAbsoluteBallistikAcoustic_1\\Right.txt");//Даётся файл, содержащий единицы и нули, 1 - человек есть, 0 - человека нет
    	in >> s1;
    	cout << "Содержимое файла Right.txt: " << endl << s1 << endl;
    	int CountRDoor = 0;
    			CountRDoor++;
    	}
    	cout << "Кол-во человек, прошедших через правую дверь = " << CountRDoor << endl;
    	cout << "________________________________________________________________________________"; //< Для более лёгкой навигации
      //printf("%c", 7);
    	cout << endl;
    	char s2[4096];
    	ifstream in2("D:\\MetATetratronicLessonsABberation\\LibraryAbsoluteBallistikAcoustic_1\\Left.txt");
    	in2 >> s2;
    	in2.close();
    	cout << "Содержимое файла Left.txt: " << endl << s2 << endl;
    	int CountLDoor = 0;
    	int j = 1;
    	while (j != 4095)
    	{
    		if (s2[j] < s2[j + 1])
    			CountLDoor++;
    		j++;
    	}
    	cout << "Кол-во человек, прошедших через левую дверь = " << CountLDoor << endl;
    	cout << "________________________________________________________________________________";
    	//printf("%c", 7);
    	cout << endl;
    	char s3[4096];
    	ifstream in3("D:\\MetATetratronicLessonsABberation\\LibraryAbsoluteBallistikAcoustic_1\\Found.txt");
    	in3 >> s3;
    	in3.close();
    	cout << "Содержимое файла Found.txt: " << endl << s3 << endl;
    	int CountFound = 0;
    	int k = 1;
    	while (k != 4095)
    	{
    		if (s3[k] > s3[k + 1])
    			CountFound++;
    		k++;
    	}
    	cout << "Общее кол-во человек = " << CountFound << endl << "\a";
    	cout << "________________________________________________________________________________";
    	system("pause");
    }

    Универ, 1-й курс. Необходимо было написать программу, на вход которой даётся 2 файла, содержащих 1 и 0, и 1 файл, содержащий диапазон чисел от 1 до 9, показывающих кол-во человек в кадре абстрактной камеры одновременно. Местоположение каждого файла строго определено. И да, не пытайтесь вдуматься, что обозначают названия папок в путях, так как смысла там никакого нет)

    Z1VR, 14 Ноября 2015

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

    +5

    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
    if (logsData.Count == 1) {
    				msg += logsData [logsData.Count - 1] + "\n";
    			} else if (logsData.Count == 2) {
    				msg += logsData [logsData.Count - 2] + "\n";
    				msg += logsData [logsData.Count - 1] + "\n";
    			} else if (logsData.Count == 3) {
    				msg += logsData [logsData.Count - 3] + "\n";
    				msg += logsData [logsData.Count - 2] + "\n";
    				msg += logsData [logsData.Count - 1] + "\n";
    			} else if (logsData.Count == 4) {
    				msg += logsData [logsData.Count - 4] + "\n";
    				msg += logsData [logsData.Count - 3] + "\n";
    				msg += logsData [logsData.Count - 2] + "\n";
    				msg += logsData [logsData.Count - 1] + "\n";
    			} else if (logsData.Count >= 5) {
    				msg += logsData [logsData.Count - 5] + "\n";
    				msg += logsData [logsData.Count - 4] + "\n";
    				msg += logsData [logsData.Count - 3] + "\n";
    				msg += logsData [logsData.Count - 2] + "\n";
    				msg += logsData [logsData.Count - 1] + "\n";
    			}

    kschingiz, 12 Ноября 2015

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

    +11

    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
    public class Solution
    {
        public static void main(String[] args)
        {
    
            int a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7, i = 8, j = 9, k = 10;
            System.out.println( + ( a + b ));
            System.out.println( + ( a + b + c ));
            System.out.println( + ( a + b + c + d ));
            System.out.println( + ( a + b + c + d + e ));
            System.out.println( + ( a + b + c + d + e + f ));
            System.out.println( + ( a + b + c + d + e + f + g ));
            System.out.println( + ( a + b + c + d + e + f + g + i ));
            System.out.println( + ( a + b + c + d + e + f + g + i + j ));
            System.out.println( + ( a + b + c + d + e + f + g + i + j + k ));
    
    
    
        }
    }

    Вывести на экран сумму чисел от 1 до 10 построчно.

    luminary, 09 Ноября 2015

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