Skip to content

Instantly share code, notes, and snippets.

View kn0ll's full-sized avatar
🏠
Working from home

Nic Luciano kn0ll

🏠
Working from home
View GitHub Profile
@kn0ll
kn0ll / class-method.js
Created February 22, 2013 00:42
Brainy collection using a class method.
define([
'backbone'
], function(Backbone) {
return Backbone.Collection.extend({
url: '/boops'
}, {
byUserId: function(user_id) {
@kn0ll
kn0ll / emitter.coffee
Created February 10, 2013 03:30
event listener and event emitter classes inspired by backbone.
# event emitter is an object which is
# responsible for triggering events, and binding
# functions to those events.
class EventEmitter
# events map event names
# to functions which are bound
# to that event. calling model.on evt, fn
# will add that function to the events hash.
events: null
@kn0ll
kn0ll / osc.coffee
Created February 1, 2013 05:29
a demo osc gui using various backbone/osc components i've written.
require [
'zepto',
'osc/client',
'gui/range'
], ($, OscClient, RangeView) ->
osc_client = new OscClient
bar_view = new RangeView
model: osc_client
@kn0ll
kn0ll / backbone.layout.js
Created January 30, 2013 09:08
backbone layout manager. provides a simple method for mapping elements of a view to subviews.
Backbone.Layout = Backbone.View.extend({
initialize: function() {
// a map of selector -> view references
this.view_references = {};
// the promises for the data
// required before rendering the view
this.promises = this.data? _.map(this.data(), function(model) {
@kn0ll
kn0ll / keyboard.coffee
Last active December 10, 2015 22:58
a way to reflect keyboard state as a backbone model.
define [
'zepto',
'backbone'
], ($, Backbone) ->
# a singleton backbone.model whose
# attributes represent keyboard state
new class extends Backbone.Model
# bind keyboard events to model state
@kn0ll
kn0ll / extend.js
Created September 15, 2012 09:24
backbone's class inheritance isolated to a single function.
var extend = (function() {
var breaker = {};
var has = function(obj, key) {
return hasOwnProperty.call(obj, key);
};
var each = function(obj, iterator, context) {
if (obj == null) return;
@kn0ll
kn0ll / graph.js
Last active October 10, 2015 04:57
a directed tick-based "streaming" graph. used for an audio processing graph, for example.
// this is a directed graph data structure- with the unique property that it is
// intended to handle the flow of data upstream in a clock based system.
// streaming audio through a graph of nodes with variable inputs and outputs, for instance.
// an `Edge` behaves as a relation between two nodes.
// the edge is saved on both connected nodes for reference.
var Edge = function(fromNode, fromIndex, toNode, toIndex) {
this.fromNode = fromNode;
this.fromIndex = fromIndex;
this.toNode = toNode;
@kn0ll
kn0ll / waveform.js
Last active October 9, 2015 05:28
a backbone view for creating a waveform png from an audio buffer.
var BufferDrawer = Backbone.View.extend({
initialize: function(options) {
this.buffer = options.buffer;
return Backbone.Model.prototype.initialize.apply(this, arguments);
},
draw: function() {
var channels = this.buffer.channels,
@kn0ll
kn0ll / middleware.coffee
Last active October 5, 2015 17:58
dead simple connect-style middleware routing.
http = require('http')
server = http.createServer()
server.middleware = []
server.use = (middleware) ->
@middleware.push middleware
server.on 'request', (req, res) ->
@kn0ll
kn0ll / proxy.coffee
Last active November 19, 2018 10:12
a simple nodejs request proxy as connect middleware. developed as a cross domain ajax proxy.
###
a small connect middleware proxy for cross domain ajax
@path first match group will be forwarded
@host the host you want to proxy
connect_server.use proxy '^(/.+)', 'api.twitter.com'
connect_server.use proxy '^/gh(/.+)', 'api.github.com'
###