Skip to content

Instantly share code, notes, and snippets.

View dougalcorn's full-sized avatar

Doug Alcorn dougalcorn

View GitHub Profile
@dougalcorn
dougalcorn / irb
Created December 9, 2011 22:01
$in criteria in Mongoid
irb(main):062:0> base.in(:from_id => port_ids)
=> #<Mongoid::Criteria
selector: {:from_id=>"$in0d06b030-04d8-012f-18e7-388d1201202c5b932da1-04d8-012f-b944-388d1201202c"},
options: {},
class: Ccom::PortConnection,
embedded: false>
# that's a jacked up selector
# now not using the _id on the field name
@dougalcorn
dougalcorn / gist:1242310
Created September 26, 2011 14:05
Bash Prompt for Git Status
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
# Black 0;30 Dark Gray 1;30
# Blue 0;34 Light Blue 1;34
# Green 0;32 Light Green 1;32
@dougalcorn
dougalcorn / password.rb
Created September 22, 2011 20:27
Generate XKCD style passwords on OS X
#!/usr/bin/env ruby
number_of_words = ARGV[0].to_i
number_of_words ||= 4
dictionary = File.read('/usr/share/dict/web2a').split
words = []
until words.length == number_of_words do
word = dictionary[rand(dictionary.size)]
@dougalcorn
dougalcorn / gist:1212205
Created September 12, 2011 19:52
testing backbone models using the right backend endpoints
/* This is in SpecHelper.js */
$(function() {
beforeEach(function() {
this.addMatchers({
toRequest: function(expectedRequest) {
var actualRequest, name, value;
actualRequest = this.actual;
for (name in expectedRequest) {
value = expectedRequest[name];
@dougalcorn
dougalcorn / after_use.sh
Created July 6, 2011 15:19
~/.rvm/hooks/after_use for JRUBY_OPTS
case "$GEM_HOME" in
*jruby*)
# -J-Djruby.reify.classes=true
# JRUBY_OPTS="-J-Djruby.reify.classes=true -J-Xmx512M -J-XX:MaxPermSize=256m -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled" ; export JRUBY_OPTS
JRUBY_OPTS="-J-Xmx1024m -J-XX:MaxPermSize=256m " ; export JRUBY_OPTS
;;
esac
From 7b7505ad8836f6fa9e613a29534bb9536defea44 Mon Sep 17 00:00:00 2001
From: Doug Alcorn <dougalcorn@gmail.com>
Date: Wed, 11 May 2011 16:59:45 -0400
Subject: [PATCH] updating the few attribute types from value_class number to
measure [#13103329]
---
3-XML-Ref-Data/CCOM Reference Data.xml | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
@dougalcorn
dougalcorn / gist:842807
Created February 24, 2011 20:18
rvm jruby problem with scripts
$ bundle
/Users/dalcorn/.rvm/gems/jruby-1.5.6@mimosa2/bin/bundle: line 9: require: command not found
/Users/dalcorn/.rvm/gems/jruby-1.5.6@mimosa2/bin/bundle: line 11: version: command not found
/Users/dalcorn/.rvm/gems/jruby-1.5.6@mimosa2/bin/bundle: line 13: syntax error near unexpected token `('
/Users/dalcorn/.rvm/gems/jruby-1.5.6@mimosa2/bin/bundle: line 13: `if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then'
$ which bundle
/Users/dalcorn/.rvm/gems/jruby-1.5.6@mimosa2/bin/bundle
$ ls -l `which bundle`
-rwxr-xr-x 1 dalcorn staff 410 Feb 24 15:09 /Users/dalcorn/.rvm/gems/jruby-1.5.6@mimosa2/bin/bundle*
$ head `which bundle`
@dougalcorn
dougalcorn / active_model_initialize.rb
Created December 30, 2010 21:34
some template code using ActiveModel::MassAssignmentSecurity to initialize with hash
class Person
include ActiveModel::MassAssignmentSecurity
attr_accessor :name, :birthday, :handsomeness
attr_protected :handsomeness
def initialize(params = {})
self.attributes = params
end
@dougalcorn
dougalcorn / kit.rb
Created December 30, 2010 20:34
Non-trivial factory_girl with associations
Factory.define(:kit) do |f|
f.association :primary_palette, :factory => :palette # association doesn't match class name
f.association :secondary_palette, :factory => :palette
f.association :user, :factory => :user
f.sequence(:name) { |i| "Kit#{i}" }
f.bg_images { |images| [images.association(:attachment)] } # has_many assoc
f.default false
f.display_fonts { [Factory(:font), Factory(:font)] }
f.body_font { Factory(:font) }
end
@dougalcorn
dougalcorn / locateble.rb
Created December 23, 2010 18:03
Basic ruby blass with parts of an address that can be assembled into a string and geolocated with Google Maps api
GOOGLE_MAPS_API_KEY = "something"
# This is a plain old ruby class that assumes someone has give it the
# parts of an address. The end goal is to use Google to geolocate it
# and assign a lat/long
class Locateable
attr_accessor :street1, :street2, :city, :state, :country
attr_accessor :latitude, :longitude, :accuracy
# returns false if google was unable to geolocate the