Skip to content

Instantly share code, notes, and snippets.

@msepcot
msepcot / enumerable-deep_find.rb
Created May 22, 2013 18:35
Add deep_find ability to Enumerable to recursively search for a Hash key. Returns the first key found.
module Enumerable
def deep_find(key)
if respond_to?(:key?) && key?(key)
self[key]
else
found = nil
find { |*a| v = a.last; found = v.is_a?(Enumerable) ? v.deep_find(key) : nil }
found
end
end
@msepcot
msepcot / branches.sh
Last active June 27, 2016 21:03
Bash script to output a list of git branches sorted by last commit date, include last commit author's name.
#!/bin/bash
$(git fetch --prune)
for branch in $(git branch -r); do
if ([ "$branch" == "origin/HEAD" ] || [ "$branch" == "origin/master" ] || [ "$branch" == "origin/develop" ] || [ "$branch" == "->" ] || [[ "$branch" =~ origin\/[0-9]+\.[0-9](\.[0-9])?$ ]]); then
continue
fi
printf "$(git log $branch -n1 --pretty=format:"%an (%ad): $branch" --date=short)\n";
done | sort
@msepcot
msepcot / license.rb
Created September 5, 2012 16:26
Look through gems and group by license
# encoding: UTF-8
require 'securerandom'
require 'fileutils'
dir = "tmp/#{SecureRandom.hex(4)}_gems"
gems = `bundle exec gem list`.split
licenses = {
'Apache 2.0' => [],
'MIT' => [],
@msepcot
msepcot / sqlserver.rb
Created August 28, 2012 14:59
Force a string to identify itself as non-UTF8 (used with ActiveRecord::ConnectionAdapters::Sqlserver::Quoting)
module ActiveRecord
module ConnectionAdapters
module Sqlserver
module Quoting
def quote(value, column = nil)
case value
when String, ActiveSupport::Multibyte::Chars
if column && column.type == :integer && value.blank?
nil
elsif column && column.type == :binary