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

    +123

    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
    public static string ConvertToBinary( ushort value )
    {
    	StringBuilder builder = new StringBuilder( 19 );
    
    	int mask = (1 << 15);
    
    	for ( int j = 0; j < 4; j++ )
    	{
    		for ( int i = 0; i < 4; i++ )
    		{
    			builder.Append( ((value & mask) != 0) ? ("1") : ("0") );
    
    			mask = mask >> 1;
    		}
    
    		if ( j < 3 )
    		{
    			builder.Append( " " );
    		}
    	}
    
    	return builder.ToString();
    }

    ivan-petrov, 08 Ноября 2011

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

    +132

    1. 1
    System.Console.WriteLine(System.String.Concat(System.Security.Cryptography.MD5.Create().ComputeHash(System.Text.Encoding.UTF8.GetBytes("hello world!")).ToList().ConvertAll(b => b.ToString("x2"))));

    страшно?

    daymansiege, 07 Ноября 2011

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

    +127

    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
    // Функция, добавляемая в цепочку низкоуровневой обработки клавиатуры с помощью SetWindowsHookEx.
    public static int LowLevelKeyboardProc( ... )
    {
    	bool fHandled = false;
    
    	// ...
    	// Далее поиск всех комбинаций, которые "запрещены" в программе,
    	// например, Win+R, Alt+Tab, Alt+F4 и т.д.; если комбинация перехвачена, то fHandled = true.
    
    	if ( fHandled )
    	{
    		KillProcess();
    		return 1;
    	}
    	else
    	{
    		return CallNextHookEx( ... );
    	}
    }
    
    static void KillProcess()					
    {
    	foreach (Process process in Process.GetProcessesByName("regedit"))
     		process.Kill();		// Если запущен редактор реестра закрываем его
    	foreach (Process process in Process.GetProcessesByName("taskmgr"))
    		process.Kill();		// Убиваем диспетчер задач если запущен
    }

    Шелл, типа explorer.exe. Ну-ну...

    ivan-petrov, 07 Ноября 2011

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

    +124

    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
    public static DateTime Sec2Date( UInt32 time )
    {
    	UInt32[] days_per_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    	int[] days_per_year = { 366, 365, 365, 365 };
    	UInt32 hour = (UInt32)((time / 3600) % 24);
    	UInt32 min = (UInt32)((time / 60) % 60);
    	UInt32 sec = (UInt32)(time % 60);
    	// в 4-х годах 1461 день, значит в 1 годе 1461/4=365.25 дней в среднем в году
    	//UInt32 year = (UInt32)(time / (24f * 3600f * 365.25));
    
    	int time_temp = (int)time;
    	int year_temp = 0;
    	do
    	{
    		time_temp -= 24 * 3600 * days_per_year[year_temp % 4];
    		year_temp++;
    	}
    	while ( time_temp > 0 );
    	int year = year_temp - 1;
    
    	// кол-во_секунд_с_начала_года = общее_кол-во_секунд - кол-во_секунд_до_начала_года_с_0_года
    	UInt32 sec_after_curr_year = time - Date2Sec( (int)year, 1, 1, 0, 0, 0 );
    	// кол-во дней, прошедших с начала года
    	UInt32 day = (UInt32)(sec_after_curr_year / (3600 * 24) + 1);
    	// день недели
    	UInt32 week = day % 7;
    	// в феврале високосного года делаем 29 дней
    	if ( 0 == (year % 4) )
    		days_per_month[1] = 29;
    	// из общего кол-во дней будем вычитать дни месяцев, получим месяц и день в месяце
    	UInt32 month = 0;
    	while ( day > days_per_month[month] ) day -= days_per_month[month++];
    	month++;
    	DateTime date = new DateTime( (int)(year + 2000), (int)month, (int)day, (int)hour, (int)min, (int)sec );
    	return date;
    }
    
    public static UInt32 Date2Sec( int Y, int M, int D, int hh, int mm, int ss )
    {
    	DateTime date = new DateTime( Y + 2000, M, D, hh, mm, ss );
    	return Date2Sec( date );
    }
    
    public static UInt32 Date2Sec( DateTime date )
    {
    	int[] days_per_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    	int[] days_per_year = { 366, 365, 365, 365 };
    
    	UInt32 sec_monthes = 0;
    	for ( int i = 0; i < (date.Month - 1); i++ )
    		sec_monthes += (UInt32)(days_per_month[i] * 24 * 3600);
    	if ( (2 < date.Month) && (0 == (date.Year % 4)) )
    		sec_monthes += 24 * 3600;		// 29 февраля
    	UInt32 sec_days = (UInt32)((date.Day - 1) * 24 * 3600);
    	UInt32 sec_hours = (UInt32)(date.Hour * 3600);
    	UInt32 sec_minutes = (UInt32)(date.Minute * 60);
    	UInt32 sec_years = 0;
    	for ( int i = 0; i < (date.Year - 2000); i++ )
    		sec_years += (UInt32)(days_per_year[i % 4] * 24 * 3600);
    	UInt32 total_sec = (UInt32)(sec_years + sec_monthes + sec_days + sec_hours + sec_minutes + date.Second);
    	return total_sec;
    }

    Время измеряется в секундах, прошедших с 00:00:00 01.01.2000.

    ivan-petrov, 07 Ноября 2011

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

    +130

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    void _device_ChangeStsConnect(bool Conn)
    {
    	switch ( Conn )
    	{
    		case true: Start( ); break;
    		case false: Stop( ); break;
    		default: break;
    	}
    }

    ivan-petrov, 07 Ноября 2011

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

    +123

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    while (oSupplierOrder.C2RCustomerID == 0)
    {
               try { oSupplierOrder.C2RCustomerID = LookupCustomerID(); }
               catch { }
    }

    diiceas, 04 Ноября 2011

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

    +127

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (ddlSex.SelectedValue.Contains("мужской"))
           cbPregnant.Visible = false;
    if (employer.Pregnant.StartsWith("1"))
          cbProject.Checked = true;
    if (employer.Pregnant.StartsWith("2"))
          cbPregnant.Checked = true;

    TasmX, 03 Ноября 2011

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

    +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
    static string ContentTypeDecode(string contentTypeName)
            {
                if (contentTypeName.Equals("Поручение")) return "Задание";
                if (contentTypeName.Equals("Поручение с результатом типа текст")) return "Задание с результатом типа текст";
                if (contentTypeName.Contains("Поручение с результатом типа выбор")) return "Задание с результатом типа выбор";
                if (contentTypeName.Equals("Поручение с результатом типа документ")) return "Задание с результатом типа документ";
                if (contentTypeName.Equals("Поручение с результатом типа форма")) return  "Задание с результатом типа форма";
                if (contentTypeName.Equals("Поручение с результатом типа флаг")) return "Задание с результатом типа флаг";
                if (contentTypeName.Equals("Поручение с результатом типа число")) return "Задание с результатом типа число";
                if (contentTypeName.Equals("Поручение с результатом типа дата")) return "Задание с результатом типа дата";
                if (contentTypeName.Equals("Поручение с результатом типа пользователь")) return "Задание с результатом типа пользователь";
                if (contentTypeName.Equals("Поручение с результатом типа список пользователей")) return "Задание с результатом типа список пользователей";
                if (contentTypeName.Equals("Поручение на сканирование")) return "Задание на сканирование";
                if (contentTypeName.Equals("Задача на контроль поручения")) return "Задание на контроль";
                if (contentTypeName.StartsWith("Утверждение документа v3")) return "Утверждение документа";
                if (contentTypeName.StartsWith("Согласование документа v3")) return "Согласование документа";
                if (contentTypeName.StartsWith("Утверждение документа v4")) return "Утверждение документа";
                if (contentTypeName.StartsWith("Согласование документа v4")) return "Согласование документа";
                return null;
            }///string ContentTypeDecode(string ContentTypeName)

    Из реального комерческого проекта

    VasyaPupkin, 02 Ноября 2011

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

    +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
    /// <summary>
    		/// Конвертирование String - Decimal
    		/// </summary>
    		/// <param name="text"></param>
    		/// <param name="value"></param>
    		/// <returns></returns>
    		public static decimal GetDecimal(this string text)
    		{
    			decimal number;
    			CultureInfo culture = null;
    
    			if (String.IsNullOrEmpty(text))
    				throw new ArgumentNullException("The input string is invalid.");
    
    			try
    			{
    				culture = CultureInfo.CurrentCulture;
    				number = decimal.Parse(text, culture);
    				return number;
    			}
    			catch
    			{
    			}
    
    			try
    			{
    				culture = culture.Parent;
    				number = decimal.Parse(text, culture);
    				return number;
    			}
    			catch
    			{
    			}
    
    			culture = CultureInfo.InvariantCulture;
    			try
    			{
    				number = decimal.Parse(text, culture);
    				return number;
    			}
    
    			catch (FormatException e)
    			{
    				throw new FormatException(String.Format("Unable to parse '{0}'.", text), e);
    			}
    		}

    Это финиш.

    fr0mrus, 02 Ноября 2011

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

    +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
    public void ExportOrderDetails()
            {
                char comma = ',';
                StringBuilder sb = new StringBuilder();
                string line = "";
    
                line += "Order No" + comma;
                line += "Customer" + comma;
                line += "Order Date" + comma;
                line += "Order Status" + comma;
                line += "Subtotal" + comma;
                line += "Tax Total" + comma;
                line += "Shipping Cost" + comma;
                line += "Shipping Method" + comma;
                line += "Order Total" + comma;
                line += "Payment Method" + comma;
                line += "Total Quantity" + comma;
                line += "Date Shipped" + comma;
                line += "Tracking No" + comma;
                line += "Order Currency Code" + comma;
                line += "Exchange Rate" + comma;
                line += "Billing First Name" + comma;
                line += "Billing Last Name" + comma;
                line += "Billing Company" + comma;
                line += "Billing Address" + comma;
                line += "Billing Address 2" + comma;
                line += "Billing City" + comma;
                line += "Billing Zip" + comma;
                line += "Billing State Code" + comma;
                line += "Billing Country ISO2" + comma;
                line += "Billing Phone" + comma;
                line += "Billing Phone 2" + comma;
                line += "Billing Email" + comma;
                line += "Shipping First Name" + comma;
                line += "Shipping Last Name" + comma;
                line += "Shipping Company" + comma;
                line += "Shipping Address" + comma;
                line += "Shipping Address 2" + comma;
                line += "Shipping City" + comma;
                line += "Shipping Zip" + comma;
                line += "Shipping State Code" + comma;
                line += "Shipping Country ISO2" + comma;
                line += "Shipping Phone" + comma;
                line += "Shipping Phone 2" + comma;
                line += "Shipping Email" + comma;
    
                line += "Combined Product Weight" + comma;
                line += "Product Qty" + comma;
                line += "Product SKU" + comma;
                line += "Product Name" + comma;
                line += "Product Variation Details" + comma;
                line += "Product Unit Price" + comma;
                line += "Product Unit Cost" + comma;
                line += "Product Weight" + comma;
                line += "Product Total Price" + comma;
                line += "Product Total Cost" + comma;
    
    
    
                sb.AppendLine(line.Remove(line.Length - 1));
     
                Response.ContentType = "application/vnd.ms-excel";
                Response.AddHeader("Content-Disposition", "attachment; filename=orders-details-" + DateTime.Now.ToString("yyyy-MM-dd") + ".csv");
                Response.ContentEncoding = Encoding.Default;
                Response.Write(sb.ToString());
                Response.End();
    
            }

    Норм так)

    sergfreest, 01 Ноября 2011

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