Skip to content

Instantly share code, notes, and snippets.

View sj26's full-sized avatar
🤹‍♂️

Samuel Cochran sj26

🤹‍♂️
View GitHub Profile
/*
TrafficCop
Author: Jim Cowart
License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license)
Version 0.1.0
*/
(function($, undefined) {
var inProgress = {};
@sj26
sj26 / array-pluck.rb
Created December 9, 2011 03:05
Gather values from an array of hashes
class Array
def pluck key
map { |hash| hash[key] }
end
end
[{:number => "1"}, {:number => "2"}, {:number => "3"}].pluck(:number)
# => ["1", "2", "3"]
gem 'chronic_duration'
@sj26
sj26 / example_client.rb
Created December 14, 2011 13:35
HTTParty extensions
class ExampleClient
include HTTParty
extend HTTPExceptions
parser Class.new HTTParty::Parser
parser.send :include, PresentParser
parser.send :include, MashedParser
end
@sj26
sj26 / chargify.rb
Created December 14, 2011 13:39
Yet Another Chargify HTTParty-based API gem for Ruby
require 'httparty'
# This may go away:
require 'active_support/all'
# (doesn't *require* Rails, but adds some niceties)
module Chargify
VERSION = "0.0.1".freeze
# Create a default `Client`, attempting to use Rails application config.
def self.client options=nil
@sj26
sj26 / _form.html.haml
Created December 15, 2011 01:49
Handle natural-language duration inputs with ChronicDuration.
= semantic_form_for @my_model do |f|
= f.inputs do
= f.input :interval_duration
= f.buttons
@sj26
sj26 / fizzbuzz.rb
Created December 18, 2011 10:16
I can FizzBuzz
#!/usr/bin/env ruby -rubygems -ractive_support/all
# The one everyone writes
(1..100).each do |number|
if number % 15 == 0
puts "FizzBuzz"
elsif number % 3 == 0
puts "Fizz"
elsif number % 5 == 0
puts "Buzz"
@sj26
sj26 / site.nu
Created December 18, 2011 10:37
Vico site
# Window quit key binding
((ViMap normalMap) map:"<ctrl-w><ctrl-q>" to:"<esc>:quit<enter>")
@sj26
sj26 / jquery.countdown.js
Created January 2, 2012 11:07
jQuery countdown counter
(function ($) {
formatDuration = function(seconds) {
var duration = '',
days = Math.floor(seconds / 86400),
hours = Math.floor(seconds / 3600) % 24,
minutes = Math.floor(seconds / 60) % 60,
seconds = seconds % 60;
if (days)
duration = days + ' day' + (days > 1 ? 's' : '') + ', ';
$ rake routes
security_foo GET /security(.:format) {:controller=>"security", :action=>"foo"}