Skip to content

Instantly share code, notes, and snippets.

@cmawhorter
cmawhorter / workaround-s3-rename.js
Created October 6, 2015 18:03
Help workaround discrepancy between OS directory names and S3 key name collisions
'use strict';
// Script to workaround discrepancies in s3 <=> os file and directory names.
// It allows you to host your static website on s3 without trailing slashes.
// e.g. example.com/products and example.com/products/mugs
if (!process.argv[2]) throw new Error('Must pass bucket as argument');
var options = {
target: '.',
@cmawhorter
cmawhorter / pr-http-proxy-test.js
Created July 6, 2015 16:58
node http-proxy pr perf test
process.title = 'node http-proxy';
var CONCURRENCY = 250;
var assert = require('assert')
, crypto = require('crypto')
, http = require('http');
http.globalAgent.maxSockets = Infinity;
@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 / find-elements-that-are-too-wide.js
Last active September 2, 2016 07:38
Checks every element in a page to see if it's total width is wider than the container (viewport by default). Might be useful to track down unwanted horizontal scroll bars.
// Deps on jquery
(function(container) {
var viewportWidth = $(container).width();
console.group('Overflow Check');
console.info('Container Width: %s', viewportWidth);
$('*').each(function() {
var $this = $(this);
var elWidth = $this.outerWidth(true);
if (elWidth > viewportWidth) {
console.warn('Overflow by %spx!', elWidth - viewportWidth, loggingVars, this);
@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 / 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 / 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({
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cmawhorter
cmawhorter / init-dev.sh
Created November 17, 2014 18:32
Configure a cordova environment to use Crosswalk and be capable of building either ARM or x86 binaries
#!/usr/bin/env sh
# Expects this dir structure:
# libs (tip: symlink these)
# crosswalk_x86
# crosswalk_arm
# src
# client
# ...
# hooks
@cmawhorter
cmawhorter / .bash_profile
Created October 21, 2014 19:53
Add alias to bash_profile to get a quick http server anywhere. Just type H to serve current directory.
# http://stackoverflow.com/a/12269225/670023
# Binds to localhost
alias H="echo 'Serving HTTP on 127.0.0.1 port 8000 ...'; python -c 'import BaseHTTPServer as bhs, SimpleHTTPServer as shs; bhs.HTTPServer((\"127.0.0.1\", 8000), shs.SimpleHTTPRequestHandler).serve_forever()'"