Skip to content

Instantly share code, notes, and snippets.

@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>
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
source "https://rubygems.org"
gem "rspec"
gem "rake"
@Peeja
Peeja / dotfile_benchmark.zsh
Created November 30, 2012 23:08
Dotfile Benchmarking
#!/bin/zsh
export TIMEFMT='%E'
main() {
echo "Purging the disk cache..."
purge
# time's output is on stderr.
zsh_elapsed_time=$( (time zsh -ilc exit) 2>&1 )
@Peeja
Peeja / finalizer.rb
Created November 21, 2012 20:50
Why does this output "Finalized: false"?
finalized = false
finalizer = lambda { finalized = true }
# Hide all direct references to the object in a lambda.
lambda do
object = Object.new
ObjectSpace.define_finalizer(object, finalizer)
end.call
ObjectSpace.garbage_collect