Skip to content

Instantly share code, notes, and snippets.

def binary_search(list, match, index = 0)
if list.empty?
-1
else
mid = list.length/2
case list[mid] <=> match
when 0
index + mid
when 1
binary_search(list[0...mid], match, index)

GitHub OAuth Busy Developer's Guide

This is a quick guide to OAuth2 support in GitHub for developers. This is still experimental and could change at any moment. This Gist will serve as a living document until it becomes finalized at Develop.GitHub.com.

OAuth2 is a protocol that lets external apps request authorization to private details in your GitHub account without getting your password. All developers need to register their application before getting started.

Web Application Flow

  • Redirect to this link to request GitHub access:
class User < ActiveRecord::Base
has_many :simple_oauths, :dependent => :destroy
accepts_nested_attributes_for :simple_oauths
validates_presence_of :username, :unless => :using_sso?
def using_sso?
!simple_oauths.empty?
require 'uri'
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
Given(/^a service implementation "([^\"]*)" exists with attributes "([^\"]*)" and first display variable named "([^\"]*)" and second display variable named "([^\"]*)"$/) do |class_name, attributes_string, first_display_var, second_display_var|
begin
klass = Object.const_get(class_name)
rescue NameError
klass = Object.const_set(class_name, Class.new(ServiceImplementation))
aux_variables = attributes_string.split(',').map { |x| x.strip.to_s }
require 'zip'
require 'zip/zipfilesystem'
require 'openssl'
require 'nokogiri'
class Ipa
attr_accessor :ipa_path, :package_name
def initialize(ipa_path)
@jamesdaniels
jamesdaniels / haha.rb
Created March 3, 2011 06:31
Oldest ruby file (of my own creation) I could locate on my hard-drive, dated 2/7/04 - man I was bad
#************************************** this will flip all the bits passed to it * * * * * * *
def flip(binary)
# replace 1 with 2, then 0 with 1, and then 2 with 0
return ((binary.tr("1","2")).tr("0","1")).tr("2","0")\
end
#************************************** adding implementation into the Integer class * * * * *
class Integer
def in_unsigned_binary(bits) #******* returns the unsigned binary form of the integer * * *
Nokogiri::HTML(open('http://hackerunderground.com/')).css('#the_puzzle').text.match(/\[(.+)\]/)[1].split.group_by(&:to_i).select{|k,v| v.size > 1}.map(&:first).select(&:prime?).first
@jamesdaniels
jamesdaniels / private.rb
Created June 27, 2011 15:24 — forked from joefiorini/private.rb
Indent methods under private?
class Blah
private
def method1
end
def method2
end
@jamesdaniels
jamesdaniels / Questions
Created July 13, 2011 15:42
Magma Rails Give-away
Day Job: Rails developer (freelance) and serial startup-cofounder
Open Source contribution (if any): a bundle, mostly focusing around Rails/OAuth/E-commerce
Tell me about your experience with Ruby/Rails: an intense love affair since 2004ish, only made rocky due to my running around with javascript
How do you use GitHub: with gusto?
Favorite luchador(es): strong bad
function savemyshitbro {
git stash
git checkout -b $1
git stash apply
git push origin $1
}
// $savemyshitbro BRANCH_NAME
// usage: savemyshitbro changes_to_something