Skip to content

Instantly share code, notes, and snippets.

View justincampbell's full-sized avatar
🌯
🍩

Justin Campbell justincampbell

🌯
🍩
View GitHub Profile
---
:update_sources: true
:sources:
- http://rubygems.org/
- http://gemcutter.org
gem: --no-ri --no-rdoc
:verbose: true
:backtrace: false
:benchmark: false
:bulk_threshold: 1000
@justincampbell
justincampbell / console.log
Created November 1, 2011 01:54
ruby/xcode issue
Last login: Mon Oct 31 21:45:40 on ttys000
~$ bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
Cloning into rvm...
remote: Counting objects: 5846, done.
remote: Compressing objects: 100% (2786/2786), done.
remote: Total 5846 (delta 3840), reused 4144 (delta 2306)
Receiving objects: 100% (5846/5846), 1.95 MiB | 2.32 MiB/s, done.
Resolving deltas: 100% (3840/3840), done.
RVM: Shell scripts enabling management of multiple ruby environments.
@justincampbell
justincampbell / date_grouping.rb
Created November 2, 2011 13:22
Date grouping pseudocode
last_date_header = nil
# Items should be sorted by date already
for item in items
if last_date_header != item.date
# Output item.date
last_date_header = item.date
end
# Output item
@justincampbell
justincampbell / hash_benchmark.rb
Created November 30, 2011 17:10
Benchmark for creating unique ids (appended to unix timestamp)
require 'benchmark'
require 'digest/md5'
require 'digest/sha1'
require 'zlib'
n = ARGV[0] ? ARGV[0].to_i : 100_000
input = ARGV[1] || ENV.inspect
puts "#{n} times, #{input.size} characters"
@justincampbell
justincampbell / asterisk_watchdog.sh
Created December 11, 2011 17:32
Asterisk watchdog script
#!/bin/bash -x
DIR=/tmp/watchdog
# Create dir if it doesn't exist
if [ ! -d $DIR ]; then
mkdir $DIR
fi
cd $DIR
#Ashton
is: a
!douchebag
def event(type, message)
events type, [message]
end
def events(type, messages)
messages.map! { |message| envelope type, message }
suppress_redis_errors do
redis.pipelined do
while messages.any?
@justincampbell
justincampbell / .rvmrc
Created January 12, 2012 19:31
GCC + RVM
CC=/usr/bin/gcc-4.2
if [ -x $CC ]; then
export CC
fi
rvm 1.9.3@project --create --install
rvm_project_rvmrc_default=1
@justincampbell
justincampbell / contact.rb
Created January 23, 2012 14:59
Rails Contact Form
class Contact
include ActiveModel::Validations
validates_presence_of :name, :subject, :body
validates :email,
:presence => true,
:format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i }
validates :verify,
@justincampbell
justincampbell / ability_spec.rb
Created February 9, 2012 20:25
CanCan Ability Spec
require 'spec_helper'
describe Ability do
let(:admin_user) { mock AdminUser }
it { Ability.should include(CanCan::Ability) }
it { Ability.should respond_to(:new).with(1).argument }
context "admin" do
before :each do