Skip to content

Instantly share code, notes, and snippets.


Erik Terpstra eterps

View GitHub Profile
eterps /
Created Jan 30, 2015
REST/hypermedia webservice in Ruby using Webmachine, Webmachine linking and Roar for HAL/JSON support
require 'webmachine/adapters/rack'
require_relative 'webservice'
run Webservice.adapter
View s3.vcl
backend s3 { .host = ""; .port = "80"; }
sub vcl_recv {
if (req.url ~ ".(css|gif|ico|jpg|jpeg|js|png|swf|txt)$") {
unset req.http.cookie;
unset req.http.cache-control;
unset req.http.pragma;
unset req.http.expires;
unset req.http.etag;
unset req.http.X-Forwarded-For;
View du.rb
class DirTree < String
include Enumerable
def each
Dir.entries(self).reject{|n| %w[. ..].include? n}.each do |filename|
yield path = "#{self}/#{filename}"{|n| yield n} if path
eterps / Sinatra
Created Nov 1, 2010
Play with Coffeescript / Sinatra
View Sinatra
Install node.js:
# See:
cd ~/tmp && wget${NJSVERSION}.tar.gz && tar zxf node-${NJSVERSION}.tar.gz && cd node-${NJSVERSION}
./configure --prefix=/opt/node-${NJSVERSION} && make && make install && ln -s /opt/node-${NJSVERSION} /opt/node
ln -s /opt/node/bin/node ~/bin/node
vi .bashrc
export PATH=$PATH:/opt/node/bin
eterps / mrisc.rb
Created Jul 8, 2011 — forked from pachacamac/mrisc.rb
A Simple Assembler Language and VM
View mrisc.rb
#!/usr/bin/env ruby
class MRISC
def run(code)
tokens = code.gsub(/(\*.*?\*)|[^a-z0-9,-;@\._]/,'').split(';')
@vars,stack,i = {:_pc=>-1,:_oc=>0},[],0!{|t| t.chars.first=='@' ? (@vars[t.to_sym]=i-1;nil) : (i+=1;t.split(',').map{|e|numeric?(e) ? e.to_i : e.to_sym})}.compact!
while @vars[:_pc] < tokens.size-1
@vars[:_pc] += 1
@vars[:_oc] += 1
eterps / conversion_functions.rb
Created Oct 29, 2015
Ruby conversion functions pattern
View conversion_functions.rb
# From Confident Ruby, page 72
module Graphics
module Conversions
def Point(*args)
case args.first
when Point then args.first
when Array then*args.first)
View open-s3uri.gemspec do |s| = 'open-s3uri'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY = 'Erik Terpstra' = ''
s.summary = 'Opens an S3 uri'
s.description = 'Opens an S3 uri like open-uri does for http URLs'
s.files = ['open-s3uri.rb']

Keybase proof

I hereby claim:

  • I am eterps on github.
  • I am eterps ( on keybase.
  • I have a public key ASBdMN2hfTUxgMovEIPOEH4e9qAXplhPeYciuLAl2LnMKwo

To claim this, I am signing this object:

eterps / event_sourcing.rb
Created Mar 22, 2016
Playing around with event sourcing principles
View event_sourcing.rb
require 'yaml'
class Storage # Normally should be Redis or Kafka?
@events ||= []
# Aggregates (models)
View sequel_playground.rb
#!/usr/bin/env ruby
require 'sequel'
require 'logger'
require 'awesome_print'
DB = Sequel.sqlite
DB.create_table :people do
primary_key :id
String :name