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
  • 03:55 (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!
import java.util.regex.Pattern
class VersionInfo {
private static Pattern VERSION_NAME_PATTERN = Pattern.compile("versionName='([0-9]+(\\.[0-9]+)+)'", Pattern.MULTILINE)
private static Pattern VERSION_CODE_PATTERN = Pattern.compile("versionCode='([0-9]+)'", Pattern.MULTILINE)
public File apkFile;
public String versionName;
public int versionCode;
public VersionInfo(File apkFile, String aaptOutput) {
@jasonwyatt
jasonwyatt / salted_passwords.py
Created January 10, 2013 01:30
Functions for hashing passwords, generating salts, and testing input passwords.
import base64
import uuid
import hashlib
def hash_password(password, salt=None):
if salt is None:
salt = uuid.uuid4().hex
hashed_password = hashlib.sha512(password + salt).hexdigest()
@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 / VersionInfo.groovy
Created August 2, 2017 17:34
Get versionName and versionCode from APK file.
class VersionInfo {
public static Pattern VERSION_NAME_PATTERN = Pattern.compile("versionName='([0-9]+(\\.[0-9]+)+)'", Pattern.MULTILINE)
public static Pattern VERSION_CODE_PATTERN = Pattern.compile("versionCode='([0-9]+)'", Pattern.MULTILINE)
public File apkFile;
public String versionName;
public int versionCode;
public VersionInfo(File apkFile, String versionName, int versionCode) {
this.apkFile = apkFile;
this.versionName = versionName
// 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);
}
@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)
def getVersionInfo = { File apkFile ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine getAaptPath(), "dump", "badging", apkFile.absoluteFile
standardOutput = stdout
}
return new VersionInfo(apkFile, stdout.toString())
}
import java.util.regex.Pattern
class VersionInfo {
private static Pattern VERSION_NAME_PATTERN = Pattern.compile("versionName='([0-9]+(\\.[0-9]+)+)'", Pattern.MULTILINE)
private static Pattern VERSION_CODE_PATTERN = Pattern.compile("versionCode='([0-9]+)'", Pattern.MULTILINE)
public File apkFile;
public String versionName;
public int versionCode;
public VersionInfo(File apkFile, String aaptOutput) {