Skip to content

Instantly share code, notes, and snippets.

@ChrisMcKee
ChrisMcKee / EnumDropDown.cs
Created January 4, 2013 14:01
Dropdown List from Enum (webforms)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI.WebControls;
public static class Helpers
{
public static IEnumerable<ListItem> EnumDropDown<T>()
{
foreach (var name in Enum.GetNames(typeof(T)))
@ChrisMcKee
ChrisMcKee / php-md5-hash-in-c#
Created January 4, 2013 13:49
PHP MD5 Hash in C# Most implementations of the PHP md5() function in C# produce a different result; this produces the correct one.
public static string PHPMd5Hash(string pass)
{
using (MD5 md5 = MD5.Create())
{
byte[] input = Encoding.UTF8.GetBytes(pass);
byte[] hash = md5.ComputeHash(input);
return BitConverter.ToString(hash).Replace("-", "");
}
}
@ChrisMcKee
ChrisMcKee / SecurityBits.cs
Created January 4, 2013 13:47
Security type methods (helpers)
using System;
using System.Configuration;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using BCrypt.Net;
public static class Helper
{
internal static T GetAppSetting<T>(string key, T Default)
@ChrisMcKee
ChrisMcKee / Base65Encoding.cs
Created January 4, 2013 13:45
Base65 Encoding
namespace Utils
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class Base65Encoding
{
private const string Characters = "0123456789AaBbCcDdEeFfGgHhIiJjKklLMmNnOoPpQqRrSsTtUuVvWwXxYyZz._-";
@ChrisMcKee
ChrisMcKee / ModelObj.cs
Last active December 10, 2015 15:09
Storing delimited data in a column using NHibernate
//Something like this
protected string _roles;
public virtual List<string> Roles
{
get
{
if (String.IsNullOrEmpty(_roles)) return new List<string>();
return _roles.Split(new[] {"|"}, StringSplitOptions.None).ToList();
}
namespace NUSSL.NUSExtra.Core.Model.Base
{
using System;
using System.Diagnostics;
public sealed class Check
{
#region Constructors
private Check()
@ChrisMcKee
ChrisMcKee / Compare two images.cs
Created January 4, 2013 12:17
Basic check for identical images
namespace Utils.Extension
{
using System.Drawing;
using System.Security.Cryptography;
public static class ExtendImage
{
public static bool EqualImage(this Image img, Image imgToCompare)
{
if (img == null && imgToCompare == null)
namespace NUSSL.NUSExtra.Core.Caching
{
using System;
using System.Collections;
using System.Text.RegularExpressions;
using System.Web.Caching;
/// <summary>
/// Cache manager - control entries to cache
/// </summary>
namespace Caching
{
using System;
using System.Collections.Generic;
using System.Web;
public static class CacheHelper
{
/// <summary>
/// Insert value into the cache using
@ChrisMcKee
ChrisMcKee / MessageDisplayConfig.cs
Created January 4, 2013 12:13
Random use of a custom config with nested keys.
namespace Core.Configuration
{
using System;
using System.Configuration;
public class MessageConfigurationSection : ConfigurationSection
{
[ConfigurationProperty("messages", IsDefaultCollection = false)]
[ConfigurationCollection(typeof (MessageCollection), AddItemName = "add", ClearItemsName = "clear", RemoveItemName = "remove")]
public MessageCollection Messages