Skip to content

Instantly share code, notes, and snippets.

View bsstoner's full-sized avatar

Brian Stoner bsstoner

View GitHub Profile
!function(env){
env.Mixins.Events = {
bindEvents: function(events) {
if (!this._bEvents) {
this._bEvents = [];
}
for (var i=0,evt; evt=events[i]; i++) {
!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();
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;
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;
@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',
(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;
var relativeDate = (function(undefined){
var SECOND = 1000,
MINUTE = 60 * SECOND,
HOUR = 60 * MINUTE,
DAY = 24 * HOUR,
WEEK = 7 * DAY,
YEAR = DAY * 365,
MONTH = YEAR / 12;
@bsstoner
bsstoner / gist:7530799
Last active December 28, 2015 16:39
local .vimrc.after
set nocompatible
set guioptions=aAce
set number
set ruler
syntax on
" Whitespace stuff
set nowrap
@bsstoner
bsstoner / couchdb-ec2-install.sh
Created June 8, 2012 20:28 — forked from msmith/couchdb-ec2-install.sh
Set up CouchDB on EC2
#!/bin/bash
#
# This script installs and configures couchdb on a fresh Amazon Linux AMI instance.
#
# Must be run with root privileges
# Tested with Amazon Linux AMI release 2011.02.1.1 (ami-8c1fece5)
#
export BUILD_DIR="$PWD"
@bsstoner
bsstoner / http.js
Created May 21, 2012 03:30
support helper for doing http tests with mocha
/**
* Modified version of TJ's http support file from the Express repo:
* https://github.com/visionmedia/express/blob/master/test/support/http.js
*
* Module dependencies.
*/
var EventEmitter = require('events').EventEmitter
, should = require('should')
, methods = ['get','post','put','delete','head']