Skip to content

Instantly share code, notes, and snippets.

View bsstoner's full-sized avatar

Brian Stoner bsstoner

View GitHub Profile
(function ($) {
// this is a binary search that operates via a function
// func should return < 0 if it should search smaller values
// func should return > 0 if it should search larger values
// func should return = 0 if the exact value is found
// Note: this function handles multiple matches and will return the last match
// this returns -1 if no match is found
function binarySearch(length, func) {
var low = 0;
@bsstoner
bsstoner / gist:b62e17311237d2d9da2a
Created May 2, 2014 19:44
Object.keys polyfill
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
if (!Object.keys) {
Object.keys = (function () {
'use strict';
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
dontEnums = [
'toString',
'toLocaleString',
'valueOf',
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement, fromIndex) {
if ( this === undefined || this === null ) {
throw new TypeError( '"this" is null or not defined' );
}
var length = this.length >>> 0; // Hack to convert object.length to a UInt32
fromIndex = +fromIndex || 0;
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun/*, thisArg*/) {
'use strict';
if (this === void 0 || this === null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
!function destroyViews(views){
if (!views) { return; }
var v;
if ($.isArray(views)) {
for (var i=0; i<views.length; i++) {
v = views[i];
if(v && $.isArray(v)){
destroyViews(v);
} else {
v && v.destroy && v.destroy();
!function(env){
env.Mixins.Events = {
bindEvents: function(events) {
if (!this._bEvents) {
this._bEvents = [];
}
for (var i=0,evt; evt=events[i]; i++) {
###########################################################################
## Playing around with the awesome Echonest Remix API.
##
## http://code.google.com/p/echo-nest-remix/
##
## This is a script that will loop 4 beats from track 1 and mix them
## behind track 2., also syncing the track tempos
##
## Change the variables below.
###########################################################################
/**
* SocketManager - Singleton to manage multi-channel socket 'routing', need a way to merge with socket.io so client sessions aren't stored twice in memory,
*
* Requires Socket.IO-node and Socket.IO client libraries.
*
* Usage:
* in your main app.js file (or whereever you create the server)
*
* var io = require('socket.io'),
* sm = require('socketmanager');
cd /path/to/files/
for fl in *.js; do
mv $fl $fl.old
sed -e 's/find_string/replace_string/' $fl.old > $fl
rm -f $fl.old
done
@bsstoner
bsstoner / Node.js OpenTokSDK
Created November 20, 2010 04:28
Node.js implementation of Tokbox's OpenTokSDK
/**
* Node.js implementation of Tokbox's OpenTokSDK
*
* by Brian Stoner
*
* var tokbox = require('./tokbox')
*
* var t = new tokbox.OpenTokSDK(API_KEY,API_SECRET)
*
* t.createSession('127.0.0.1', {}, function(session){