Skip to content

Instantly share code, notes, and snippets.

View jamesarosen's full-sized avatar

James A Rosen jamesarosen

View GitHub Profile
@jamesarosen
jamesarosen / shed_resource.js
Created August 24, 2011 01:52 — forked from mattetti/sc-simple-ds.js
Shed.Resource
(function(window) {
Shed.Resource = SC.Object.extend({
fetch: function() {
if (!this.hasFetched) {
this.hasFetched = true;
var self = this;
this.deferedFetch = $.getJSON(this.resourceURL())
.done(function(json) {
self.set('data', self.constructor.parse(json));
require 'benchmark'
class Object
def either?(*args)
args.include? self
end
def in?(*args)
case args.length
when 0
false
module Rack
class Lockdown
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
if ["GET", "HEAD"].include?(request.request_method)
config.action_controller.asset_host = Proc.new do |source, request|
non_ssl_host = "http://asset#{source.hash % 4}.backpackit.com"
ssl_host = "https://asset1.backpackit.com"
if request.ssl?
case
when source =~ /\.js$/
ssl_host
when request.headers["USER_AGENT"] =~ /(Safari)/
non_ssl_host
@jamesarosen
jamesarosen / .rspactor
Created February 26, 2010 20:18 — forked from mislav/.rspactor
# this goes in the $HOME dir
# needs mislav-rspactor v0.3.2 and RSpec 1.2
RSpactor::Runner.class_eval do
alias old_formatter_opts formatter_opts
def formatter_opts
# update this path to where you saved unicode_formatter.rb
old_formatter_opts + " -r /Users/mislav/Projects/unicode_formatter -f UnicodeFormatter"
end
end
class TwitterSettingsController < ApplicationController
ssl_required :edit, :enable, :oauthorized
before_filter :require_user
def edit
end
def enable
@request_token = oauth_consumer.get_request_token(:oauth_callback => oauthorized_twitter_url)
session[:oauth_token] = @request_token.token
class TwitterSettingsController < ApplicationController
ssl_required :edit, :enable, :oauthorized
before_filter :require_user
def edit
end
def enable
@request_token = oauth_consumer.get_request_token(:oauth_callback => oauthorized_twitter_url)
session[:oauth_token] = @request_token.token
@jamesarosen
jamesarosen / round_to_precision.rb
Created January 27, 2010 13:15 — forked from bcardarella/round_to_precision.rb
Float#round_to_precision
class Float
# Takes a fraction and will round a float to the nearest multiple
# >> k = 0.4
# >> k.round_to_fraction
# => 0.5
# >> k = 0.75
# >> k.round_to_fraction
# => 1.0
# >> k.round_to_fraction(0.65)

GitHub Javascript Strategy

Unless otherwise necessary (such as mobile development), the GitHub javascript codebase is based off jQuery. You can safely assume it will be included on every page.

File naming

  • All jquery plugins should be prefixed with jquery, such as jquery.facebox
  • All github-specific jquery plugins should be prefixed with jquery.github. Like jquery.github.repo_list.js
  • All page-specific files (that only run on ONE page) should be prefixed with page. page.billing.js
@jamesarosen
jamesarosen / people_controller.rb
Created September 25, 2009 17:45 — forked from technicalpickles/example.json.rb
using plain ole' Ruby as a Rails TemplateHandler
class PeopleController < ActionController::Base
def index
respond_to do |format|
format.jqa
end
end
end