Skip to content

Instantly share code, notes, and snippets.

View twhid's full-sized avatar
💭
⌨️ probably clacking

Tim Whidden twhid

💭
⌨️ probably clacking
View GitHub Profile
@twhid
twhid / unix-timestamp-converter.js
Created April 19, 2014 02:24
BBEdit Text Filter to transform unix timestamp to human a readable string in the UTC time zone.
#!/usr/local/bin/node
// Note that a more standard node hashbang doesn't seem to work
// in a BBEdit Text Filter (or perhaps it's Homebrew installed node weirdness).
// So, change the hashbang to a path to your node executable
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (data) {
@twhid
twhid / resolveModuleDirPath.js
Created June 11, 2015 18:25
One-liner to resolve the directory path of a module using the built-in Node.js algorithm
var moduleDir = require.resolve('module/package').replace('package.json', '');
@twhid
twhid / image-contracts-v3.js
Created September 15, 2015 19:19 — forked from nameofname/image-contracts-v3.json
New Image Contract idea
// NOTE* The notations below assume that there is only 1 size per image, ie. new dynamically sized images are already working :
// POST a new image :
// soa/inventory-3/2/image
// payload : multi part form-data
// return value :
{
id : '123',
original : '/path/to/original.jpeg',
master : '/path/to/master.jpeg',
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Skeleton Parent Page</title>
<style type="text/css">
html {
width: 100%;
height: 100%;
}
@twhid
twhid / gist:2648062
Created May 9, 2012 19:05
grunt task to deploy JS files to S3 with awssum
grunt.registerMultiTask('s3deploy', 'deploy to S3 using awssum', function () {
// dependencies
var awssum = require('awssum'),
fs = require('fs'),
path = require('path'),
aws = require('./settings').aws;
var amz = awssum.load('amazon/amazon'),
AmazonS3 = awssum.load('amazon/s3'),
s3 = new AmazonS3(aws.accessKey, aws.secretKey, aws.accountId , amz.US_EAST_1),
@twhid
twhid / helper.html
Created July 25, 2012 17:04
elledecor/1stdibs cross-frame helper code
<!--
* 1stdibs cross-domain iframe helper
* put this near the top of the page
-->
<script type="text/javascript">
(function () {
// SET DOCUMENT.DOMAIN FOR CROSS-FRAME COMMUNICATION
var domain = document.location.hostname.split('.');
document.domain = domain[domain.length-2] + '.' + domain[domain.length-1];
@twhid
twhid / uglify.js
Last active November 13, 2015 11:13
#!/usr/local/bin/node
// BBEdit text filter to uglify Javascript.
// Uses the default compression options, *except* it turns off warnings because they cause the script to error out.
//
// Requires uglifyjs https://github.com/mishoo/UglifyJS2
// In this example, I've installed uglifyjs globally via `npm install uglify-js -g`
// Your install directory may be different...
var UglifyJS = require('/usr/local/share/npm/lib/node_modules/uglify-js');
@twhid
twhid / pre-commit
Last active November 13, 2015 18:42
Run JSHint validation before commit.
#!/bin/sh
#
# Run JSHint validation before commit.
#
# Originally: http://stackoverflow.com/a/21238963/302550
#
# Requires Node (http://nodejs.org/) and jshint (https://www.npmjs.org/package/jshint)
# be globally installed (e.g.: npm install jshint -g).
#
# Edited slightly to make it easier to work with Git GUIs (e.g. PHPStorm IDE, Tower).
@twhid
twhid / cssmin.js
Created May 3, 2012 17:13 — forked from FiNGAHOLiC/cssmin.js
grunt cssmin sqwish task
// grunt minify CSS task using sqwish
grunt.registerMultiTask('cssmin', 'minify css with sqwish', function () {
var sqwish = require('sqwish'),
dest = this.file.dest;
try {
var css = grunt.file.read(this.file.src),
min = sqwish.minify(css);
@twhid
twhid / docker.jenkins.github.sh
Last active May 24, 2016 17:29
bash script to build docker images of node apps via jenkins jobs. Requires jq and the Jenkins GitHub plugin.
#!/usr/bin/env bash
# AWS domain
DOMAIN=${AWS_DOMAIN}
# Set CI_TEST to true to exit the script before build commences.
TEST=${CI_TEST:-'false'}
# Defaults for testing (variables supplied by Jenkins when in that environment).
GIT_URL=${GIT_URL:-"git@github.com:foo/foo-bar-baz-qux.git"}