Skip to content

Instantly share code, notes, and snippets.

View sorted-bits's full-sized avatar

Wim Haanstra sorted-bits

View GitHub Profile
@sorted-bits
sorted-bits / gist:1302088
Created October 20, 2011 19:35
shouldAllowRotateToInterfaceOrientation
+ (BOOL) shouldAllowRotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation
{
NSString* currentOrientation = @"";
switch (interfaceOrientation)
{
case UIInterfaceOrientationLandscapeLeft:
currentOrientation = @"UIInterfaceOrientationLandscapeLeft";
break;
case UIInterfaceOrientationLandscapeRight:
currentOrientation = @"UIInterfaceOrientationLandscapeRight";
@sorted-bits
sorted-bits / gist:1302080
Created October 20, 2011 19:33
Encryption & decryption
public static string Encrypt(this string Message, string passphrase = "")
{
if (passphrase == "")
passphrase = ConfigurationManager.AppSettings["encrpytionPassphrase"];
byte[] Results;
System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider();
byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(passphrase));
@sorted-bits
sorted-bits / gist:1302074
Created October 20, 2011 19:31
MD5 and SHA1 hashing
public static string ToSHA1(this string text, Encoding enc)
{
byte[] buffer = enc.GetBytes(text);
SHA1CryptoServiceProvider cryptoTransformSHA1 =
new SHA1CryptoServiceProvider();
string hash = BitConverter.ToString(
cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
return hash;
}
@sorted-bits
sorted-bits / gist:1302069
Created October 20, 2011 19:30
String to valid filename
static public string ToValidFileName(this string name)
{
string invalidChars = Regex.Escape(new string(Path.GetInvalidFileNameChars()));
string invalidReStr = string.Format(@"[{0}]+", invalidChars);
return Regex.Replace(name, invalidReStr, "_");
}
@sorted-bits
sorted-bits / gist:1302057
Created October 20, 2011 19:26
Validating Int from string
public static bool IsInt(this string text)
{
int integer = 0;
return Int32.TryParse(text, out integer);
}