Skip to content

Instantly share code, notes, and snippets.

View madx's full-sized avatar

François Vaux madx

View GitHub Profile
module Sinatra
# HTTP Authorization helpers for Sinatra.
#
# In your helpers module, include Sinatra::Authorization and then define
# an #authorize(user, password) method to handle user provided
# credentials.
#
# Inside your events, call #login_required to trigger the HTTP
# Authorization window to pop up in the browser.
#
describe 'content_type' do
it 'is set to text/plain for each request' do
get '/'
last_response.headers['Content-Type'].should == 'text/plain'
end
end
describe 'get /__index__' do
it 'returns the wiki index' do
get '/__index__'
module RestSource
attr_accessor :env
def call(env)
@env = env
method = env['REQUEST_METHOD'].downcase.to_sym
params = env['REQUEST_URI'][1..-1].split('/').collect { |p|
Rack::Utils.unescape(p)
}
# Rackable is a tiny module that aims to provide a REST-like interface to
# any object.
#
# It uses Rack under the hood, thus any “Racked” object is a valid Rack
# application.
#
# I really don't know if this is useful, but it's more a proof of concept than
# anything.
module Rackable
attr_accessor :response, :env, :header
# Rack side
rackable/examples (master*:7bf42fc) $ rackup rest_string.ru
127.0.0.1 - - [21/Jul/2009 15:32:35] "INSTANCE_EVAL /Dir%5B%22%2F%2A%22%5D.inspect HTTP/1.1" 200 245 0.0059
# Telnet
~ $ telnet localhost 9292
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
INSTANCE_EVAL /Dir%5B%22%2F%2A%22%5D.inspect HTTP/1.1
~ $ sudo ab -n 10000 http://localhost:9292/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Server Software:
Server Hostname: localhost
Server Port: 9292
require 'rackable'
require 'couchrest'
DB = CouchRest.database!('http://localhost:5984/targetz')
class Target < CouchRest::ExtendedDocument
use_database DB
property :url
property :slug
SELECT NumPil, NumAv
FROM Vols
WHERE NumPil IS NOT NULL AND NumAv IS NOT NULL
GROUP BY NumPil, NumAv
ORDER BY NumPil;
#!/bin/bash
ISSUES=/home/madx/repos/mine/bit/issues
function bit_nl() { nl -nln -w1 -s $@ }
function bit_before() {
line="$(bit_nl $ISSUES)"
}
function bit_chunk() {
ditz $ ditz add
Title: Hello
Description (ctrl-d, ., or /stop to stop, /edit to edit, /reset to reset):
> Make a Hello world
> .
Is this a (b)ugfix, a (f)eature, or a (t)ask? t
Issue creator (enter for "madx <[email protected]>"):
Comments (ctrl-d, ., or /stop to stop, /edit to edit, /reset to reset):
> Lol.
> .