Skip to content

Instantly share code, notes, and snippets.

View glv's full-sized avatar

Glenn Vanderburg glv

View GitHub Profile

Keybase proof

I hereby claim:

  • I am glv on github.
  • I am glv (https://keybase.io/glv) on keybase.
  • I have a public key whose fingerprint is 0CF3 D473 4F46 7494 1975 290C DA1F 2F76 9F2F 5496

To claim this, I am signing this object:

@glv
glv / gist:134881
Created June 23, 2009 22:11 — forked from objo/gist:134796
entries.map(&:job).sort_by(&:number).map(&:project).compact.uniq
# Put this in your .irbrc, and then type
# "some_object.my_methods" in an IRB session
# for less noisy exploration of what objects
# can do.
class Object
def my_methods
base_object = case self
when Class then Class.new
when Module then Module.new
@glv
glv / gist:703997
Created November 17, 2010 20:16
USE INDEX with Active Record finders for Rails 3
# for background, see http://m.onkey.org/use-index-with-active-record-finders
# and http://twitter.com/#!/dougalcorn/status/4963159878139904
from = "#{quoted_table_name} USE INDEX(index_activities_on_created_at_and_country_id)"
Activity.from(from).where('created_at >= ? AND country_id = ?', 10.days.ago, 79).all
@glv
glv / gist:1438719
Created December 6, 2011 16:05 — forked from gvaughn/gist:1436816
Conway's Game of Life in functional ruby
def evolve(generation)
live_neighbor_stats = generation_stats(generation)
live_neighbor_stats[3] + (live_neighbor_stats[2] & generation)
end
def generation_stats(live_cells)
live_cells.each_with_object(Hash.new(0)) {|live_cell, counter|
neighbors(*live_cell).each {|neighbor| counter[neighbor] += 1 }
}.each_with_object(Hash.new {|h,k| h[k] = []}) {|(cell, count), collector| collector[count] << cell}
end
require 'active_record'
module ActiveRecord
module Associations
# This fix allows the association extension methods to work when used in combination
# with built-in Arel scoping methods (where, joins, etc.) and *also* with named scopes
# defined on the target class.
class AssociationProxy
def with_scope_with_extensions(*args, &block)
@glv
glv / bundler-exec.sh
Created February 25, 2013 20:32
Smart aliases to wrap commands in "bundle exec" for you when needed
# I source this from ~/.bash_profile
# I think I got them from @JEG2
BUNDLED_COMMANDS="foreman rackup rails rake rspec ruby shotgun spec watchr nesta cap"
## Functions
bundler-installed()
{
which bundle > /dev/null 2>&1
@glv
glv / sort-without-threading-macro.clj
Created October 17, 2013 16:18
Avdi Grimm praised the symmetry of the Clojure version of line sorting (http://devblog.avdi.org/2013/10/16/sorting-lines-in-5-languages/). I thought it would be instructive to show how a more traditional Lispy version, without Clojure's ->> macro, obscures that symmetry.
(spit (nth *command-line-args* 2)
(clojure.string/join "\n"
(sort (clojure.string/split-lines (slurp (nth *command-line-args* 1))))))
@glv
glv / blockchain_proof.txt
Created February 26, 2016 16:41
Blockchain identification
Verifying that +glennv is my blockchain ID. https://onename.com/glennv
@glv
glv / percentages.rb
Created July 1, 2016 19:32
Dave Thomas' Ruby puzzler
# What is the value of this Ruby expression?
% % % % %
# There's a trailing space, which is important!
# It evaluates to "%". Why? It's equivalent to this:
%|%|% %|%|
# which parses as: