Skip to content

Instantly share code, notes, and snippets.

@seifertd
seifertd / Makefile
Last active August 29, 2015 14:26
csv transforms don't finish if we exit after the parser says we are finished reading the csv input
❯❯❯ cat Makefile
COFFEE=node_modules/.bin/coffee
# ## Usage
usage :
@echo ''
@echo '---------------------------'
@echo ''
@echo 'Core tasks : Description'
@echo '-------------------- : -----------'
Creating buffer of size 515000
Done creating buffer, duration: 1 ms
Set cache key foobydoo with object of length 515000, duration: 19 milliseconds
Creating buffer of size 515100
Done creating buffer, duration: 1 ms
Set cache key foobydoo with object of length 515100, duration: 13 milliseconds
Creating buffer of size 515200
Done creating buffer, duration: 1 ms
Set cache key foobydoo with object of length 515200, duration: 9 milliseconds
Creating buffer of size 515300
@seifertd
seifertd / coarrays.rb
Last active December 18, 2015 14:58
Sorting arrays of related objects
require 'benchmark'
N = 100_000
[3, 5, 10].each do |array_size|
terms = []
arr2 = []
array_size.times do |n|
terms << {:id => n, :name => "term#{n}", :version => 1}
@seifertd
seifertd / nested_csv.rb
Last active December 18, 2015 03:29
CSV to nested hashrequire 'csv'
require 'csv'
users_by_id = {}
CSV.new(DATA, headers: true).each do |row|
user_id = row['user_id'].to_i
supervisor_id = row['supervisor_id'].to_i
is_supervisor = row['is_supervisor'] == 't'
existing_user = (users_by_id[user_id] ||= { user_name: row['user_name'], user_id: user_id})
existing_user[:users] ||= [] if is_supervisor
supervisor = users_by_id[supervisor_id]
@seifertd
seifertd / Gemfile.lock
Created September 8, 2012 20:05
Current gemfile
GIT
remote: git://github.com/seifertd/sms-fu.git
revision: 2fe5e992109945f30099952d07b9041e18d303df
specs:
sms_fu (1.1.3)
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.2.7)
@seifertd
seifertd / dropped_dtmf.txt
Created September 8, 2012 19:11
Debug log for dropped DTMF
[2012-09-08 14:46:18] DEBUG Celluloid: [RECV] Event: Newchannel
Privilege: call,all
Channel: SIP/telco-0000016c
ChannelState: 0
ChannelStateDesc: Down
CallerIDNum: NNNNNNNNNN
CallerIDName: XXXXXXXXXX XXXX
AccountCode:
Exten: 4242016871
Context: medready
@seifertd
seifertd / cave.rb
Created February 10, 2012 19:44
My solution to the Hitting Rock Bottom puzzle (http://puzzlenode.com/puzzles/11-hitting-rock-bottom)
class Cave
WATER = '~'
ROCK = '#'
AIR = ' '
attr_reader :grid, :flow_points
attr_accessor :water
# Create a Cave from the given file.
def initialize(filename)
# Keep track of points where water can flow either down or to the right
@seifertd
seifertd / flatten.rb
Created December 9, 2010 04:24
naive re-implementation of Array#flatten with tests
# This module implements flatten and flatten! methods. It is expected that it
# be included in Array or a subclass of Array (strictly speaking, it expects the
# class it is included in to 1) have an each method, 2) respond to 'replace' taking an Array as a
# single argument, 3) can be constructed using an Array as a single argument and 4) can be compared
# to an Array using ==).
module Flatten
# When included in a class that already defines :flatten and :flatten!,
# alias them away and remove them so that the module methods below take
# precedence.