Skip to content

Instantly share code, notes, and snippets.

@jstrimpel
jstrimpel / gist:1855573
Created February 17, 2012 21:28
indexedDB Shim
(function () {
if (window.indexedDB) return false;
if (!window.openDatabase) throw "get yourself a decent browser";
var indexedDB = function () {}; // begin shim
window.indexedDB = window.indexedDB || indexedDB;
})();
@jstrimpel
jstrimpel / gist:2473110
Created April 23, 2012 19:02
underscore valid object chain and truth test
_.mixin({
validChain: function (chain, test) {
var parts = chain.split('.'), valid = false, struct = window;
if (parts[0] === 'window') parts.splice(0, 1);
valid = _.all(parts, function (part) { return struct = struct[part]; });
if (test && valid) {
if (typeof test === 'function')
return test(struct);
@jstrimpel
jstrimpel / gist:3227797
Created August 1, 2012 15:26
old haproxy conf; one of many variations used to get socket.io and ngnix playing well together
global
maxconn 4096
pidfile /var/run/haproxy.pid
debug
defaults
mode http
frontend all
bind 0.0.0.0:80
@jstrimpel
jstrimpel / gist:3321349
Created August 11, 2012 05:16
q promises in node test
var q = require('/home/wwwyzzerdd/node_modules/q'),
fs = require('fs');
var foo = function () {
var deferred = q.defer();
fs.readFile('in.txt', 'utf8', deferred.makeNodeResolver());
return deferred.promise;
};
var read = function () {
@jstrimpel
jstrimpel / gist:3354257
Created August 15, 2012 00:40
requirejs optimize build error
// main module
define(['core/text!template/main.html', 'js/foo', 'js/bar', 'js/baz'], function (template, foo, bar, baz) { });
// build.json used for optimize
{
"baseUrl": "./src/client",
"dir": "./web",
@jstrimpel
jstrimpel / gist:3743562
Created September 18, 2012 14:54
Marionette Extensions
NS.Application = Marionette.Application.extend({
constructor: function () {
var that = this, events;
Marionette.Application.prototype.constructor.apply(this, arguments);
events = {
on: function (topic, func, object) {
this.vent.on(topic, func, (object ? object : undefined));
@jstrimpel
jstrimpel / gist:6043926
Created July 20, 2013 04:56
requirejs config getting destroyed
// server start up
var requirejs = require('requirejs');
requirejs.config({
paths: {}, // bunch of paths
baseUrl: 'dirpath'
});
// request handler
// http request - much more going on here, but this is basically what happens
requirejs.optimize({ baseUrl: 'anotherdirpath', paths: {} }, function () {
@jstrimpel
jstrimpel / backbone collection push and unshift
Created August 2, 2013 04:03
What is the best method for handling polling activity feeds or infinite scroll in backbone collection views? I tied this into a backbone marionette collection view with an infinite scroll library. Is there a better way? Am I missing an easier way to handle these cases using a backbone collection?
var fetch = Backbone.Collection.prototype.fetch;
var reset = Backbone.Collection.prototype.reset;
Backbone.Collection.prototype.fetch = function (options) {
if (options.unshift || options.push) { // force a reset
options.reset = true;
}
return fetch.call(this, options);
};
@jstrimpel
jstrimpel / gist:7434663
Created November 12, 2013 17:06
I suck at regexes. I know there has to better regex for extracting all the values for a particular attribute from an of HTML string.
function getAttributeValues(html) {
var htmlSubstr = html,
match = true,
values = [],
start = 0;
while (match) {
htmlSubstr = htmlSubstr.substr(start);
match = htmlSubstr.match(/<[^>]*\s(?:some-attribute-name=["']([^"']*)["'])[^>]*>/);
if (match) {
@jstrimpel
jstrimpel / gist:10047510
Created April 7, 2014 20:36
wrap library
define(['l!app/vendor/client/d3'], functtion () {
// library code
});