Skip to content

Instantly share code, notes, and snippets.


Luke Rodgers lukeasrodgers

View GitHub Profile
lukeasrodgers / ruby-redis-utils.rb
Last active Jul 11, 2016
scan-style iteration over redis list in ruby, making multiple roundtrips
View ruby-redis-utils.rb
# useful if k is a very large list, and you don't want to do it all in one request
# note that consistency will not be guaranteed here (i.e. list can change during iteration)
def scan_list(k, range=1000, &block)
i = 0
result = []
while l = HLR.lrange(k, i, i+range)
break if l.size == 0
if block_given?
yield l


  • ensure config is loaded/tested in correct env


  • check for divide by zero
  • is integer division/rounding accounted for?
  • what happens if inputs are very small/very large?
  • what happens if results are negative (even though this "should never happen")


View gist:e9f269f25e049f72a79897af43d9d3e8
# List users by average and maximum session length.
SELECT person, max(client.runtime_ms), avg(client.runtime_ms)
FROM item_occurrence
# List active date ranges for each deploy.
SELECT client.javascript.code_version, min(timestamp), max(timestamp)
FROM item_occurrence
lukeasrodgers / movies.cypher
Created Jan 22, 2016
neo4j movies.cypher export using neo4j-shell-tools
View movies.cypher
CREATE (:`Movie`:`UNIQUE IMPORT LABEL` {`released`:1999, `tagline`:"Welcome to the Real World", `title`:"The Matrix"});
CREATE (:`Person`:`UNIQUE IMPORT LABEL` {`born`:1964, `name`:"Keanu Reeves"});
CREATE (:`Person`:`UNIQUE IMPORT LABEL` {`born`:1967, `name`:"Carrie-Anne Moss"});
CREATE (:`Person`:`UNIQUE IMPORT LABEL` {`born`:1961, `name`:"Laurence Fishburne"});
CREATE (:`Person`:`UNIQUE IMPORT LABEL` {`born`:1960, `name`:"Hugo Weaving"});
CREATE (:`Person`:`UNIQUE IMPORT LABEL` {`born`:1967, `name`:"Andy Wachowski"});
CREATE (:`Person`:`UNIQUE IMPORT LABEL` {`born`:1965, `name`:"Lana Wachowski"});
CREATE (:`Person`:`UNIQUE IMPORT LABEL` {`born`:1952, `name`:"Joel Silver"});
CREATE (:`Person`:`UNIQUE IMPORT LABEL` {`born`:1978, `name`:"Emil Eifrem"});
lukeasrodgers / movies.grapml
Created Jan 22, 2016
neo4j movies.graphml export using neo4j-shell-tools
View movies.grapml
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="" xmlns:xsi="" xsi:schemaLocation="">
<graph id="G" edgedefault="directed">
<node id="n0" labels=":Movie"><data key="labels">:Movie</data><data key="tagline">Welcome to the Real World</data><data key="title">The Matrix</data><data key="released">1999</data></node>
<node id="n1" labels=":Person"><data key="labels">:Person</data><data key="name">Keanu Reeves</data><data key="born">1964</data></node>
<node id="n2" labels=":Person"><data key="labels">:Person</data><data key="name">Carrie-Anne Moss</data><data key="born">1967</data></node>
<node id="n3" labels=":Person"><data key="labels">:Person</data><data key="name">Laurence Fishburne</data><data key="born">1961</data></node>
<node id="n4" labels=":Person"><data key="labels">:Person</data><data key="name">Hugo Weaving</data><data key="born">
View quickrubyprof.rb
# Gemfile
gem 'ruby-prof'
# code to profile
require 'ruby-prof'
# run code
result = RubyProf.stop
printer =
lukeasrodgers / monkeypatch_ar_mysql_collation_charset.rb
Created Oct 6, 2015
monkeypatch active record mysql adapter to understand collation, charset
View monkeypatch_ar_mysql_collation_charset.rb
# this is ugly and terrible, don't do this
module ActiveRecord
module ConnectionAdapters
class TableDefinition
def column(name, type, options = {})
name = name.to_s
type = type.to_sym
column = self[name] || new_column_definition(@base, name, type)
lukeasrodgers / jsfactories.js
Last active Aug 29, 2015
simple js factories using builder pattern
View jsfactories.js
* Builder pattern for factories, mimic use of FactoryGirl traits.
* usage: factories.boostedBoost({retweets: 1}).twitter().withdrawn().geo(11217).generate();
* must call `generate` as last step
* may pass options to initial method call, as well as subsequent method calls
function addFactory(factoryName, config) {
// add trait function to generated Factory
function addTrait(k, Factory, config) {
Factory.prototype[k] = function() {
lukeasrodgers / puma_perf_get
Created Dec 17, 2014
puma perf testing JSON API GET
View puma_perf_get
Benchmarking (be patient)
Finished 450 requests
Server Software:
Server Hostname:
Server Port: 3080
Document Path: /api/v1/users/1/cabinets/1/drinks
Document Length: 801 bytes
lukeasrodgers / unicorn_perf_get
Created Dec 17, 2014
unicorn perf testing JSON API GET
View unicorn_perf_get
Benchmarking (be patient)
Finished 199 requests
Server Software:
Server Hostname:
Server Port: 3080
Document Path: /api/v1/users/1/cabinets/1/drinks
Document Length: 801 bytes