Skip to content

Instantly share code, notes, and snippets.

@devpuppy
devpuppy / nokogiri libxml homebrew lion
Created November 8, 2011 23:26
How to fix: Nokogiri was built against LibXML version 2.7.3, but has dynamically loaded 2.7.8
FIXME:
WARNING: Nokogiri was built against LibXML version 2.7.3, but has dynamically loaded 2.7.8
or
libxml_ruby.bundle: dlsym(0x10fde1900, Init_libxml_ruby): symbol not found
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
@devpuppy
devpuppy / kwurry_talk.rb
Last active November 19, 2019 21:50
RubyConf Kwurry Lightning Talk
# currying
add = ->(a, b) {
a + b
}
add_two = add.curry.(2)
# => #<Proc:0x00007f911d0962c0 (lambda)>
add_two.(1)
# => 3
@devpuppy
devpuppy / diffedit.sh
Created November 14, 2013 22:12
alias diffedit
# subl . + all files that have been edited in this branch
# your $EDITOR may vary
alias diffedit="(echo '.' && git diff --name-only `git merge-base origin/master HEAD`) | xargs subl"
@devpuppy
devpuppy / hmap_perf.rb
Last active December 1, 2015 19:44
perf comp of Hash#hmap implementations
require 'benchmark/ips'
# hash.size # 1000
# hash.values.flatten.size # 500500
def a_big_hash
{}.tap do |h|
1.upto(1000) { |i| h[i.to_s.to_sym] = 1.upto(i).to_a }
end
end
@devpuppy
devpuppy / user_dot_trebuchet_spec.rb
Created November 26, 2012 17:40
How to stub user.trebuchet to always return true for any feature
# as a one-liner to use in an rspec example
@user.stub(:trebuchet).and_return(double(@user.trebuchet, :launch? => true))
# more verbose example
it "should stub user.trebuchet" do
@user = Factory(:user)
@user.trebuchet.launch?("something ridiculous").should be_false
enthusiastic_trebuchet = double(@user.trebuchet, :launch? => true)
@user.stub(:trebuchet).and_return(enthusiastic_trebuchet)
@devpuppy
devpuppy / airbrake_to_csv.rb
Created January 25, 2012 21:23
Airbrake exporter + stats
# code at http://gist.github.com/3350
# tests at http://gist.github.com/3354
require 'rubygems'
require 'active_resource'
require 'time'
class Hoptoad < ActiveResource::Base
self.site = "https://YOUR_ACCOUNT.hoptoadapp.com"
class << self
@devpuppy
devpuppy / factory.rb
Created December 12, 2010 21:26
trick to load factories from subdirectories of test/factories
# will go three levels deep to find Factory definitions within subdirectories of test/factories
path = Rails.root.join('test/factories')
levels = 3
subdirectories = Dir[File.join(path, '*')].select {|name| File.directory?(name) }
(levels - 1).times do
subdirectories.each do |subdirectory|
subdirectories += Dir[File.join(subdirectory, '*')].select {|name| File.directory?(name) }
end
@devpuppy
devpuppy / .bash_profile
Created March 14, 2010 21:19
.bash_profile
PATH=$PATH:/opt/local/bin
export PATH
alias be='mate -w ~/.bash_profile;source ~/.bash_profile'
# alias ss='script/server'
# alias sc='script/console'
alias rdm='rake db:migrate'
alias glg='gem list |grep'
alias rrg='rake routes |grep'
@devpuppy
devpuppy / .autotest
Created March 12, 2010 21:04 — forked from dust3d/gist:330740
.autotest
# on Ruby 1.9.1...
# gem install test-unit -v 1.2.3
# gem install autotest redgreen autotest-fsevent autotest-rails ZenTest autotest-growl
require 'redgreen'
Autotest.send(:alias_method, :real_ruby, :ruby)
Autotest.send(:define_method, :ruby) do |*args|
real_ruby + %[ -rrubygems -e "require 'redgreen'" ]
end
def disable_rubygems; nil; end
def source(s); $src = s unless s[/gemcutter/] end
def gem(n, v)
if Hash === v
$stderr.puts "ignoring git gem #{n}"
return
end
puts "#{n} --version '#{v}' #{$src ? " -s#{$src}": ""}"
end
load ARGV[0] || "Gemfile"