Skip to content

Instantly share code, notes, and snippets.

View nevans's full-sized avatar

nicholas a. evans nevans

View GitHub Profile
use master
drop database activerecord_unittest
drop database activerecord_unittest2
go
create database activerecord_unittest
go
create database activerecord_unittest2
go
use activerecord_unittest
go
@nevans
nevans / compact_progress_bar_formatter.rb
Created December 1, 2008 05:41
compact progressbar for rspec
require 'spec/runner/formatter/base_text_formatter'
require 'progressbar'
module Spec
module Runner
module Formatter
class CompactProgressBarFormatter < BaseTextFormatter
# Threshold for slow specs, in seconds.
# Anything that takes longer than this will be printed out
THRESHOLD = 0.25
@nevans
nevans / gist:51068
Created January 23, 2009 16:31 — forked from pjb3/gist:50340
# I didn't like the original for two reasons:
# 1) joining strings into a regex with "|" smells like a future bug to me
# (unless you will never match on anything containing '|')
# 2) always using regex smells to me. why not leave that decision to the
# user of this method? I offer two alternatives, based on === and ==.
# 3) this might be premature optimization, but I've skipped the map step
# to save memory and time in calling methods that may not be used.
# true if any fields of this object match any of the values
# (implicitly converting values to case insensitive Regexp, as in original)
@nevans
nevans / README
Created October 2, 2009 15:33
cucumber RailsLoggerFormatter
Works with cucumber 0.3.104. Earlier versions of
cucumber use a slightly different formatter API,
and will require small tweaks to make this work.
cd ~/tmp
# current bundler (0.6.0) has a different bug, so I'm using github master version
git clone git://github.com/wycats/bundler
cd bundler
git rev-parse HEAD # => 4907696811a73211aaded4f6ba03cbc45898769b
rake install
cd ..
rails test_gem_bundler
@nevans
nevans / -why?.txt
Created November 4, 2009 16:48
Why is rvm re-ordering my $PATH?
Why is rvm re-ordering my $PATH?
I can understand it placing its own dirs
on the front of the path... but why have
items 1-7 been shuffled below items 8-13?
(And no, I don't know why the /opt/local
dirs are there both with and without the
trailing slash. I'll clean that up.)
@nevans
nevans / ruby1.8.6-permutations.rb
Created January 13, 2010 21:27
Array#permute in ruby
class Array
def permute
return Array(first).map {|e| [e] } if length == 1
Array(first).inject([]) {|a,e|
Array(self[1..-1]).permute.each {|p|
a << [e] + p
}
a
}
end
@nevans
nevans / Gemfile
Created March 9, 2010 20:14
bug in vegas 0.1.4, ruby 1.8.6
source :rubygems
gem "vegas", "~> 0.1.4"
gem "rack", "~> 1.1.0"
gem "mongrel", "~> 1.1.5"
@nevans
nevans / gist:330603
Created March 12, 2010 18:37
disk space for backups
mount |
awk '/ext3/{ print $3 }' |
grep -v '/tmp' |
xargs df |
awk 'NR==1{next}
$4~/%/{ print "+ "$2" ("$5")"; SUM += $2 }
$5~/%/{ print "+ "$3" ("$6")"; SUM += $3 }
END { print "=> " SUM/1024/1024 }'
@nevans
nevans / gist:330605
Created March 12, 2010 18:40
what IPs are trying to hack my server
sudo last -i -f /var/log/btmp |
awk '{ per[$3] += 1 } END { for (i in per) print per[i], i }' |
sort -n |
tail -15