Skip to content

Instantly share code, notes, and snippets.

@jdjkelly
jdjkelly / gist:3093536
Created July 11, 2012 21:05
Creating 400 test users with Facebook's test user API
require 'net/http'
require 'uri'
require 'open-uri'
400.times do
begin
http = Net::HTTP.new("graph.facebook.com", 443)
http.use_ssl = true
http.start do |http|
req = Net::HTTP::Get.new("/APPID/accounts/test-users?installed=true&name=josh&locale=en_US&permissions=xmpp_login&method=post&access_token=TOKEN")
@jdjkelly
jdjkelly / gist:3093546
Created July 11, 2012 21:06
Creating friendships between test users with Facebook's test user API
require 'net/http'
require 'uri'
require 'open-uri'
require 'crack/json'
http = Net::HTTP.new("graph.facebook.com", 443)
http.use_ssl = true
http.start do |http|
req = Net::HTTP::Get.new("/APPID/accounts/test-users?access_token=TOKEN&limit=500")
response = http.request(req)
@jdjkelly
jdjkelly / pitchfork_backbone.js
Created September 20, 2012 14:06
Core Pitchfork Backbone App
// This is the core part of Pitchfork.com's Backbone app.
// The autobahn object in particular is a great example of how to layer backbone on to a traditional, CMS-driven media site while maintaing server-side view rendering.
var p4k = window.p4k || {};
$(function() {
var a = p4k.core = p4k.core || {};
a.Task = function(c, b) {
this.fn = c;
this.initialize(b)
};
@jdjkelly
jdjkelly / gist:3836089
Created October 4, 2012 20:08
Build a JS array of properties from an object
buildArrayFromKeys: (keys, object) ->
arr = []
keys.forEach (i) ->
arr.push _.clone(object[i])
arr
@jdjkelly
jdjkelly / gist:4617102
Created January 24, 2013 02:17
Demonstrates how to make an OAuthd signed request to an endpoint by recreating the consumer via an OmniAuth strategy.
consumer = OmniAuth::Strategies::Yahoo.new(nil, consumer_key, consumer_secret).consumer
request_token = OAuth::RequestToken.new(consumer, token, secret )
token = OAuth::Token.new(token, secret )
access_token = request_token.get_access_token(:oauth_session_handle => self.session_handle, :token => token)
# Example OAuth signed API endpoint GET request
api_request = "http://social.yahooapis.com/v1/user/#{guid}/contacts"
response = access_token.get(api_request)
@jdjkelly
jdjkelly / gist:4625106
Last active December 11, 2015 16:08
Demonstrates a strategy for refreshing an access token using an OmniAuth provider class inherited from OAuth2
client = OmniAuth::Strategies::Windowslive.new( nil, windowslive_app_id, windowslive_app_consumer_secret).client
@access_token = OAuth2::AccessToken.new(client, refresh_token)
@access_token.refresh!
# Example API endpoint request
api_request_url = "https://apis.live.net/v5.0/me/contacts"
access_token.request(:get, api_request_url)
@jdjkelly
jdjkelly / gist:4728352
Last active December 12, 2015 06:19
Binary search on sorted array of ints
binarySearch = (array, key) ->
lo = 0
hi = array.length -1
while lo <= hi
mid = lo + (hi - lo) /2
if(key < array[mid]
hi = mid - 1
else if key > array[mid]
lo = mid + 1
else
controller =
###
From HTML5Rocks
Even if you connect the gamepad, it won't manifest itself in any way unless the user
presses any of its buttons first. This is to prevent fingerprinting, although proves to be
a bit of a challenge for user experience: you can't ask the user to press the button or
provide gamepad-specific instructions because you have no idea whether they connected
their controller.
Chrome's implementation of the API exposes a function – navigator.webkitGetGamepads() –
@jdjkelly
jdjkelly / gist:5200375
Last active November 26, 2017 03:07
Rails 3 – Setting Up Guard with Rspec and Spork with Growl Notifications in OSX

Gemfile:

group :development do
  gem 'rspec-rails'
  gem 'guard'
  gem 'guard-rspec'
end

group :test do

gem 'rspec'