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 / 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 / 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 / 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 / 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 / session.coffee
Created February 28, 2013 04:53
a session model for brainy
define [
'backbone',
'resources/user'
], (Backbone, User) ->
class extends Backbone.Model
idAttribute: '_id'
urlRoot: '/sessions'
defaults:
@kn0ll
kn0ll / backbone.layout.js
Last active December 19, 2015 00:28
simple backbone layout manager (simple subview definitions, with listener cleanup)
Backbone.Layout = Backbone.View.extend({
initialize: function() {
this.viewReferences = {};
Backbone.View.prototype.initialize.apply(this, arguments);
},
setView: function(selector, view) {
var $foundViewNode = $(selector, this.$el),
previousView = this.viewReferences[selector];
@kn0ll
kn0ll / backbone.collectionlayout.js
Created June 26, 2013 15:39
simple backbone collection layout. extends backbone.layout.js. accepts an `ItemView` and a `collection` and appends a new `ItemView` to it's parent container for each model in the collection
Backbone.CollectionLayout = Backbone.Layout.extend({
initialize: function() {
Backbone.Layout.prototype.initialize.apply(this, arguments);
this.listenTo(this.collection, 'add', _.bind(this.modelAdded, this));
},
ItemView: Backbone.Layout,
modelAdded: function(model) {
@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'
###
@kn0ll
kn0ll / useHass.ts
Last active December 21, 2019 10:27
home assistant react hooks
import constate from "constate";
import * as React from "react";
import {
Connection,
subscribeEntities,
HassEntities,
AuthData,
Auth,
createConnection
} from "home-assistant-js-websocket";
@kn0ll
kn0ll / QueryRenderer.tsx
Last active July 23, 2020 20:46
attempts to abstract / manage handling apollo network logic. a strongly typed pattern matching type thing for Apollo
import * as React from 'react';
import { QueryResult } from 'react-apollo';
import { ApolloError } from 'apollo-client';
export enum QueryRendererState {
LOADING,
EXPECTED_ERROR,
UNEXPECTED_ERROR,
READY,
}