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 / 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 / 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 / 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 / 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 / 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 "."
# 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 / 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
@jasonkarns
jasonkarns / fiddle.css
Created June 29, 2011 19:07
Map Tooltips
#map{
background:url(/_layouts/images/advics.internet.branding/map.png) #FFFFFF;
height:448px;
position:relative;
}
#map ul {
list-style:none;
}
.maplocation {
position:absolute;
CmdUtils.makeBookmarkletCommand({
name: "radbox",
url: "javascript:function%20addvid(){var%20d=document,%20z=d.createElement(%27scr%27+%27ipt%27),%20b=d.body;try%20{if(!b)%20throw(0);r=Math.floor(Math.random()*100+1);z.setAttribute(%27src%27,%20%27http://radbox.me/init/static/add.js?r=%27+r.toString());b.appendChild(z);}%20catch(e)%20{alert(%27Please%20wait%20until%20the%20page%20has%20loaded.%27);}}if(window.location.hostname.search(%27radbox%27)%20==%20-1)%20{addvid();}%20else%20{alert(%27You%20cannot%20use%20this%20bookmarklet%20in%20Radbox.%27);}void(0);"
})
@jasonkarns
jasonkarns / YQL.html
Created December 15, 2010 06:01
Sample YQL demo
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>YQL</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
//<![CDATA[
(function($){