Skip to content

Instantly share code, notes, and snippets.

View tomlobato's full-sized avatar
🎯
Focusing

Tom Lobato tomlobato

🎯
Focusing
View GitHub Profile
@tomlobato
tomlobato / gist:71e2815ff210dc24a1717df2afd8048a
Last active July 7, 2019 06:00 — forked from nevans/gist:9374041
simple ruby console histogram generator
require 'pry' # gem install pry
# Pass in an enumeration of data and
# (optionally) a block to extract the grouping aspect of the data.
#
# Optional: sort_by lambda (operates on group key and count)
def puts_hist(data, sort_by:nil, &blk)
data = data.map(&blk) if blk
counts = data.each_with_object(Hash.new(0)) {|k,h| h[k]+=1}