Skip to content

Instantly share code, notes, and snippets.

@laser
laser / triggers-differences.js
Created September 18, 2012 16:30
Difference in callback arguments when publishing via "triggers" mechanism
// CollectionView + ItemView example
var MySubView = Marionette.ItemView.extend({
"triggers": {
"click .save": "widget:saved"
}
});
var MyCollectionView = Marionette.CollectionView.extend({
"initialize": function(options) {
@laser
laser / gist:4520238
Last active December 11, 2015 00:59
gross?
165 def testUnableToRemoveOwnerProjectAccess(self):
166 try:
167 raise barrister.RpcException(40, "dingle")
168 except barrister.RpcException as e:
169 assert e.code == 40
//
@laser
laser / gist:4520708
Last active December 11, 2015 00:59
def assertUserValidationException(fx):
def decorator(fx):
try:
fx()
except barrister.RpcException as e:
assert e.code == 1002
else:
assert False, "Should have thrown an RpcException with status code 1002"
return decorator
app.get('/proxied_image/:image_url', function(request_from_client, response_to_client){
sys.puts("Starting proxy");
var image_url = request_from_client.params.image_url;
var image_host_name = url.parse(image_url).hostname
var filename = url.parse(image_url).pathname.split("/").pop()
var http_client = http.createClient(80, image_host_name);
var image_get_request = http_client.request('GET', image_url, {"host": image_host_name});
image_get_request.addListener('response', function(proxy_response){
@laser
laser / gist:5585470
Last active December 17, 2015 09:09
A collection of views, in Backbone
window.BaseListView = window.BaseView.extend({
close: function() {
this._closeAllSubViews();
window.BaseView.prototype.close.call(this);
},
initialize: function(options) {
this._subViews = [];
this.collection.on("add", this._renderSubView, this);
this.collection.on("reset", this._renderSubViews, this);
this.collection.on("remove", this._closeSubView, this);
@laser
laser / gist:5629587
Created May 22, 2013 18:05
class level thread safety...
// defining attr_accessor on singleton Class instance of Foo
class Foo
class << self
attr_accessor :color
end
end
// not threadsafe
@laser
laser / sinatra-bp-p1-baseline.rb
Last active December 18, 2015 22:09
Sinatra Best Practices: Part One (baseline)
########
# app.rb
#
require 'sinatra'
set :root, File.dirname(__FILE__)
enable :sessions
@laser
laser / sinatra-bp-p1-modular.rb
Created June 24, 2013 19:56
Use the "modular style"
########
# app.rb
#
require 'sinatra/base'
class SimpleApp < Sinatra::Base
set :root, File.dirname(__FILE__)
@laser
laser / sinatra-bp-p1-rackup.ru
Last active December 18, 2015 22:18
Start it up with Rack
###########
# config.ru
#
require File.dirname(__FILE__) + '/app'
run SimpleApp
########
# app.rb
#
require 'sinatra/base'
class SimpleApp < Sinatra::Base
set :root, File.dirname(__FILE__)