Skip to content

Instantly share code, notes, and snippets.

geeksam / counts_by.rb
Last active March 21, 2017 19:32
View counts_by.rb
module Enumerable
def counts_by(&property)
group_by(&property) # Group my values by some interesting property
.lazy # (in a potentially more GC-friendly way),
.map {|x,xs| [ x, xs.length ] } # collapsing the sub-lists of values to simple counts...
.sort_by(&:last) # and show them in increasing order of frequency (so that,
# if the list is very long, the high numbers are at the end)
geeksam / config-initializers-breadcrumb.rb
Created October 13, 2015 23:55
Handy pattern for puts-statement debugging in Rails
View config-initializers-breadcrumb.rb
if Rails.env.test? || Rails.env.development?
module Kernel
def __breadcrumb__(msg = "")
return unless $debug
msg = msg.to_s
breadcrumb = ">>> #{caller.first}"
breadcrumb << "\n--> #{msg}" if msg.present?
Rails.logger.debug breadcrumb
puts '', breadcrumb
geeksam /
Created February 20, 2015 19:03
OFFS Indentation example (OFFS:

I propose the following convention: the actual lines of code that are directly related to the OFFS gem itself should be aligned with the left margin. Code inside the would_like_to and may_still_need_to blocks should be indented "normally", as though the surrounding OFFS do/end lines were not present. See the example Ruby file also in this gist.

This convention serves two purposes:

  1. It provides a visual indication that something in the file is "weird", thus calling our attention to the complexity penalty being imposed by carrying extra branches in VCS.
  2. When the feature itself is eventually cleaned up, the diff will be a straight deletion, not the deletion-plus-insertion one would otherwise get from deindenting a block of code. This will make it more obvious if someone deletes one branch and makes an edit in the other in the same Git commit.
geeksam /
Last active June 12, 2017 20:46
The "Is It a DSL or an API?" Ten Question Checklist

[NOTE: The original version was posted in 2007 on an O'Reilly blog, but the page has been erroring out for months now. I'm copying it here because, while useful, can be slow. chromatic is a lovely person who (he thinks) probably has copyright to this piece.]

The "Is It a DSL or an API?" Ten Question Checklist

Saturday May 19, 2007 6:00AM
by chromatic in Opinion

geeksam / README.txt
Last active November 27, 2018 18:55
Short list of usernames, for wemux session only
View README.txt
I mostly work in a wemux session so that my coworkers can SSH in and join me on
short notice, and have configured my tmux status bar to show the usernames of
everyone who's logged in. However, I also sometimes have tmux sessions open with
personal projects, and don't need to see usernames in *those* sessions. Also,
some people have really long usernames, so I want to assign them nicknames so
the entire list doesn't get truncated.
geeksam / comparisons.feature
Created December 2, 2013 04:30
A little something that might be of interest for Ada Developers Academy
View comparisons.feature
Feature: Salary range comparisons
AS A person involved in a recruitment discussion
I WANT to know whether the candidate's and recruiter's expected salary ranges overlap
SO THAT I can avoid spending time on negotiations that can't ultimately be satisfied
AS A person who knows about the phenomenon of price anchoring
I WANT to approach this question without necessarily being first to name a number
SO THAT I don't compromise my negotiating position
geeksam /
Last active December 25, 2015 02:59
Some things I should've said before jumping in to argue the finer points of community handling of probably <5% of eventual cases...

Trigger Warning for SA/DV (prompted by recent developments in PDX and Ruby worlds)

  • (1/9) I have a terribly sloppy habit, when arguing a topic, of skipping supporting points that "should be obvious". So, for the record: (link)
  • (2/9) I've had a secondhand education in sexism, DV, oppression theory from my amazing partner, who worked in DV agencies for years. (link)
  • (3/9) One thing I've learned is that abuse is shockingly prevalent, highly underreported, and almost always goes unaccounted for. (link)
  • (4/9) I believe @saltinejustine. I can't imagine how much courage it takes to speak up. Nobody deserves abuse, or backlash from reporting. (link)
  • (5/9) Abusers are everywhere. You probably know at least one. Our culture, and our desire to think wel
geeksam / com.googlecode.iterm2.plist
Created August 15, 2013 21:27
iTerm 2 settings
View com.googlecode.iterm2.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
geeksam / gist:6142405
Created August 2, 2013 18:54
AXE brogramming
View gist:6142405
class Brogrammer
def ponder_life
self.if(you == understand.this) {
def if(predicate)
yield if predicate
geeksam / gist:5722686
Created June 6, 2013 16:03
Blurb for Fluent Refactoring
View gist:5722686
Fluency is "what you can say without having to think about how to say
it." "Refactoring" is a language that describes ways to make your
code better. I want to inspire you to learn more of that language, so
you can make your code better without having to think about it.
I'll walk you through the process of reworking a 50-line controller
action that's hard to comprehend, let alone refactor. We'll tease
apart fiendishly intertwined code, embrace duplication, use dirty
tricks to our advantage, and uncover responsibilities that weren't
obvious when we started.