Skip to content

Instantly share code, notes, and snippets.

View jnraine's full-sized avatar

Jordan Raine jnraine

View GitHub Profile
@jnraine
jnraine / gist:1075117
Created July 11, 2011 00:11
An early version of a Rails settings model
class Setting < ActiveRecord::Base
@@settings = {}
belongs_to :record, :polymorphic => true
validates_uniqueness_of :key
before_save :expire_cache
# Retrieve and cache a value for a key
@jnraine
jnraine / strings-as-booleans.java
Created February 7, 2012 22:04
Using strings as booleans in Java
/* The ugly way */
String isSomething = "true"
if ( "true".equals(isSomething) ) {
/* It takes me a couple seconds to figure out why I'm here */
}
/* The easy-to-read way */
String isSomething = true
@jnraine
jnraine / dict.js
Created March 20, 2012 16:59
Y U SO VERBOSE JAVA?
{"foo": "bar", "baz": "quux"}
@jnraine
jnraine / TimerMessageParser.java
Created October 23, 2012 16:17
Code Share I (October 25)
package ca.sfu.cq.util.filter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TimerMessageParser {
private String message;
public TimerMessageParser(String message) {
this.message = message;
@jnraine
jnraine / ticket.sh
Created October 7, 2014 00:15
Helper to open JIRA tickets from Terminal
# Usage:
# ticket <= opens ticket associated with the branch you're on (for branch clio-1234-fix-the-thing, opens CLIO-1234)
# ticket 5678 <= opens CLIO-5678
ticket () {
ticketNumber=$1
if [ "$ticketNumber" -eq "" ]
then
ticketNumber=$(git rev-parse --abbrev-ref HEAD | ruby -e "branch=gets.downcase;print branch.match(/^clio-(\d+)/)[1] if branch.start_with?('clio-')")
fi
if [ "$ticketNumber" -eq "" ]
@jnraine
jnraine / gem_loc.rb
Created April 27, 2019 22:33
Count lines of code per gem in your Gemfile
# gem_loc.rb
#
# Output require-able lines of code gems in your Gemfile
#
# Usage: rails runner <path to this file>
require "rails/code_statistics_calculator"
require "csv"
gem_specs = Bundler::LockfileParser.new(Rails.root.join("Gemfile.lock").read).specs.each(&:__materialize__)