Skip to content

Instantly share code, notes, and snippets.

@Peeja
Peeja / gist:5831155
Created June 21, 2013 13:33
"The goggles, they do nothing!" `rake db:test:prepare` appears to have become `rake test:prepare` in Rails 4, but the old task still exists and does nothing. http://stackoverflow.com/q/17150529/4937
$ rake --trace db:test:prepare
** Invoke db:test:prepare (first_time)
** Execute db:test:prepare
$ rake --trace test:prepare
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
@Peeja
Peeja / readable_big_decimal.rb
Last active December 18, 2015 15:39
Look at your code. Now back to me. Now back to your code. Now back to me. Your BigDecimals are now readable.
module ReadableBigDecimal
def inspect
"<#{self.class.name}: #{self.to_f}>"
end
end
BigDecimal(10) # => #<BigDecimal:7fcd7103ee68,'0.1E2',9(36)>
BigDecimal.send(:prepend, ReadableBigDecimal)
BigDecimal(10) # => #<BigDecimal: 10>
@Peeja
Peeja / tee_io.rb
Created April 30, 2013 15:15
TeeIO: A method for logging to a file and STDOUT at the same time. Or to any two or more IOs. Greatly inspired by James Edward Grey II.
class TeeIO
# TeeIO will write to each of these IOs when it is written to.
def initialize(*ios)
@ios = ios
end
def write(data)
@ios.each { |io| io.write(data) }
end
var ids = [...];
rottenTweets;
_(ids).each(function(id) {
getTweet(id, function(tweetBody) {
rot13(tweetBody, function(rottenTweet) {
rottenTweets.push(rottenTweet);
if (rottenTweets.length == ids.length) {
useRottenTweets();
@Peeja
Peeja / gist:5152969
Created March 13, 2013 15:02
Moving STDERR and STDOUT around for great justice.
# A program which outputs "error" to STDERR and "output" to STDOUT.
a_program() {
echo error >&2
echo output
}
# Run a_program.
# - Redirect a_program's STDERR (file descriptor 2) to the STDIN of a tee process.
# - tee echoes its STDIN to the given filename and to its STDOUT.
# - Redirect tee's STDOUT to its STDERR.
@Peeja
Peeja / .gitignore
Last active December 14, 2015 07:49
Shows that Rails depends on vulnerable version of mail. https://github.com/rails/rails/pull/9475
Gemfile.lock
# Fix pbcopy etc.
set-option -g default-command "reattach-to-user-namespace -l zsh"
# act like vim
setw -g mode-keys vi
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
task :foo do
sh 'echo $FOO'
end
The command you ran:
$ rails runner ';'
Exception backtrace(s), if any: (warnings, in this case)
/Users/peeja/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/x86_64-darwin11.2.0/psych.bundle: warning: already initialized constant ANY
/Users/peeja/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/x86_64-darwin11.2.0/psych.bundle: warning: already initialized constant UTF8
/Users/peeja/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/x86_64-darwin11.2.0/psych.bundle: warning: already initialized constant UTF16LE
/Users/peeja/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/x86_64-darwin11.2.0/psych.bundle: warning: already initialized constant UTF16BE
/Users/peeja/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/x86_64-darwin11.2.0/psych.bundle: warning: already initialized constant ANY
/Users/peeja/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/x86_64-darwin11.2.0/psych.bundle: warning: already initialized constant UTF8
@Peeja
Peeja / Gemfile
Created December 3, 2012 22:04 — forked from rsutphin/Gemfile
RSpec rcov task does not work
source :rubygems
gem 'rake'
gem 'rspec', '2.12.0'
gem 'rcov'