Skip to content

Instantly share code, notes, and snippets.

Jamie Wilkinson jamiew

Block or report user

Report or block jamiew

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:133
def what_is_gist
"A bad ass version-able pastebin"
This is sorta cool I guess?
jamiew / git-latest
Created Nov 7, 2014
"git latest" command will show you all branches by last-updated date
View git-latest
for ref in $(git for-each-ref --sort=-committerdate --format="%(refname)" refs/heads/ refs/remotes ); do git log -n1 $ref --pretty=format:"%Cgreen%cr%Creset %C(yellow)%d%Creset %C(bold blue)<%an>%Creset%n" | cat ; done | awk '! a[$0]++'
View ActiveRecord create_or_update.rb
# wise's mod, from:
# original from Rails Spikes:
def self.create_or_update(options = {})
id = options.delete(:id)
conditions = options.delete(:conditions)
record = id ? find_by_id(id) : find(:first, :conditions => conditions) || new
options.each_pair { |key, value| record[key] = value }
jamiew / no javascript tooltips.css
Created Aug 25, 2008
modern browsers don't need javascript for tooltips. js for legacy is easy enough
View no javascript tooltips.css
a.tip {position: relative;}
a span.tip-content,
a span.tip-bottom {
position: absolute;
width: 273px;
padding: 20px 50px 5px 20px;
bottom: 48px;
jamiew / lazily calculated mixin.rb
Created Aug 22, 2008
Allows attributes to be declared as lazy, meaning that they won't be # computed until they are asked for
View lazily calculated mixin.rb
# pseudoforked from mojombo:
# Before you ask--yes, this has a very specific use case and is not
# generally applicable to the problem of fine-grained lazy evaluation.
# But it does *exactly* what I need it to do. =)
# Allows attributes to be declared as lazy, meaning that they won't be
# computed until they are asked for. Just mix this module in:
# class Foo
View gist:7383
# never render the full layout if it's an XmlHttpRequest
class ApplicationController < ActionController::Base
def render(*args)
args.first[:layout] = false if request.xhr? and args.first[:layout].nil?
View rails beta invitations.rb
## from railscasts:
# models/invitation.rb
belongs_to :sender, :class_name => 'User'
has_one :recipient, :class_name => 'User'
validates_presence_of :recipient_email
validate :recipient_is_not_registered
validate :sender_has_invitations, :if => :sender
jamiew / passenger_status.rb
Created Oct 31, 2008 — forked from dan-manges/passenger_status.rb
munin plugin for Passenger Phusion process stats
View passenger_status.rb
#!/usr/bin/env ruby
# put in /etc/munin/plugins and restart munin-node
# by Dan Manges,
# NOTE: you might need to add munin to allow passwordless sudo for passenger-memory-stats
def output_config
puts <<-END
graph_category App
graph_title passenger status
graph_vlabel count
View ActiveRecord: delete duplicate entries.rb
def delete_dups_for(model, collect_by)
keep_array = { |h,k| h[k] = [] }
delete_array = []
model_name =
all_objects = model.all.reverse #so we add newest first, sort of
pbar =, all_objects.count)
all_objects.each do |obj|
if detect_dup((keep_array[obj.send(collect_by)]), obj).nil?
keep_array[obj.send(collect_by)] << obj
View Retrospectiva SVN changeset sync.rb
def sync_changesets
latest_changeset = changesets.find(:first, :select => 'revision', :order => 'revised_at DESC')
start = latest_changeset ? latest_changeset.revision.to_i + 1: 1
stop = latest_revision
return if start > stop
Changeset.transaction do
You can’t perform that action at this time.