Skip to content

Instantly share code, notes, and snippets.

View Fauntleroy's full-sized avatar

Timothy Kempf Fauntleroy

View GitHub Profile
// Thing constructor
var Thing = function(){
this.pies = ['cherry','apple'];
};
Thing.prototype = {};
Object.defineProperties( Thing.prototype, {
piescount: {
get: function(){ return this.pies.length; }
var shoe = require('shoe');
var through = require('through');
var result = document.getElementById('result');
var stream = shoe('/chat');
stream.on( 'data', function( msg ){
console.log( 'data', msg );
});
var getElementsByClass = function( classname ){
var els_with_class = [];
var els = document.getElementsByTagName('*');
for( var i = 0; i < els.length; i++ ){
var el = els[i];
if( el.className.split(' ').indexOf( classname ) > -1 ) els_with_class.push( el );
}
return els_with_class;
};
@Fauntleroy
Fauntleroy / index.js
Created February 20, 2014 20:23
Use browserify + hbsfy to render solidus widgets client side
var $ = require('jquery');
// Set up hbsfy for Solidus feature parity
var Handlebars = require('hbsfy/runtime');
// Pull in Handlebars helpers
var HandlebarsHelper = require('handlebars-helper');
HandlebarsHelper.help( Handlebars );
// Set partials
Handlebars.registerPartial( 'favorite', require('../../views/favorite.hbs') );
@Fauntleroy
Fauntleroy / gulpfile.js
Created February 21, 2014 01:24
I'm terrible at uglifyify
var gulp = require('gulp');
var vinylSource = require('vinyl-source-stream');
var watchify = require('watchify');
gulp.task( 'browserify', function(){
// use watchify instead of gulp-browserify and gulp.watch
var bundler = watchify('./src/universe-experiment.js');
bundler.transform('hbsfy');
bundler.transform('uglifyify');
var rebundle = function(){
@Fauntleroy
Fauntleroy / Modular.js
Last active August 29, 2015 13:56
"Modular" self-rendering module example
var NO_OP = function(){};
var domready = require('domready');
var sizzle = require('sizzle');
var elClass = require('element-class');
var jsonp = require('jsonp');
var xhr = require('xhr');
var Modular = function( config ){
this.url = config.url;
@Fauntleroy
Fauntleroy / client.js
Last active August 29, 2015 13:56
RPC + data stream
var rpc = require('rpc-stream');
var engine = require('engine.io-stream');
var rpc_client = rpc();
var engine_stream = engine('/test');
remote = rpc_client.wrap(['addMessage']);
engine_stream
.pipe( rpc_client )
// assume this is node.js/browserify land so this is actually private
var next_server_number = function( servers ){
var current_int = 1;
servers = servers.sort( function( a, b ){
return a - b;
});
for( var i = 0; i < servers.length; i++ ){
if( current_int === servers[i] ){
current_int++;
}
@Fauntleroy
Fauntleroy / gist:9868613
Created March 30, 2014 06:35
geochat issue
Uncaught exception: Error: Firebase.child failed: First argument was an invalid path: "null". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"
Error thrown at line 3, column 2 in g(a) in https://cdn.firebase.com/v0/firebase.js:
throw a;
called from line 275, column 2 in Ia(a, b) in https://cdn.firebase.com/v0/firebase.js:
(!u(b) || 0 === b.length || ya.test(b)) && g(Error(A(a, 1, l) + 'was an invalid path: "' + b + '". Paths must be non-empty strings and can\'t contain ".", "#", "$", "[", or "]"'))
called from line 3844, column 4 in <anonymous function: H.prototype.F>(a) in https://cdn.firebase.com/v0/firebase.js:
Ia("Firebase.child", a);
called from line 106, column 2 in createUserNode(username) in https://dl.dropboxusercontent.com/u/1330446/geochat/js/scripts.js:
userRef = allUserRef.child(username);
@Fauntleroy
Fauntleroy / index.js
Last active August 29, 2015 14:02
Poopy lil' form value parser
var dom = require('domquery');
var domready = require('domready');
var forEach = Array.prototype.forEach;
var getFormData = function( form ){
var form_data = {};
forEach.call( form.elements, function( el, i ){
switch( el.tagName ){
case 'INPUT':
case 'TEXTAREA':