Skip to content

Instantly share code, notes, and snippets.

View jamesarosen's full-sized avatar

James A Rosen jamesarosen

View GitHub Profile
require 'casrack'
use CasrackTheAuthenticator::Simple, :cas_server => "http://cas.mycompany.com/cas"
/* this CSS stylesheet uses some icons from the
wonderful Silk icon set, available at
http://www.famfamfam.com/lab/icons/silk/
*/
/* COLORS */
form .error input, form .error select, form .error textarea {
border-color: #cc0000;
}
@jamesarosen
jamesarosen / application.js
Created November 13, 2009 21:04
Push Javascript functionality to static files called with dynamic parameters
// put the view editing Javascript logic in a static .js file:
MyApp = {
onCreateReview: function(flash, newReviewsCount, reviewPartial) {
$("#new_review").before('<div id="flash_notice">' + flash + '</div>');
$("#reviews_count").html(newReviewsCount);
$("#reviews").append(reviewPartial);
$("#new_review")[0].reset();
}
};
# from http://missingfeature.com/scheduling-crons-with-delayedjob?c=1
class DjCron
def self.step(action, period, change = {})
next_at = Time.now.change(change) + period
puts "Performing #{action.to_s} and rescheduling at #{next_at.to_s}"
self.reschedule_at(next_at, action, period, change)
end

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 / i_rack.rb
Created December 11, 2009 12:48
Hilariously awful joke by Nick Quaranto
# Hilariously awful joke by Nick Quaranto
# taken from http://www.httpstatusok.com/#46
class I::Rack
def initialize(app)
@app = app
end
def call(env)
@jamesarosen
jamesarosen / build_options.yml
Created January 17, 2010 16:49
Bundler build_options for binary gems
mysql:
mysql-dir: /usr/local/mysql
mysql-lib: /usr/local/mysql/lib
mysql-include: /usr/local/mysql/include
pg:
pgsql-include: /Library/PostgreSQL/8.4/include
with-pgsql-lib: /Library/PostgreSQL/8.4/lib
@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)
@jamesarosen
jamesarosen / Gemfile-original.rb
Created February 3, 2010 17:02
Having some trouble with Bundler
# Edit this Gemfile to bundle your application's dependencies.
git "git://github.com/rails/arel.git"
git "git://github.com/rails/rack.git"
source :gemcutter
gem "rails", :git => "git://github.com/rails/rails.git"
gem "sqlite3-ruby"
gem 'redgreen', '~> 1.2.2', :only => :test
@jamesarosen
jamesarosen / degrading_html5_range_helper.rb
Created February 11, 2010 17:02
An HTML5 range input that degrades gracefully
# The goal is to create a "rating" tag. It should use the <input type='range'>
# tag from HTML5 if available, but degrade to something usable if not.
#
# An alternative to this would be some sort of Javascript-based
# progressive-enhancement. I think that might actually be preferable,
# but I can't quite envision it yet. Perhaps you'd like to fork this Gist and
# add a JS version?
def range_tag(name, range, options = {})
if browser_supports_html5_range?
options.reverse_merge!({