Skip to content

Instantly share code, notes, and snippets.

View jasonkarns's full-sized avatar
🏠
Working from home

Jason Karns jasonkarns

🏠
Working from home
View GitHub Profile
@jasonkarns
jasonkarns / ar_model_spec.rb
Created October 25, 2011 19:19
each_subjects
describe ArModel do
context "when active" do
subject { ArModel.active }
each_subjects(:status_code) { should eql('ACTIVE') }
end
end
# This script greps the code base for all associations with an explicit foreign_key.
# For each defined association, it attempts to infer the foreign_key using our inflection rules.
# If the inferred foreign_key matches the explicit foreign_key, then the foreign_key declaration can be removed.
# If not, then there is the potential that the inflection can be added to config/initializers/inflections
# (unless it is an exception to an already-defined initializer inflection)
# USAGE: run from the command line
# $ ruby find_redundant_foreign_keys.rb
root = File.expand_path(File.dirname(__FILE__) + '/../')
@jasonkarns
jasonkarns / movie_rename.rb
Created March 10, 2012 18:13
Rename your movie folders.
require 'rubygems'
require 'cgi'
require 'json'
movies = Dir.open(".").select do |f|
File.directory?(f) && !f.match(/\..*/)
end
movies.each do |movie|
print "."
@jasonkarns
jasonkarns / rgb.js
Created May 14, 2012 02:26
Parse RGB colors
var color = {
RGB : function(){
// if (!(this instanceof color.RGB)) {
// return new color.RGB.apply(this, arguments);
// }
var rgb;
if(arguments.length === 1){
rgb = (typeof arguments[0] === 'string')? color.RGB.parse(arguments[0]) : arguments[0];
@jasonkarns
jasonkarns / version.rb
Created October 8, 2012 17:11
Improved ::VERSION pattern for gems?
module MyGem
module VERSION
MAJOR=0
MINOR=0
PATCH=1
PRE="beta"
def self.to_s
[MAJOR, MINOR, PATCH, PRE].compact.join(".")
@jasonkarns
jasonkarns / post-checkout
Created November 6, 2012 04:30
Post Checkout git hook to remind me about running certain commands when appropriate files have been modified
#!/bin/sh
if git diff-tree --name-only --no-color -r -m $1 $2 | fgrep -e 'Gemfile' >/dev/null 2>&1
then
echo "\nGemfile modified: run \`bundle install\`\n"
fi
if git diff-tree --name-only --no-color -r -m $1 $2 | fgrep -e 'db/migrate' -e 'db/schema.rb' -e 'db/structure.sql' >/dev/null 2>&1
then
echo "\nSchema modified: run \'rake db:migrate\'\n"
fi
@jasonkarns
jasonkarns / my_class.rb
Created November 18, 2012 18:23
AOP Logging
require 'aquarium'
require 'my_logger'
class MyClass
include MyLogger
def some_method
...
end
@jasonkarns
jasonkarns / readme.md
Last active March 11, 2024 23:26
Git send-email using Gmail
  1. Configure git.
# ~/.config/git/config
[sendemail]
  confirm = auto
  smtpServer = smtp.gmail.com
  smtpServerPort = 587
  smtpEncryption = tls
  smtpUser = <gmail email address>
@jasonkarns
jasonkarns / fb.js
Last active December 16, 2015 19:59
Facebook's JS SDK doesn't support registering multiple 'ready' handlers. So here's an implementation inspired by Twitter's SDK. (uses underscore)
window.fb = (b = { _e: [], ready: function(f){ b._e.push(f); } });
window.fbAsyncInit = function() {
fb.ready = function(f){ f(); };
_.invoke(fb._e, 'call');
};
fb.ready(function(){ console.info("facebook sdk loaded"); });
@jasonkarns
jasonkarns / partialObject.underscore.js
Last active December 16, 2015 22:09
Instead of partially applying parameters to a function, partially apply properties on a plain old javascript object.
_.partialObject = function(func, partial_object) {
return function(object) {
return func.call(this, _.extend({}, partial_object, object));
};
};