Skip to content

Instantly share code, notes, and snippets.

@cmawhorter
cmawhorter / workaround.js
Created January 13, 2015 23:41
hmmac issue #10 workaround
// https://github.com/cmawhorter/hmmac/issues/10
var app = require('express')();
var Hmmac = require('hmmac');
var AWS = require('aws-sdk');
var accessKeyId = 's3box';
var secretAccessKey = 's3box';
var hmmac = new Hmmac({
@cmawhorter
cmawhorter / hash-object.js
Created February 20, 2015 19:40
Deep complex object fingerprinting/hashing in nodejs javascript (recursive).
var crypto = require('crypto');
var ALGO = 'sha256';
function hashValue(val) {
var hash = crypto.createHash(ALGO)
, target;
switch (toString.call(val)) {
case '[object Object]':
target = hashObject(val);
@cmawhorter
cmawhorter / load-large-json.js
Created April 30, 2015 00:37
I was getting V8 crashes in nodejs 0.12.1 while trying to load large (not really. 500mb.) JSON files and so I needed this.
// This loads large-ish new line separated JSON files into memory. If you need truly large file support
// and getting errors, you might want to google nodejs v8 heap limit or something.
// I believe it's the --max-old-space-size option in particular.
// Another script I wrote generated the JSON files in this
// format, so this script matches the format.
// File Lines:
// 1. [
// 2. null
// 3. , { some: 'object', data: 'here' }
@cmawhorter
cmawhorter / http-proxy-leak-test.js
Created July 6, 2015 16:51
node http-proxy leaks somewhere. presumably sockets
process.title = 'node http-proxy';
var CONCURRENCY = 250;
var assert = require('assert')
, crypto = require('crypto')
, http = require('http');
http.globalAgent.maxSockets = Infinity;
@cmawhorter
cmawhorter / patch-document-createelement-for-gwt.js
Last active November 12, 2015 05:14
Older versions of GWT used document.createElement incorrectly which leads to an Invalid Character error
// If you're supporting an app built with GWT and running into Invalid Character errors
// in older version of IE, this patch should fix it with no GWT code changes.
//
// Just include thes script before before including your gwt <script src="app.nocache.js">
//
// Yay. GWT magically working again.
// NOTE: Does a console.warn "Init document.createElement interception..." prior to running.
// NOTE: If the patch ever encounters an error it will fall back to the native browser
@cmawhorter
cmawhorter / spc
Created March 10, 2013 01:03
Simple shell script to output a number of blank lines. Defaults to 30.
#!/usr/bin/env bash
# usage: `spc` or `spc [number of lines]`
lines=${1:-30}
for ((i=1; i<=$lines; i++))
do
echo
done
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid
@cmawhorter
cmawhorter / redis.conf
Created June 7, 2013 00:16
default redis 2.6.10 conf with daemonize set to yes
# Redis configuration file example
# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
@cmawhorter
cmawhorter / wait-for-state-example.js
Created December 23, 2015 03:53
Wait for all values in state to be true before calling callback or error on timeout.
// similar usecase; abbreviated
var myTask = function(callback) {
var state = { response: false, body: false, other: null }; // only t/f factored when enableNulls
var abortWait = waitForState(state, callback); // returns function to abort with error
var req = request('https://...');
req.on('response', function(res) {
asyncLogResponse(function(err) {
if (err) return abortWait(err); // aborts wait and callbacks immediately
state.response = true;
@cmawhorter
cmawhorter / lambda-functionWhileThrottled.js
Last active December 24, 2015 01:59
Script to trigger lambda throttling. Creates many concurrent lambda calls to a long-running function.
// just a control; doesn't matter specifics
exports.handler = function(event, context) {
console.log('starting');
setTimeout(function() {
console.log('done');
context.succeed();
}, 1000);
};