Skip to content

Instantly share code, notes, and snippets.

View brcosm's full-sized avatar

Brandon Smith brcosm

  • Amazon.com
  • Seattle, WA
View GitHub Profile
@brcosm
brcosm / avalon_game_state.json
Last active December 19, 2015 10:59
Game state dump to show object model as exposed to the
{
"currentLeader":{
"role":{
"name":"Loyal Servant of Arthur",
"type":2
},
"playerId":"RND 6"
},
"voteNumber":1,
"passedQuestCount":3,
@brcosm
brcosm / UIKeyboardNotification Resizing
Last active April 5, 2016 21:45
How to deal with keyboard resizing in a UIViewController
- (void)observeKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)stopObservingKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@brcosm
brcosm / Rakefile
Created January 15, 2013 20:26
The Rakefile I use to deploy my Jekyll site.
require 'jcs3'
def content_type_for_extension(extension)
return "text/html" if %w[html htm].include?(extension)
return "text/css" if %w[css].include?(extension)
return "application/javascript" if %w[js].include?(extension)
return "image/gif" if %w[gif].include?(extension)
return "image/jpeg" if %w[jpeg jpg].include?(extension)
return "image/png" if %w[png].include?(extension)
return "image/tiff" if %w[tiff tf].include?(extension)
@brcosm
brcosm / gist:3484575
Created August 27, 2012 00:13
AWSHTTP List Glacier Vaults
#import "AWSHTTPRequest.h"
#import "AWSVersion4RequestSigner.h"
- (void)exampleRequest {
NSString *service = @"glacier";
NSString *region = @"us-west-2";
NSString *host = [NSString stringWithFormat:@"%@.%@.amazonaws.com", service, region];
AWSVersion4RequestSigner *v4Signer = [[AWSVersion4RequestSigner alloc] initWithAccessKey:@"YOURKEY" secretKey:@"YOURSECRETKEY"];
@brcosm
brcosm / ProxyCache.m
Created July 2, 2012 23:00
NSURLCache to ignore UIWebView sub-requests
@interface ProxyCache : NSURLCache
@end
@implementation ProxyCache
- (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request {
if ([request.URL.absoluteString hasPrefix:@"https://www.amazon.com/ap/uedata?"]) {
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:request.URL
MIMEType:@"text/plain"
expectedContentLength:0
@brcosm
brcosm / apns.rb
Created September 13, 2011 02:41
Ruby Apple Push Notification Example
require 'openssl'
require 'socket'
require 'rubygems'
require 'json'
# Takes json as an input and sends data to APNS over SSL
APNS_HOST = 'gateway.sandbox.push.apple.com'
APNS_PORT = 2195
APNS_CERT_FILE_PATH = 'MyCert.pem'
@brcosm
brcosm / Contacts.m
Created September 11, 2011 19:08
Objective-C Image for Contact in Address Book
@implementation Contacts
+ (UIImage *)imageForContactWithName:(NSString *)name {
// Create a CF string reference from the NSString pointer
CFStringRef cfName = objc_unretainedPointer(name);
UIImage *personImage = nil;
// Create a reference to the address book
ABAddressBookRef addressBook = ABAddressBookCreate();
@brcosm
brcosm / pax.rb
Created August 26, 2011 02:08
Ruby file used to convert some PAX html schedule data into a .plist for my iPhone app
def get_panelist_array(div)
# Regex to get rid of bracketed stuff
r = /\[.*\]/
panelists = div.gsub(r,"")
panelists = panelists.gsub("<i>Panelists include: ","")
panelists = panelists.gsub("</i>","")
panelists = panelists.split(", ")
xml = "\t\t<array>\n"