Skip to content

Instantly share code, notes, and snippets.

@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);
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: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
@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 / 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 / derp.js
Created August 3, 2012 04:14
less than O(n+m)?
var all_items = [{
"name": "cat",
"id": 1
}, {
"name": "dog",
"id": 2
}, {
"name": "spoon",
"id": 3
}, {
RestResponse r;
if (d == null) {
r = new RestResponse(something_something);
}
if (!r) {
r = new RestResponse(something_else);
}
@laser
laser / gist:2252674
Created March 30, 2012 16:34
Problem running tests with @testling - "curl: (52) Empty reply from server"
///////
// u.js
function isEmail (email) {
var regEx = /^[a-zA-Z0-9.!#$%&'*+-\/=?\^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
return regEx.test(email);
}
///////////
// test.js
@laser
laser / gist:2198227
Created March 25, 2012 16:52
Sinon.js mocked object not acknowledging calls to methods if invoked directly as callbacks of jQuery.delegate
test("Handler is invoked as callback from jQuery delegate method directly...", function() {
var Controller,
View,
$el,
c,
v,
mock;
Controller = function() {
var self = {};
@laser
laser / Sample QUnit Test
Created March 24, 2012 00:37
Mocking behavior using Sinon not working properly w/jQuery delegate method
module("Event delegation test");
test("Keyup in view should trigger callback in controller", function() {
var Controller,
View,
$el,
c,
v,
mock;