Skip to content

Instantly share code, notes, and snippets.

View traviskaufman's full-sized avatar

Travis Kaufman traviskaufman

View GitHub Profile
@jakemcgraw
jakemcgraw / module.js
Last active February 24, 2016 20:18
Pattern for blue compatible modules
modules.export = (function(){
var Promise = require('bluebird');
var fs = Promise.promisifyAll(require('fs'));
return function(params, cb) {
return fs.doSomeStuffAsync(params)
.then(function(result){
return someOtherAsync(result);
})
.then(function(moreResults){
return someMoreAsync(moreResults);
@oxbowlakes
oxbowlakes / scala-interview2.scala
Created March 2, 2012 12:08
Scala interview questions hard
trait MyList[+A] {
def fold[B](k: Option[(A, B)] => B): B
def map[B](f: A => B): MyList[B] = sys.error("Implement me in terms of fold")
def flatMap[B](f: A => MyList[B]): MyList[B] = sys.error("Implement me in terms of fold")
def headOption: Option[B] = sys.error("Implement me in terms of fold")
def tailOption: Option[MyList[B]] = sys.error("Implement me in terms of fold")
def isEmpty = sys.error("Implement me in terms of fold")
def length = sys.error("Implement me in terms of fold")
}
@ishikawa
ishikawa / HeapPermute.java
Created November 5, 2008 00:16
B. Heap's permutation algorithm
import java.util.Arrays;
/**
* http://lucitworks.com/Snippets/Algorithms/permutation.htm
*/
public class HeapPermute {
private static void swap(int[] v, int i, int j) {
int t = v[i]; v[i] = v[j]; v[j] = t;
}
@jelbourn
jelbourn / alpha-blend.scss
Last active September 12, 2018 03:50
SCSS alpha blend
// Overlays one color on top of another and returns the resulting color.
// This is used to determine contrast ratio for two colors with partial opacity.
// See http://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
@function alpha-blend($overlay, $base) {
$overlayAlpha: alpha($overlay);
$baseAlpha: alpha($base);
// If the overlaid color is completely opaque, then the result is just going to be that color.
@if $overlayAlpha >= 1 {
@return $overlay;
@domenic
domenic / iterator-of-promises.js
Created July 12, 2013 21:27
Iterator of promises: forEach
function iteratorOfPromisesForEach(iterator, callback) {
var snapshot = iterator.next();
if (snapshot.done) {
return Promise.resolve();
}
return snapshot.value.then(callback).then(() => iteratorOfPromisesForEach(iterator, callback));
}
var result = iteratorOfPromisesForEach(filesIterator, function (file) {
// return immediately to just do sync processing
@simonexmachina
simonexmachina / .gitignore
Last active October 24, 2019 05:44
Example .gitignore file for iOS projects
## Build generated
build/
DerivedData
build.xcarchive
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
@clarkdave
clarkdave / nconf-yaml.js
Created August 20, 2014 11:19
Load YAML config files using nconf (nodejs)
var nconf = require('nconf');
var yaml = require('js-yaml');
var app_config = __dirname + '../config/application.yml';
// load cmd line args and environment vars
nconf.argv().env();
// load a yaml file using a custom formatter
nconf.file({
@olivierlacan
olivierlacan / migrate_postgresql_database.md
Last active March 24, 2022 20:30
How to migrate a Homebrew-installed PostgreSQL database to a new major version (9.3 to 9.4) on OS X. See upgraded version of this guide: http://olivierlacan.com/posts/migrating-homebrew-postgres-to-a-new-version/

This guide assumes that you recently run brew upgrade postgresql and discovered to your dismay that you accidentally bumped from one major version to another: say 9.3.x to 9.4.x. Yes, that is a major version bump in PG land.

First let's check something.

brew info postgresql

The top of what gets printed as a result is the most important:

@pwalsh
pwalsh / appengine-service-accounts-on-devserver.md
Last active May 17, 2022 18:07
Google App Engine Service Accounts that work in local development: A guide for the lost and weary

It is easy to get service accounts working with App Engine's app_devserver.py - once you know how.

On the way there, you might have pulled out all your hair following one documentation dead end after another, trying to piece together the right information.

Here are the steps you need to take, in exact order, to get this working. Once you follow these steps, you'll be able to use service accounts in local development, so that you can interact with Google APIs (e.g.: Spreadsheet, Calendar) in a way that is consistent with the deployment environment on App Engine.

In order to follow the instructions, you'll be better off using the latest UI for Google Cloud projects. Older interfaces (such as the dedicated App Engine dashboard) have things in different places, under different names, etc. It is a world of pain there.

Also note that I've tested this on several 1.9.x releases of App Engine; I can't confirm the behaviour of earlier releases.

@jlbruno
jlbruno / ordinal.js
Last active July 28, 2022 14:58
Javascript Ordinal Numbers
// found here http://forums.shopify.com/categories/2/posts/29259
var getOrdinal = function(n) {
var s=["th","st","nd","rd"],
v=n%100;
return n+(s[(v-20)%10]||s[v]||s[0]);
}