Skip to content

Instantly share code, notes, and snippets.

View jamiehodge's full-sized avatar

Jamie Hodge jamiehodge

  • Zendesk
  • Copenhagen, Denmark
View GitHub Profile
@jamiehodge
jamiehodge / auth
Last active December 21, 2015 17:29
auth plugin
require 'base64'
class Zoidberg::Plugin::Auth
Zoidberg::Plugin.define :auth, self
def initialize(app)
app.generic_controller.send(:include, InstanceMethods)
end
module InstanceMethods
@jamiehodge
jamiehodge / gist:6339574
Created August 26, 2013 09:22
Sequel file plugin
require 'pathname'
module Storage
class Local
attr_reader :path
def initialize(path)
@path = Pathname(path).expand_path
end
def [](id)
D, [2013-07-05T15:41:56.753944 #24121] DEBUG -- Asgard: GET /collections/ (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.46.5 (KHTML, like Gecko) Version/7.0 Safari/537.46.5)
D, [2013-07-05T15:41:56.754476 #24121] DEBUG -- Asgard: Rendering template collections/index.html
D, [2013-07-05T15:41:56.755479 #24121] DEBUG -- Asgard: Rendering layout layouts/application.html
E, [2013-07-05T15:41:56.756006 #24121] ERROR -- Asgard: Exception: Errno::EPIPE: Broken pipe
E, [2013-07-05T15:41:56.756179 #24121] ERROR -- Asgard: /usr/local/Cellar/ruby/HEAD/lib/ruby/gems/2.1.0/gems/zoid-0.0.0/lib/zoid/reactor/pure.rb:188:in `write_nonblock'
E, [2013-07-05T15:41:56.756239 #24121] ERROR -- Asgard: /usr/local/Cellar/ruby/HEAD/lib/ruby/gems/2.1.0/gems/zoid-0.0.0/lib/zoid/reactor/pure.rb:188:in `write_buffer'
E, [2013-07-05T15:41:56.756277 #24121] ERROR -- Asgard: /usr/local/Cellar/ruby/HEAD/lib/ruby/gems/2.1.0/gems/zoid-0.0.0/lib/zoid/reactor/pure.rb:206:in `write'
E, [2013-07-05T15:41:56.756325 #24121] ERROR
require 'formula'
class Libvpx < Formula
homepage 'http://www.webmproject.org/code/'
url 'http://webm.googlecode.com/files/libvpx-v1.1.0.tar.bz2'
sha1 '356af5f770c50cd021c60863203d8f30164f6021'
head 'http://git.chromium.org/webm/libvpx.git'
depends_on 'yasm' => :build
#!/usr/bin/env ruby
require 'media'
$0 = '0.0'
converter =
Media.convert do
options y: true
input '/path/to/input.mov'
@jamiehodge
jamiehodge / example.rb
Created June 3, 2013 14:48
Drag and drop ordered list
require 'sequel'
DB = Sequel.sqlite
DB.create_table :collections do
primary_key :id
end
DB.create_table :items do
primary_key :id
@jamiehodge
jamiehodge / migration.rb
Created May 30, 2013 20:24
Notify function and trigger
create_function(:notify, <<-SQL, language: :plpgsql, returns: :trigger, replace: true)
BEGIN
IF (TG_OP = 'DELETE') THEN
PERFORM pg_notify(TG_TABLE_NAME, '{ \"id\": \"' || OLD.id || '\", \"event\": \"' || TG_OP || '\" }');
RETURN OLD;
ELSE
PERFORM pg_notify(TG_TABLE_NAME, '{ \"id\": \"' || NEW.id || '\", \"event\": \"' || TG_OP || '\" }');
RETURN NEW;
END IF;
END;
@jamiehodge
jamiehodge / resource.rb
Last active November 28, 2017 23:23
Server Side Events, Sequel and Postgres LISTEN/NOTIFY
require 'sequel'
DB ||= Sequel.connect ENV['DATABASE_URL']
class Resource < Sequel::Model
include Sequel.inflections
def after_save
db.notify channel
end
@jamiehodge
jamiehodge / gist:5644074
Last active December 17, 2015 17:09
Explicit chunk upload proposal

POST /uploads

  • complete: default false
  • chunk_size: default 1024*x

-> /uploads/id

  • form PUT uploads/id/chunks/id
  • list /uploads/id/chunks/id

PUT (repeat) GET to see what is missing

@jamiehodge
jamiehodge / gist:5642713
Created May 24, 2013 10:56
parse url query string
params = (url) ->
plus = /\+/g
search = /([^&=]+)=?([^&]*)/g
decode = (s) -> decodeURIComponent s.replace(plus, ' ')
index = url.indexOf '?'
if index isnt -1 then hash = url.substr index + 1 else hash = ''
result = {}
while match = search.exec(hash)