Skip to content

Instantly share code, notes, and snippets.

View jasonwyatt's full-sized avatar
:shipit:
Typing, probably

Jason Feinstein jasonwyatt

:shipit:
Typing, probably
  • Robinhood
  • Seattle, WA
  • 14:29 (UTC -07:00)
  • X @jasonwyatt
View GitHub Profile
@jasonwyatt
jasonwyatt / mongobackup.py
Created January 10, 2013 00:33
Python script to back up MongoDB databases given a MongoDB URL and output directory path. If no Mongo URL is given, it will default to checking for a MONGOLAB_URI config variable with `heroku config`.
#!/usr/bin/env python
import os
import argparse
import logging
import datetime
import urlparse
import subprocess
logging.basicConfig(level=logging.INFO)
@jasonwyatt
jasonwyatt / bounceserver.js
Created July 11, 2012 02:58
Node.js server which will bounce requests to other servers.
/**
* bounceserver.js
* License: MIT (http://www.opensource.org/licenses/mit-license.php/)
* Author: Jason Feinstein (jason.feinstein@gmail.com)
*
* Instructions:
* 1. Install node.js: http://nodejs.org
* 2. run this file, listing the bounce addresses like so:
* node bounceserver.js http://mybounceaddress:1111/ http://google.com
* 3. Start sending requests to the server. They will be bounced properly!
@jasonwyatt
jasonwyatt / passwordgen.py
Created March 8, 2012 16:28
Random String Generator (Passwords)
def random_string(n_chars):
'''Generates a random string of length n_chars.
>>> random_string(5)
'FM>ro'
>>> random_string(8)
'"K^V]J|/'
>>> random_string(32)
')tTu,2"s`ke`MF0}qWd.-&__C8OEksQy'
@jasonwyatt
jasonwyatt / googlemaps.js
Created February 21, 2012 16:55
Google Maps RequireJS Module
(function(){
var callback = function(){},
callbackName = 'gmapscallback'+(new Date()).getTime();
window[callbackName] = callback;
define(['http://maps.googleapis.com/maps/api/js?sensor=true&callback=' + callbackName], function(){
return google.maps;
});
})();
@jasonwyatt
jasonwyatt / tl_trac_beautifier.user.js
Created November 28, 2011 16:58
TransLoc Trac Beautifier
// ==UserScript==
// @name TL Trac Beautifier
// @namespace https://dev.transloc.com
// @description Makes Trac look much better.
// @include https://dev.transloc.com/*
// ==/UserScript==
var $;
// Add jQuery
@jasonwyatt
jasonwyatt / debouncer.js
Created September 21, 2011 15:00
How to **correctly** debounce an event that will be triggered many times with identical arguments.
function debounce(fn, debounceDuration){
// summary:
// Returns a debounced function that will make sure the given
// function is not triggered too much.
// fn: Function
// Function to debounce.
// debounceDuration: Number
// OPTIONAL. The amount of time in milliseconds for which we
// will debounce the function. (defaults to 100ms)
@jasonwyatt
jasonwyatt / MySingleton.js
Created July 26, 2011 15:09
Singleton Pattern with Require JS
define(function(){
var instance = null;
function MySingleton(){
if(instance !== null){
throw new Error("Cannot instantiate more than one MySingleton, use MySingleton.getInstance()");
}
this.initialize();
}
@jasonwyatt
jasonwyatt / polylinefade.js
Created November 18, 2010 17:13
Fade out a google maps polyline.
function fadeOut(line, keepAround, fadeDuration){
keepAround = keepAround || 1000;
fadeDuration = fadeDuration || 500;
setTimeout(function(){
var startingOpacity = line.strokeOpacity,
startTime = (new Date()).getTime();
function step(){
var currentTime = (new Date()).getTime(),
// Triggers the 'onresize' event for the window manually.
if(document.createEventObject){
window.fireEvent('onresize', document.createEventObject());
} else {
var evt = document.createEvent("HTMLEvents");
evt.initEvent('resize', true, true);
window.dispatchEvent(evt);
}
dojo.require('dojo.window');
dojo.addOnLoad(function(){
var body = dojo.body(),
footerId = 'footer'; // change this to whatever your footer's id is.
function adjustFooter(){
dojo.create('div', {style: 'clear:both', id: 'adjustFooter'}, body);
var bodySize = dojo.marginBox(body),
windowSize = dojo.window.getBox(),
changes = { 'bottom': '0px', 'clear': '', 'position': 'absolute' };