Skip to content

Instantly share code, notes, and snippets.

View jhurliman's full-sized avatar
🐨

John Hurliman jhurliman

🐨
View GitHub Profile
@jhurliman
jhurliman / UIColor+Lerp.m
Created April 18, 2015 06:12
UIColor Linear Interpolation (lerp)
+ (UIColor *)colorLerpFrom:(UIColor *)start to:(UIColor *)end withProgress:(CGFloat)t
{
// TODO: Interpolate in HSB space instead of RGB
t = MAX(0, MIN(1, t));
CGFloat redA, greenA, blueA, alphaA;
[start getRed:&redA green:&greenA blue:&blueA alpha:&alphaA];
CGFloat redB, greenB, blueB, alphaB;
[end getRed:&redB green:&greenB blue:&blueB alpha:&alphaB];
@jhurliman
jhurliman / Async.swift
Created July 24, 2015 08:00
Async.swift
import Foundation
typealias Callback = () -> ()
typealias DoneCallback = (error: NSError?) -> ()
typealias ItemCallback = (i: Int, done: DoneCallback) -> ()
func each(range: Range<Int>, exec: ItemCallback, done: DoneCallback) {
var pending = 0
for i in range {
@jhurliman
jhurliman / keybase.md
Created July 31, 2015 20:52
keybase.md

Keybase proof

I hereby claim:

  • I am jhurliman on github.
  • I am jhurliman (https://keybase.io/jhurliman) on keybase.
  • I have a public key whose fingerprint is 69B3 1804 7775 BCB5 89D8 6114 53FB 287A E5DD 51C1

To claim this, I am signing this object:

@jhurliman
jhurliman / getopts.sh
Created August 25, 2015 22:44
Parse command line options in pure bash
# Parse command line arguments
while [[ $# > 1 ]]; do
local key="$1"
case $key in
-g|--github-token)
GITHUB_TOKEN="$2"
shift
;;
# Catch-all
*)
@jhurliman
jhurliman / returnError.js
Created September 14, 2015 01:26
Difference between "return new Error()" and "throw new Error" in bluebird
var P = require('bluebird');
P.resolve().then(function () {
// Change this to throw new Error to get the expected behavior
if (true) return new Error('Returned error');
return { key: { subKey: 'test' } };
}).then(function (obj) {
// This will crash if return new Error is used since the Error is not caught by bluebird
console.log('obj.key.subKey = %s', obj.key.subKey);
}).catch(function (err) {
@jhurliman
jhurliman / crosswalk2014-excerpt.tsv
Created September 21, 2015 16:31
crosswalk2014-excerpt.tsv
00100300 Faulkner University Faulkner University Yes [YCY] 101189
00100301 Faulkner University Faulkner University - Birmingham Center Yes [YCY] 101189
00100303 Faulkner University Faulkner University - Huntsville Center Yes [YCY] 101189
00100304 Faulkner University Faulkner University - Mobile Center Yes [YCY] 101189
00100305 Faulkner University Faulkner University - No [NNN] 101189
00100306 Faulkner University Faulkner University - No [NNN] 101189
00100307 Faulkner University Faulkner University - No [NNN] 101189
00100308 Faulkner University Faulkner University - No [NNN] 101189
00100309 Faulkner University Faulkner University - No [NNN] 101189
00100310 Faulkner University Faulkner University - No [NNN] 101189
@jhurliman
jhurliman / .prompt
Created October 12, 2015 17:16
Bash prompt with git support
# source /usr/local/etc/bash_completion.d/git-prompt.sh
PROMPT_COMMAND=__generate_prompt
__generate_prompt() {
# Undocumented function that updates OS X Terminal\'s knowledge of
# the current
# working directory. Required for Cmd + T to open a new tab in the same
# directory.
#
# See '/etc/bashrc' on an OS X box for details.
@jhurliman
jhurliman / ec2-instance-info.js
Created November 6, 2015 22:25
Retrieve metadata about the host EC2 instance
var P = require('bluebird');
var request = P.promisify(require('request'));
P.promisifyAll(request);
exports.currentInstanceInfo = currentInstanceInfo;
var INSTANCE_BASE_URL = 'http://169.254.169.254/2014-11-05/';
currentInstanceInfo().then(res => console.dir(res));
@jhurliman
jhurliman / uuid.js
Created November 22, 2015 04:31
Generate V4 UUIDs in node.js
function uuid() {
var bytes = require('crypto').randomBytes(16);
bytes[6] = (bytes[6] & 0x0f) | 0x40;
bytes[8] = (bytes[8] & 0x3f) | 0x80;
var str = bytes.toString('hex');
return str.substr(0, 8) + '-' +
str.substr(8, 4) + '-' +
str.substr(12, 4) + '-' +
str.substr(16, 4) + '-' +
str.substr(20, 12);
@jhurliman
jhurliman / optimization-test.js
Last active December 13, 2015 20:17
Use V8 internal methods to test if a JS function can be optimized
/**
* Based on code from <https://github.com/petkaantonov/bluebird/wiki/Optimization-killers>
* Run this script using:
* `node --allow-natives-syntax optimization-test.js`
* For more diagnostic output use:
* `node --trace_opt --trace_deopt --allow-natives-syntax optimization-test.js`
*/
function myFunction() {
return 'hello world';