Skip to content

Instantly share code, notes, and snippets.

View uhhuhyeah's full-sized avatar

David A McClain uhhuhyeah

View GitHub Profile
@uhhuhyeah
uhhuhyeah / outfitCollectionView.js
Created September 6, 2012 18:33
How do I test this?
window.app.OutFitCollectionView = Backbone.View.extend({
// redacted code for brevity...
render: function() {
this.collection.each(this.renderOutfit);
// redacted code for brevity...
return this;
},
@uhhuhyeah
uhhuhyeah / performance_metrics.md
Created June 16, 2012 00:11
Concepts used in browser-side performance testing

Outline

The purpose of this document is to outline the main metrics we use when discussing various end-user performance measurements such as "page speed".

Fig 1) A diagram we have been using in conversations to help illustrate the various events and how they inter-relate.

Events discussed

  • FIRST BYTE
  • DOC READY/DOM CONTENT EVENT
@uhhuhyeah
uhhuhyeah / meta.rb
Created April 4, 2012 21:25
Metaprogramming eg
# Permission based relations
# define admins, uploaders and guests associations via users
%w(admins uploaders guests).each do |method_name|
define_method(method_name) { self.memberships.where(role: method_name.singularize).collect(&:user) }
end
## vs...
def admins
self.memberships.where(role: :admin).collect(&:user)
@uhhuhyeah
uhhuhyeah / rvm_saddness.txt
Created March 21, 2012 19:37
rvm saddness
`rvm use #{ruby_version}@identity-service --create`
# Can't run this from the script. :(
# results in `RVM is not a function, selecting rubies with 'rvm use ...' will not work.`
# Is there something special about rvm that's going to prevent us from accessing it from within the script?
mc-identity-service (master *) λ type rvm | head -1
rvm is a function
mc-identity-service (master *) λ irb
1.9.3-p125 :001 > `type rvm | head -1`
(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"
@uhhuhyeah
uhhuhyeah / multiple.rb
Created February 23, 2012 15:56
I suck at Maths
# Is x a multiple of y?
x % y == 0
@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 / 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 / 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: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'