Skip to content

Instantly share code, notes, and snippets.

@zev
zev / DWIMlogging
Created September 28, 2011 03:03
Buffered logging to handle encoding conversion failures
def flush
@guard.synchronize do
unless buffer.empty?
old_buffer = buffer
begin
@log.write(old_buffer.join)
rescue Encoding::UndefinedConversionError
puts "Enc err"
@log.write(old_buffer.map { |b| b.force_encoding(Encoding.default_internal) }.join)
puts "Enc Done"
@zev
zev / dbtap.clj
Created May 16, 2012 02:13
Custom Cascalog tap from a db query
(defn convert-rs
[rs keys]
(vec (doall
(map #(vec (map-values % keys)) rs))))
(defn map-values
[r keys]
(map #(% r) keys))
(defn users-query
@zev
zev / github_show.sh
Created September 18, 2012 03:55 — forked from andrewplummer/github_show.sh
Open a link to a file in Github from the command line.
#!bin/bash
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
parse_git_remote() {
git remote -v | head -n 1 | sed 's/.*github.com:\(.*\).git .*/\1/'
}
@zev
zev / active_record_gem_3_2.rb
Created June 18, 2014 02:59
RecordNotFound missing descriptive message from various ActiveRecord versions
# Activate the gem you are reporting the issue against.
gem 'activerecord', '3.2.18'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# This connection will do for database-independent bug reports.
begin
class_to_load = class_name.constantize
class_to_load.new
# ...
rescue NameError => e
# do other things if class_name is not an actual class
end