Skip to content

Instantly share code, notes, and snippets.

View jamiehodge's full-sized avatar

Jamie Hodge jamiehodge

  • Zendesk
  • Copenhagen, Denmark
View GitHub Profile

Request:

GET /
Host: tus.example.org

Response:

HTTP/1.1 200 OK

...

@jamiehodge
jamiehodge / upload.md
Last active December 17, 2015 14:39
Upload protocol proposal

Request:

GET /
Host: tus.example.org

Response:

HTTP/1.1 200 OK

...

@jamiehodge
jamiehodge / upload.md
Last active December 17, 2015 14:09
Upload protocols

Server ideals

  • stateless
  • tell, don't ask

Client ideals

  • graceful degredation (should be possible to manually split and submit files via forms)
  • a minimum of logic
  • chunk files
@jamiehodge
jamiehodge / sequel_dot.rb
Created May 6, 2013 07:31
sequel DB diagrams
#! /usr/bin/env ruby
# Usage:
# ruby sequel_dot.rb [SEQUEL-DATABASE-URI] > output.dot
# Or pipe directly to Graphviz:
# ruby sequel_dot.rb [SEQUEL-DATABASE-URI] | dot -Tgif > output.gif
#
# Note adapted from Jeremy Evans' and Rohit Namjoshi's son's code at
# http://sequel.heroku.com/2010/05/29/fun-with-graphviz-and-associations/
#
@jamiehodge
jamiehodge / sinatra.rb
Last active December 16, 2015 06:19
What am I?
# What am I? A controller? A router?
class Foo < Sinatra::Base
set :bar, Baz
def self.both
# aren't a composite object in denial?
get '/glee' do
'happy!'
@jamiehodge
jamiehodge / shell.rb
Last active December 13, 2015 23:49
Stream and capture subprocess stdout
require 'open3'
def subprocess(*cmd)
Open3.popen3(*cmd) {|i,o,e,t|
out = Thread.new do
o.each_with_object([]) do |line,memo|
memo << line
yield line if block_given?
end.join
@jamiehodge
jamiehodge / router.rb
Last active December 12, 2015 04:18
Sinatra Journey
require 'journey'
require 'forwardable'
class Router
extend Forwardable
def_delegator :router, :call
def_delegator :formatter, :generate
def add_route(app, path, conditions={}, defaults={}, name)
routes.add_route(
@jamiehodge
jamiehodge / controller.rb
Created January 30, 2013 11:33
Header links
class Catalogs < Controller
set :model, Catalog
set :fields, [:title, :description]
namespace '/' do
get do
catalogs = model.paginate(page, page_size)
@jamiehodge
jamiehodge / http.txt
Created January 30, 2013 11:13
Link headers and collections
Link: <http://localhost:5000/catalogs/>; rel="self"; title="Catalog Index"
Link: <http://localhost:5000/catalogs/1>; rel="item"; title="Catalog"
Link: <http://localhost:5000/catalogs/2>; rel="item"; title="Catalog"
...
Link: <http://localhost:5000/catalogs/?page=2&page_size=12>; rel="next"; title="Next Page"