Skip to content

Instantly share code, notes, and snippets.

Avatar

Erik Terpstra eterps

View GitHub Profile
@eterps
eterps / config.ru
Created Jan 30, 2015
REST/hypermedia webservice in Ruby using Webmachine, Webmachine linking and Roar for HAL/JSON support
View config.ru
require 'webmachine/adapters/rack'
require_relative 'webservice'
run Webservice.adapter
View s3.vcl
backend s3 { .host = "s3.amazonaws.com"; .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}"
DirTree.new(path).each{|n| yield n} if File.directory? path
end
end
end
@eterps
eterps / Sinatra
Created Nov 1, 2010
Play with Coffeescript / Sinatra
View Sinatra
Install node.js:
# See: http://nodejs.org/#download
NJSVERSION=v0.2.4
cd ~/tmp && wget http://nodejs.org/dist/node-${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
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
tokens.map!{|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
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
module_function
def Point(*args)
case args.first
when Point then args.first
when Array then Point.new(*args.first)
View open-s3uri.gemspec
Gem::Specification.new do |s|
s.name = 'open-s3uri'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.author = 'Erik Terpstra'
s.email = 'erterpstra@gmail.com'
s.summary = 'Opens an S3 uri'
s.description = 'Opens an S3 uri like open-uri does for http URLs'
s.files = ['open-s3uri.rb']
View keybase.md

Keybase proof

I hereby claim:

  • I am eterps on github.
  • I am eterps (https://keybase.io/eterps) on keybase.
  • I have a public key ASBdMN2hfTUxgMovEIPOEH4e9qAXplhPeYciuLAl2LnMKwo

To claim this, I am signing this object:

@eterps
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?
def self.events
@events ||= []
end
end
# 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