Skip to content

Instantly share code, notes, and snippets.

View uhhuhyeah's full-sized avatar

David A McClain uhhuhyeah

View GitHub Profile
@uhhuhyeah
uhhuhyeah / custom_nsindexpath.m
Created November 24, 2010 00:55
How to create an index path
// {section index, row index}
unsigned indexes[2] = {0,0};
NSIndexPath *ip = [[[NSIndexPath alloc] initWithIndexes:indexes length:2] autorelease];
@uhhuhyeah
uhhuhyeah / dropbox-and-git.sh
Created November 29, 2010 23:31
Use Dropbox as a remote git repo
# Instructions for setting up a remote repo on Dropbox
# Assuming project/repo called 'myrepo'
cd ~/Dropbox
mkdir -p git/myrepo.git
cd !$
git --bare init
cd ~/development/uhy/myrepo
git remote add dropbox file://$HOME/Dropbox/git/myrepo.git
@uhhuhyeah
uhhuhyeah / template.rb
Created February 26, 2011 03:58
Gemfile for template
@git_repo = "https://github.com/uhhuhyeah/rails3_template"
# Remove unwanted files
run "rm public/index.html"
run "rm public/images/rails.png"
run "rm public/javascripts/rails.js"
run "rm app/views/layouts/application.html.erb"
# Grab standards gems
run "wget --no-check-certificate '#{@git_repo}/raw/master/Gemfile' -O Gemfile"
@uhhuhyeah
uhhuhyeah / ie_hack.js
Created April 8, 2011 18:21
Work around for select not working in laktek / jQuery-Smart-Auto-Complete in IE browsers
// Where 'fruits_field' is the id of the autocomplete field
// Note: Place this code after the smartAutoComplete() function
$('input#fruits_field').bind({
lostFocus: function(e) {
// Grab any highlighted results
results = $('.smart_autocomplete_highlight');
if (results && $(results[0]).text() != '') {
// Set the input's value to the selected result
@uhhuhyeah
uhhuhyeah / gist:1045026
Created June 24, 2011 15:30
rack-oauth raises 401, causes a 500
/!\ FAILSAFE /!\ Fri Jun 24 08:28:50 -0700 2011
Status: 500 Internal Server Error
401 Unauthorized
/Users/davidamcclain/.gem/ruby/1.8/gems/oauth-0.4.4/lib/oauth/consumer.rb:217:in `token_request'
/Users/davidamcclain/.gem/ruby/1.8/gems/oauth-0.4.4/lib/oauth/tokens/request_token.rb:18:in `get_access_token'
/Users/davidamcclain/.gem/ruby/1.8/gems/rack-oauth-0.1.5/lib/rack-oauth.rb:213:in `do_callback'
/Users/davidamcclain/.gem/ruby/1.8/gems/rack-oauth-0.1.5/lib/rack-oauth.rb:188:in `call'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/string_coercion.rb:25:in `call'
/usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/head.rb:9:in `call'
/usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/methodoverride.rb:24:in `call'
@uhhuhyeah
uhhuhyeah / gist:1045031
Created June 24, 2011 15:31
token_request method in oauth gem
# in ~/.gem/ruby/1.8/gems/oauth-0.4.4/lib/oauth/consumer.rb:196
def token_request(http_method, path, token = nil, request_options = {}, *arguments)
response = request(http_method, path, token, request_options, *arguments)
case response.code.to_i
when (200..299)
if block_given?
yield response.body
else
# symbolize keys
@uhhuhyeah
uhhuhyeah / gist:1045040
Created June 24, 2011 15:35
rescue_from in application_controller
class ApplicationController < ActionController::Base
include Rack::OAuth::Methods
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
rescue_from OAuth::Unauthorized, :with => :oauth_unauthorized
private
def record_not_found
render :file => File.join(RAILS_ROOT, 'public', '404.html'), :status => 404
@uhhuhyeah
uhhuhyeah / fb_connect_notes.md
Created January 31, 2012 05:33
Basics of (a basic) Facebook Connect integration

Basics of (a basic) Facebook Connect integration

Assuming we have registered an app with Facebook we need two things to get basic integration with Facebook Connect. A link so the user can trigger the auth request and an end-point for Facebook to send the user and their authorization/authentication credentials to.

Link

Add a link to https://graph.facebook.com/oauth/authorize passing as params our app_id, what permissions we want and what callback URL we want FB to hit on successful auth. The link would look a little like:

<a href="https://graph.facebook.com/oauth/authorize?client_id=1234567890&redirect_uri=https://modcloth.com/auth/facebook/callback&scope=publish_stream,offline_access,email,user_location,user_birthday">
@uhhuhyeah
uhhuhyeah / multiple.rb
Created February 23, 2012 15:56
I suck at Maths
# Is x a multiple of y?
x % y == 0
(1..100).each do |i|
is_multiple_of_3 = i % 3 == 0
is_multiple_of_5 = i % 5 == 0
if is_multiple_of_3 && is_multiple_of_5
puts "Fizzbuzz (#{i})\n"
elsif is_multiple_of_3
puts "Fizz (#{i})\n"
elsif is_multiple_of_5
puts "Buzz (#{i})\n"