Skip to content

Instantly share code, notes, and snippets.

View blakewatters's full-sized avatar

Blake Watters blakewatters

View GitHub Profile
@guenter
guenter / move_to_rds.rb
Created November 11, 2010 02:14
A quick and dirty script to move a database into Amazon RDS (or any other database). Can transfer part of the data beforehand.
require 'fileutils'
start_time = Time.now
SOURCE_DB = {
:name => 'db_name',
:user => 'db_user',
:password => 'db_pass',
:host => 'localhost'
@zaius
zaius / background.sh
Created January 16, 2011 23:29
How to redirect a running process output to a file and log out
ctrl-z
bg
touch /tmp/stdout
touch /tmp/stderr
gdb -p $!
# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)
@kopischke
kopischke / markdown2evernote.rb
Created June 5, 2011 16:57
OS X service scripts
#!/usr/bin/env ruby -wKU
# Adapted from Brett Terpstra’s original “Markdown to Evernote” service (http://brettterpstra.com/a-better-os-x-system-service-for-evernote-notes-with-multimarkdown/)
# Martin Kopischke 2011 – License: Creative Commons Attribution Share-Alike (CC BY-SA) 3.0 Unported (http://creativecommons.org/licenses/by-sa/3.0/)
# Changes: – create only one Evernote note per (Multi)Markdown input passed (instead of one per line)
# – do not choke on shell escape characters (use Tempfile instead of shell pipe for osascript)
# – default to MultiMarkdown 3 executable (instead of MMD 2 Perl script)
# – make smart typography processing optional (set SMARTY to 'false' to bypass processing;
# note smart typography cannot be disabled in MMD 3.0 and 3.0.1
# – handle both smart typography processing scripts (ie. SmartyPants.pl)
@blakewatters
blakewatters / gist:1368819
Created November 16, 2011 00:00
sendData:toResourcePath:usingBlock
// Encode some arbitrary data and send it to the remote server. Object mapping will be performed on the results
- (RKObjectLoader *)sendData:(id)data toResourcePath:(NSString *)resourcePath usingBlock:(void (^)(RKObjectLoader *objectLoader))block {
RKObjectLoader* loader = [self objectLoaderWithResourcePath:resourcePath delegate:nil];
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:self.serializationMIMEType];
NSString* string = [parser stringFromObject:serializedObject error:error];
NSData* data = [string dataUsingEncoding:NSUTF8StringEncoding];
loader.params = [RKRequestSerialization serializationWithData:data MIMEType:self.serializationMIMEType];
loader.method = RKRequestMethodPOST;
@soemarko
soemarko / theme.html
Created November 26, 2011 16:18
embed github gist to tumblr
<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
<!--
Usage: just add <div class="gist">[gist URL]</div>
Example: <div class="gist">https://gist.github.com/1395926</div>
-->
@jmreidy
jmreidy / env.sample.js
Created December 28, 2011 23:28
Pivotal to Sprintly importer
module.exports = {
pivotal: {
TOKEN: 'TOKEN'
PID: 'PID',
},
sprintly: {
USER: "USER_EMAIL",
ID: 'PRODUCT_ID',
KEY: 'API_KEY'
},
@chriseidhof
chriseidhof / nsincrementalstore.markdown
Created February 18, 2012 16:39
Accessing an API using CoreData's NSIncrementalStore

Accessing an API using CoreData's NSIncrementalStore

Note: the original location of this article is on my blog, however, it is posted here too for better readability.

In this article, we will see how to use Core Data for accessing your API. We will use the Bandcamp API as our running example. I've only been experimenting with this code for a few days, so there might be mistakes in there.

@romainbriche
romainbriche / TBXML+NSDictionary.h
Created February 27, 2012 09:07
Parse XML to NSDictionary using TBXML
#import "TBXML.h"
@interface TBXML (TBXML_NSDictionary)
+ (NSDictionary*)dictionaryWithXMLNode:(TBXMLElement*)element;
+ (NSDictionary*)dictionaryWithXMLData:(NSData*)data;
@end
@blakewatters
blakewatters / gist:1994289
Created March 7, 2012 16:44
iOS 5 Interface Builder, View Controller and ARC Best Practices

Now that the GateGuru team has been developing on the iOS 5 SDK for awhile, I thought I'd pull together some lessons learned.

  • Declare your IBOutlet and IBActions within the private category within your implementation file. This makes them visible to interface builder without cluttering up the external interfaces and leaking implementation details.
  • Declare your IBOutlet properties as (nonatomic, weak). The weak reference implies a non-owning reference and ARC will nil it as necessary.
  • Delegate properties should be (nonatomic, weak) as well.
  • The designated initializer for UIView's is initWithFrame: when initialized programmatically. When loaded from a Storyboard or custom Nib, it is initWithCoder:
  • The designated initializer for UIViewController's is initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil when initialized programmatically. It is initWithCoder: when loaded from a Storyboard or Nib.
@alloy
alloy / Instructions.md
Created June 28, 2012 12:56
Run iOS unit tests (in a Xcode workspace) when a file changes and *only* those tests related to the changed file. Also trims otest output and colors test results.