Skip to content

Instantly share code, notes, and snippets.

@dhobbs
dhobbs / gulpfile.js
Created May 22, 2016 07:28 — forked from mlouro/gulpfile.js
gulpfile.js with browserify, jshint, libsass, browserSync for livereload, image optimization and system notifications on errors
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var del = require('del');
var uglify = require('gulp-uglify');
var gulpif = require('gulp-if');
var exec = require('child_process').exec;
var notify = require('gulp-notify');
@dhobbs
dhobbs / iam
Created July 2, 2014 14:51
Export IAM credentials as environment variables
#! /bin/bash
# download jq from http://stedolan.github.io/jq/
IAM_CREDS=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/[iam-role] 2>/dev/null`
export AWS_ACCESS_KEY_ID=`echo $IAM_CREDS | jq .AccessKeyId | sed -e 's/^"//' -e 's/"$//'`
export AWS_SECRET_ACCESS_KEY=`echo $IAM_CREDS | jq .SecretAccessKey | sed -e 's/^"//' -e 's/"$//'`
@dhobbs
dhobbs / nested-defs
Last active August 29, 2015 13:57
Nested defs
(ns meow.alerts
(:require [clojure.stacktrace :refer [print-stack-trace]]))
(defmacro safely [body]
`(try ~body
(catch java.lang.Throwable e#
(println "Caught exception while trying to report a problem:" (.getMessage e#))
(print-stack-trace e#))))
(defn init! [sms-send server]
@dhobbs
dhobbs / httpsRedirect
Last active December 20, 2015 16:49
HTTPS redirect
#!/usr/bin/env node
'use strict';
var http = require('http');
var listenPort = process.argv[2];
if (listenPort == undefined || isNaN(listenPort)) throw new Error('No valid port number specified. Usage: httpsRedirect [portToListenOn]');
@dhobbs
dhobbs / https-redirector
Created August 1, 2013 08:25
Java code to redirect all http requests to https, using simpleframework
private static void startHttpsRedirector() throws IOException {
org.simpleframework.http.core.Container container = new org.simpleframework.http.core.Container() {
@Override
public void handle(Request request, Response response) {
Path path = request.getPath();
Query query = request.getQuery();
String rawHost = request.getValue("host");
System.out.println("Raw host: " + rawHost);
System.out.println("Raw path: " + path);
@dhobbs
dhobbs / gist:1244690
Created September 27, 2011 09:35 — forked from lucagrulla/gist:1240766
Marks-solution
// for the origina blog post check
// http://www.markhneedham.com/blog/2011/09/25/jquery-collecting-the-results-from-a-collection-of-asynchronous-requests/
var people = ["Marc", "Liz", "Ken", "Duncan", "Uday", "Mark", "Charles"];
asyncLoop(people, [], function(name, grid, callBackFn) {
// parse data and create something cool
grid.push(somethingCool);
callBackFn();
}, function(grid) {
// do something with grid