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 / CocoaLumberjack.swift
Last active August 29, 2015 14:06
CocoaLumberjack Swift Wrapper, fixed for Xcode 6 B6 and up
// Created by Ullrich Schäfer on 16/08/14.
// Bitmasks are a bit tricky in swift
// See http://natecook.com/blog/2014/07/swift-options-bitmask-generator/
//enum LogFlag: Int32 {
// case Error = 0b1
// case Warn = 0b10
// case Info = 0b100
w3wp.exe Error: 0 : [IdentityServer3.Core.Configuration.Hosting.ErrorPageFilterAttribute]: 07/07/15 04:14:12 +00:00 -- Exception accessing: /identity/permissions
System.InvalidOperationException: Sequence contains more than one element
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, Js
@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 / LocalizationHelper.h
Created October 20, 2011 19:39
LocalizationHelper
//
// LocalizationHelper.h
//
// Created by Wim Haanstra on 9/30/10.
// Copyright 2010 Wim Haanstra. All rights reserved.
//
#import
@interface LocalizationHelper : NSObject { }
@sorted-bits
sorted-bits / LocalizationHelper.h
Created October 20, 2011 19:38
LocalizationHelper
//
// LocalizationHelper.h
//
// Created by Wim Haanstra on 9/30/10.
// Copyright 2010 Wim Haanstra. All rights reserved.
//
#import
@interface LocalizationHelper : NSObject { }
@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);
}
@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: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: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:1302091
Created October 20, 2011 19:36
shouldAllowRotateToInterfaceOrientation implementation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [WHUtilities shouldAllowRotateToInterfaceOrientation:interfaceOrientation];
}