Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Data.SqlClient;
using System.Data;
using System.Collections.Generic;
namespace AdoUsageDemo
{
// While I prefer to use LINQ for these types of database actions, we have some code
// in some of our applications that has been around for a while where we cannot take the
// time to upgrade them. So this is to demonstrate how to refactor older ADO.NET code in
/*
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;
}
@slmcmahon
slmcmahon / MetaSearchServiceDelegate.h
Created March 4, 2012 22:59
Protocol for MetaSearchService
#import <Foundation/Foundation.h>
@class MetaSearchService;
@protocol MetaSearchServiceDelegate <NSObject>
- (void)metaSearchComplete:(MetaSearchService *)service;
@end
@slmcmahon
slmcmahon / MetaSearchService.h
Created March 4, 2012 23:00
MetaSearchService header
#import <Foundation/Foundation.h>
#import "ASIHTTPRequestDelegate.h"
#import "MetaSearchServiceDelegate.h"
extern NSString *const META_SEARCH_URL;
extern NSString *const META_SEARCH_SOAP;
extern NSString *const META_SEARCH_SOAP_ACTION;
@interface MetaSearchService : NSObject<ASIHTTPRequestDelegate,NSXMLParserDelegate> {
NSMutableString *currentString;