- stateless
- tell, don't ask
- graceful degredation (should be possible to manually split and submit files via forms)
- a minimum of logic
- chunk files
| # 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!' |
| #! /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/ | |
| # |
| form method='post' action=url(record) | |
| fieldset | |
| input name='_method' type='hidden' value='link' | |
| p | |
| input name='link[rel]' type='hidden' value=rel | |
| input name='link[id]' type='text' required=true | |
Request:
GET /
Host: tus.example.org
Response:
HTTP/1.1 200 OK
...
Request:
GET /
Host: tus.example.org
Response:
HTTP/1.1 200 OK
...
| 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) |
POST /uploads
-> /uploads/id
PUT (repeat) GET to see what is missing
| require 'sequel' | |
| DB ||= Sequel.connect ENV['DATABASE_URL'] | |
| class Resource < Sequel::Model | |
| include Sequel.inflections | |
| def after_save | |
| db.notify channel | |
| end |
| 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; |