Skip to content

Instantly share code, notes, and snippets.

@slmcmahon
slmcmahon / gist:10564234
Created April 13, 2014 01:03
keybase.md
### Keybase proof
I hereby claim:
* I am slmcmahon on github.
* I am slmcmahon (https://keybase.io/slmcmahon) on keybase.
* I have a public key whose fingerprint is 5EDF 98DD DF62 2F0A D425 6173 93DA CB79 C1F8 E531
To claim this, I am signing this object:
@slmcmahon
slmcmahon / gist:a263ffe2d51324d4f275
Last active August 29, 2015 14:04
Check System.DirectoryServices.SearchResult for byte[] or string
private string GetDataFromResults(SearchResult result, string propertyName)
{
if (!result.Properties.Contains(propertyName) || result.Properties[propertyName].Count == 0)
{
return null;
}
var prop = result.Properties[propertyName][0];
var data = prop.GetType() == typeof (byte[])
? Encoding.UTF8.GetString((byte[]) prop)
@slmcmahon
slmcmahon / FindExtendedASCIIChars
Created September 23, 2014 16:33
Reports the index of any characters in a string where the ASCII value is greater than 127
declare
@test nvarchar(500),
@idx int,
@c nchar(1)
set @idx = 1
set @test = 'Nå er tiden for alle gode menn til å komme til unnsetning for landet sitt.'
while @idx < LEN(@test)
begin
/*
This is a convenience class for storing login credentials
This depends on SFHFKeychainUtils from http://github.com/ldandersen/scifihifi-iphone/tree/master/security
and you must add Security.framework to your project
*/
/**********************************************
//CredentialManager.h
#import <Foundation/Foundation.h>
@slmcmahon
slmcmahon / vi_regex_for_objc_props.txt
Created August 24, 2010 18:37
VI regex replace to generate synthesizers from properties.
Converts properties to synthesizers
1. :%s/@property (\(.*, \|\).*)\s.*\s\**\(.*\);/@synthesize \2;/g
2. :%s/@property (\(.*, \|\).*)\s.*\s\**\(.*\);/@synthesize \2 = _\2;/g
Converts properties to release calls
3. :%s/@property (\(.*, \|\).*)\s.*\s\**\(.*\);/ [_\2 release]; _\2 = nil;/g
Example:
input:
@slmcmahon
slmcmahon / NumberConversionTests
Created November 26, 2010 16:47
Demonstrates a way to use TryParse to convert numbers
using System;
using NUnit.Framework;
namespace NumberConversions
{
[TestFixture]
public class ConversionTests
{
private const string VALID_NUMBER = "12345";
private const string INVALID_NUMBER = "BR549";
@slmcmahon
slmcmahon / GetAvailableFrameworks
Created November 29, 2010 21:27
returns a comma delimited list of available .net frameworks
// need this to be able to run in .net 2.0. The result of this is to be sent up
// to the server by the client so that we can determine what versions of the
// .net framework that our users have installed
private string GetAvailableFrameworks()
{
string frameworkRegistryPath = @"Software\Microsoft\.netframework";
List<string> versions = new List<string>();
RegistryKey key = Registry.LocalMachine.OpenSubKey(frameworkRegistryPath);
if (key == null)
{
@slmcmahon
slmcmahon / ServerResponse.cs
Created December 7, 2010 20:56
Container for transferring data between a client application and an ASP.NET server
namespace AppServer.Models
{
/// <summary>
/// This is a generic server response container that provides a way to
/// transfer any serializable type between the client and the server with
/// meta info about the data being transferred
/// </summary>
/// <typeparam name="T">The type of the Payload Property</typeparam>
public class ServerResponse<T>
{
@slmcmahon
slmcmahon / ServerResponse.java
Created December 7, 2010 20:58
Javascript Overlay object for handling JSON server response
package com.yourgwtapp.client.dto;
import com.google.gwt.core.client.JavaScriptObject;
public class ServerResponse<T extends JavaScriptObject> extends JavaScriptObject {
protected ServerResponse() { }
public final native T getPayload() /*-{ return this.Payload; }-*/;
public final native boolean getSuccess() /*-{ return this.Success; }-*/;
@slmcmahon
slmcmahon / gist:1431911
Created December 5, 2011 01:25
Convert XML formatted date to an NSDate
- (NSDate *)convertXmlDate:(NSString *)xmlDate {
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"];
NSDate *date = [dateFormat dateFromString:xmlDate];
[dateFormat release];
return date;
}