Skip to content

Instantly share code, notes, and snippets.

View mynameisrufus's full-sized avatar

Rufus Post mynameisrufus

View GitHub Profile
}else if(this.options.position.length){
if(typeof(this.options.position[1]) == 'string') {
var topFinal = this.options.position[1];
} else {
var top = $value(this.options.position[1]) + $value(this.options.offsetTop);
var topFinal = (container_dimensions.height <= viewport_dimensions.height) ? (this.options.constrainToViewport ? Math.max(0,Math.min(viewport_dimensions.height - (container_dimensions.height),top)) : top) + 'px' : 0;
}
if(typeof(this.options.position[0]) == 'string') {
var leftFinal = this.options.position[0];
} else {
Model.first.attributes.each{|k,v| puts "\s\s#{k} { #{v} }"}; nil
class User < ActiveRecord::Base
scope :order, lambda{|params|
return if params.nil?
order = []
params.split(/\|/).each do |param|
order << param.gsub(/_asc/, ' ASC').gsub(/_desc/, ' DESC')
end
{:order => order.join(' ,')}
}
end
[0, 4, 3, 2, 1].each do |order|
score = scores.fetch(order)
@mynameisrufus
mynameisrufus / gist:668349
Created November 8, 2010 21:59
Hubris Open4 example
def self.noisy(str)
pid, stdin, stdout, stderr = Open4.popen4 str
puts "running #{str}\n"
# puts "Status: #{status.exitstatus}"
# puts "#{pid} done"
msg =<<-"EOF"
@mynameisrufus
mynameisrufus / gist:670561
Created November 10, 2010 08:43
Staging branch
# deploy from sha1
IO.popen("git rev-parse HEAD").read.gsub(/\W/,'')
# deploy from branch name
IO.popen("git rev-parse --abbrev-ref HEAD").read.gsub(/\s/,'')
@mynameisrufus
mynameisrufus / gemfile.rb
Created December 1, 2010 23:13
os specific gems
group :test do
gem 'guard'
gem 'guard-rspec'
if RUBY_PLATFORM =~ /linux/
gem 'rb-inotify'
gem 'libnotify'
end
if RUBY_PLATFORM =~ /darwin/
after_save :remove_erroneous_record
def remove_erroneous_record
self.destroy if created_in_error?
end
def created_in_error?
referral_outcome == "Created in Error"
end
@mynameisrufus
mynameisrufus / new.rb
Created January 7, 2011 09:39
Rails3 app template (jQuery, RSpec, Cucumber, Machinist, Devise)
# Run using $ rails new [appname] -JT -m new.rb
# GEMS
gem 'rails', '3.0.3'
gem 'compass', '0.10.6'
gem 'devise', '1.1.5'
gem 'cancan', '1.4.1'
# unversioned gems
@mynameisrufus
mynameisrufus / db_backup.sh
Created February 9, 2011 03:05
Postgres backup script (rails focused)
# Postgres backup script
# mynameisrufus
#
# Cron tab examples:
#
# daily keeping the last 5 days (run at 1:00AM, 2 minutes after the hour)
#
# 02 1 * * * postgres /script/db_backup.sh daily /var/backups/db $DATABASE_OWNER 5 >> /var/backups/db/backup.log 2>&1
#
#