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

    В номинации:
    За время:
  2. Куча / Говнокод #16285

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if chkyandex.Checked then
    	
        reg.Expression:='([a-zA-Z0-9]+[\.]{0,}[\_]{0,}[-]{0,})+@([ya]{2}[ndex]{0,4}|[xaker]{5})\.[a-zA-Z]{2,3}\s{0,4}[:;]\s{0,4}[a-zA-Z0-9\.\_]+'; 
        else
        reg.Expression:='([a-zA-Z0-9]+[\.]{0,}[\_]{0,}[-]{0,})+@([mail]{4}|[inbox]{5}|bk{2}|list{4})\.([a-zA-Z]{2,3}\s{0,4}[:;]\s{0,4}[_\-a-zA-Z\d\.\_]+)';

    RegEXP головного мозга.
    Работает.

    brutushafens, 08 Июля 2014

    Комментарии (23)
  3. Си / Говнокод #16240

    +133

    1. 1
    2. 2
    /* All the message are high priority message  */
    message_id = message_id | LOW_PRIORITY_MESSAGE_MASK;

    Все сообщения с высоким приоритетом. *Да-да, конечно*

    sermp, 27 Июня 2014

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

    +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
    string parser(string chto, string chem)
                {
                    int dlina = chem.Length;
                    int kol = chto.Length;
                    string ret = null;
                    int shet = 0;
                    int r = 0;
                    int nom = 0;
                    for (int i = 0; i < kol; i++)
                    {
                        if (chto[i] == chem[0] && shet == 0)
                        {
                            for (int j = i; j < dlina + i; j++)
                            {
                                if (chto[j] == chem[r])
                                {
                                    r++;
                                    shet++;
                                    nom = j;
                                }
    
                            }
                            if (shet != dlina)
                            {
                                shet = 0;
                                r = 0;
                                nom = 0;
                            }
                        }
                    }
                    int schet = nom + 3;
                    while (chto[schet] != '<')
                    {
                        ret += chto[schet];
                        schet++;
                    }
                    return ret;
                }

    Функция для парсинга подстроки

    vladb9582, 18 Июня 2014

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

    +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
    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
    [Serializable]
    public class CSScriptCompiler
    {
    	//file name of script  including full path
    	string sFileNameWithPath;
    
    	System.Reflection.Assembly m_assembly = null;
    
    	public CSScriptCompiler(string ScriptFileName)
    	{
    		this.sFileNameWithPath = Path.GetFullPath(ScriptFileName);
    
    		try
    		{
    			//load Assembly of *.cs file
    			m_assembly = CSScript.Load(sFileNameWithPath, null, true);
    		}
    		catch (Exception ex)
    		{
    			m_assembly = null;
    			MessageBox.Show(ex.Message);
    			
    			throw (ex);
    		}
    	}
    
    	public bool Initialize(params object[] InitArgs)
    	{
    		if (m_assembly == null)
    		{
    			return false;
    		}
    
    		try
    		{
    			var InitFuntion = m_assembly.GetStaticMethod("*.Initialize", InitArgs);
    
    			//call initialize function
    			InitFuntion(InitArgs);
    		}
    		catch (Exception ex)
    		{
    			MessageBox.Show(ex.Message);
    			return false;
    		}
    
    		return true;
    	}
    
    
    	public object CallFunction(String sFunctionName, params object[] args)
    	{
    		object result = null;
    
    		sFunctionName = "*." + sFunctionName;
    		try
    		{
    			var theFunction = m_assembly.GetStaticMethod(sFunctionName, args);
    		   
    			//call the method with your own arguements
    			result = theFunction(args);
    		}
    		catch (Exception ex)
    		{
    			MessageBox.Show(ex.Message);
    		}
    
    		return result;
    	}
    }

    Ну что тут скажешь...
    Велосипедист...

    blackhearted, 16 Июня 2014

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

    +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
    try
                {
                    DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(filePath));
                    if (!dir.Exists)
                    {
                        dir.Create();
                    }
                }
                catch (IOException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                catch
                {
                    throw new Exception("Системная ошибка при создании директории");
                }

    EADG, 05 Июня 2014

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

    +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
    //checks if the string is a hex stream e.g. "31 32 33 6A F8"
            private bool _IsHexStream(string sValue)
            {
                sValue = sValue.Trim();
    
                
                if (sValue.Length < 2)
                {
                    return false;
                }
    
                for (int i = 0; i < sValue.Length; i++)
                {
                    if(_IsHexChar(Convert.ToChar(sValue.Substring(i,1))) == false)
                    {
                        return false;
                    }
                }
    
                //every third char must be a space, only possible in case of two bytes
                if (sValue.Length > 3)
                {
                    for (int i = 2; i < sValue.Length; i += 3)
                    {
                        string sBuffer = sValue.Substring(i, 1);
    
                        if (sBuffer.Equals(" ") == false)
                        {
                            return false;
                        }
                    }
                }
    
                //string is a hex stream 
                return true;
            }

    blackhearted, 02 Июня 2014

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

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    panel1.Visible = checkBoxCCF.Checked;
    panel2.Visible = checkBoxReliabilty.Checked;
    panel3.Visible = checkBoxRisk.Checked;
    panel4.Visible = checkBoxSaftey.Checked;
    panel5.Visible = checkBoxSensitivity.Checked;
    panel6.Visible = checkBoxThroughput.Checked;
    panel7.Visible = checkBoxUncertainity.Checked;

    Почему половина переменных нормальные, половина нет? Логика некоторых погромистов зашкаливает...

    kostoprav, 28 Мая 2014

    Комментарии (3)
  10. Си / Говнокод #16065

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    typedef long bool_t;
    #define TRUE 1
    #define FALSE 0
    
    void f() {
            bool_t var;
            for (var = TRUE; var > FALSE; var++) { /* ... */ }
    }

    evg_ever, 28 Мая 2014

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

    +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
    public void ExtIdGen()
    {
    	try
    	{
    		Random rnd = new Random();
    		string uin = "";
    		for (int i = 0; i < 20; i++)
    		{
    			uin += rnd.Next(10).ToString();
    		}
    
    		this.ExtId = uin;
    
    		GetError("0");
    	}
    	catch
    	{
    		GetError("-6");
    	}
    }
    
    private void GetError(string error_code)
    {
                switch (error_code)
                {
                    case "0":
                        this.LastErrorCode = 0;
                        this.LastErrorDescription = "Нет ошибок";
                        break;
    		// -1 .. -5
                    case "-6":
                        this.LastErrorCode = -6;
                        this.LastErrorDescription = "Ошибка при получении идентификатора запроса";
                        break;
                }
    }

    LastErrorCode, LastErrorDescription, ExtId - public поля.
    Там весь класс написан в таком стиле, с вызовами GetError, принимающими номер ошибки в виде строки, молчаливым catch-ем всех исключений и т.п.

    yamamoto, 17 Мая 2014

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