Skip to content

Instantly share code, notes, and snippets.

class SomeMiddleware
def initialize(app) @app = app end
def call(env)
background(env) { ... }
@app.call env
end
def background(env, &block)
if env['rack.run_once'] then yield
require 'logger'
require 'openssl'
class UcellGateway
#dunno what this is, but it's yours :)
include MessageFilter
def initialize
@logger = Logger.new
@elvuel
elvuel / gist:1986329
Created March 6, 2012 13:40 — forked from Dremora/gist:709312
EventStream
require 'sinatra'
require 'eventmachine'
class EventStream
include EventMachine::Deferrable
def initialize(channel, &block)
@channel = channel
@block = block
@elvuel
elvuel / backbone.iframe.sync.js
Created March 8, 2012 05:25 — forked from unixcharles/backbone.iframe.sync.js
Backbone.sync implementation that use iframe + multipart/form-data
(function () {
Backbone.syncWithoutUpload = Backbone.sync
Backbone.syncWithUpload = function(method, model, options) {
// Create iframe
var iframe_id = 'file_upload_iframe_' + Date.now()
, iframe = jQuery('<iframe id="' + iframe_id + '" name="' + iframe_id + '" ></iframe>').hide()
// Create an hidden form
var authToken = jQuery('meta[name=csrf-token]').attr('content')
, authParam = jQuery('meta[name=csrf-param]').attr('content')
@elvuel
elvuel / paginated_collection.js
Created March 31, 2012 01:52 — forked from io41/paginated_collection.js
Pagination with Backbone.js
// includes bindings for fetching/fetched
var PaginatedCollection = Backbone.Collection.extend({
initialize: function() {
_.bindAll(this, 'parse', 'url', 'pageInfo', 'nextPage', 'previousPage');
typeof(options) != 'undefined' || (options = {});
this.page = 1;
typeof(this.perPage) != 'undefined' || (this.perPage = 10);
},
fetch: function(options) {
@elvuel
elvuel / git-cheat.rdoc
Created April 6, 2012 08:50 — forked from jschementi/git-cheat.rdoc
Git cheatsheets
@elvuel
elvuel / oauth.rb
Created April 10, 2012 03:50 — forked from robertsosinski/oauth.rb
Step-by-step processes of creating an OAuth Authorization Header
require 'uri'
require 'base64'
require 'openssl'
# NOTE: Oauth uses a specific unreserved character list for URL encoding.
def url_encode(input)
unreserved = '-._~0-9A-Za-z' # These are the only characters that should not be encoded.
URI.escape(input, Regexp.new("[^#{unreserved}]"))
end
@elvuel
elvuel / gist:2419978
Created April 19, 2012 09:39 — forked from jinie/gist:1065394
Read binary file in ruby and print hex output
#!/usr/bin/ruby
require 'getoptlong'
filename = ""
blocksize = 1024
opts = GetoptLong.new(
[ "-f", "--file", GetoptLong::REQUIRED_ARGUMENT],
[ "-b", "--block", GetoptLong::REQUIRED_ARGUMENT]
@elvuel
elvuel / ejabberd_auth.rb
Created April 25, 2012 02:21 — forked from abloom/ejabberd_auth.rb
ejabberd auth external script
#!/usr/bin/env ruby
require 'logger'
$stdout.sync = true
$stdin.sync = true
path = "/usr/local/var/log/ejabberd/auth.log"
file = File.open(path, File::WRONLY | File::APPEND | File::CREAT)
file.sync = true
#!/usr/bin/env ruby
require 'logger'
require 'rest_client'
$stdout.sync = true
$stdin.sync = true
path = "/usr/local/var/log/ejabberd/auth.log"
file = File.open(path, File::WRONLY | File::APPEND | File::CREAT)