Skip to content

Instantly share code, notes, and snippets.

View bmorton's full-sized avatar

Brian Morton bmorton

  • Microsoft
  • Oakland, CA
View GitHub Profile
@bmorton
bmorton / iTunes
Created March 14, 2011 17:56
iTunes workaround to keep it from launching with the play key
#!/usr/bin/env python
import sys, os, subprocess
launch = True
blocker = ""
apps = ["Vox", "VLC"]
ps = subprocess.Popen("/bin/ps -x", shell=True, stdout=subprocess.PIPE)
require 'rubygems'
require 'sinatra'
require 'active_record'
configure do
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'asides.sqlite3')
@bmorton
bmorton / gist:1055639
Created June 30, 2011 04:27
Google CDN with fallback
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="/public/scripts/libs/jquery-1.4.4.min.js"%3E%3C/script%3E'))</script>
@bmorton
bmorton / arduino.pde
Created August 3, 2011 07:10
Arduino Experiment
/*
* Set LED brightness by serial write
* An Arduino experiment
* by Brian Morton
*/
int ledPin = 9;
int brightness = 0;
void setup() {
@bmorton
bmorton / gist:1204251
Created September 8, 2011 18:42
4 iPhone Libraries

4 iPhone libraries to make your first iPhone app experience better

I've dabbled in countless iPhone examples, demo apps, and personal hacks. I've watched almost every WWDC session and iTunes U video about iOS. I constantly download apps from the App Store when I hear they do something cool or if they visually impress me. I feed off the libraries listed in others' legal sections listing out their licenses and attributing credit where credit is due.

And now I'm working on my first official, commercially-backed app. And it's not easy. Luckily, I've got somewhere to start. Plenty of people have solved the problems I've encountered. I can't even begin to thank them enough, but this is my attempt to give them the credit they deserve and spread the word on some great open source projects.

ASIHTTPRequest from All-Seeing Interactive

I've found that communicating with an API in an iPhone app requires a bit more than Apple provides in its base frameworks. ASIHTTPRequest fills that gap and provides a wrapper

@bmorton
bmorton / net_http_debug.rb
Created December 22, 2011 03:50 — forked from kaiwren/net_http_debug.rb
Enable debug for all Ruby HTTP requests
require 'net/http'
module Net
class HTTP
def self.enable_debug!
raise "You don't want to do this in anything but development mode!" unless Rails.env == 'development'
class << self
alias_method :__new__, :new
def new(*args, &blk)
instance = __new__(*args, &blk)
instance.set_debug_output($stderr)
@bmorton
bmorton / api_page_helper.rb
Created January 9, 2012 09:08 — forked from dblock/api_page_helper.rb
pagination helper with Grape
module ApiPageHelper
PAGINATE_OPTIONS = {
:default_page_size => 10
}
PAGINATE_PARAMS = [ "page", "offset", "size" ]
def paginate(coll, options = {})
options = PAGINATE_OPTIONS.merge(options)
if params[:page]
page = params[:page].to_i
size = (params[:size] || options[:default_page_size]).to_i
// as NSObject
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
[mapping mapKeyPath:@"numbers" toAttribute:@"orderedSet"];
TestMappable* object = [[[TestMappable alloc] init] autorelease];
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:@"application/json"];
id data = [parser objectFromString:@"{\"numbers\":[1, 2, 3]}" error:nil];
RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:data destinationObject:object mapping:mapping];
BOOL success = [operation performMapping:nil];
@bmorton
bmorton / application_with_config.rb
Created January 23, 2012 06:44 — forked from mislav/application_with_config.rb
Read custom config from settings.yml into a Rails 3 app
# needs the "hashie" gem in Gemfile
require 'erb'
module Movies
class Application < Rails::Application
# read from "settings.yml" and optional "settings.local.yml"
settings = ERB.new(IO.read(File.expand_path('../settings.yml', __FILE__))).result
mash = Hashie::Mash.new(YAML::load(settings)[Rails.env.to_s])
@bmorton
bmorton / ruby-debug19.markdown
Created January 23, 2012 23:00 — forked from amateurhuman/ruby-debug19.markdown
Install ruby-debug19 with ruby 1.9.3

Install ruby-debug19 with ruby 1.9.3

Download the following gems from http://rubyforge.org/frs/?group_id=8883

  • linecache19-0.5.13.gem

  • ruby-debug-base19-0.11.26.gem

    gem install ~/Downloads/linecache19-0.5.13.gem

You need to point to the directory with the Ruby header files (specifically method.h) and pass it with the gem install command. Should look something like: