Skip to content

Instantly share code, notes, and snippets.

View phillipj's full-sized avatar

Phillip Johnsen phillipj

View GitHub Profile
@phillipj
phillipj / config.yaml
Last active February 3, 2019 11:31
kops example for AWS IAM authenticator debugging
apiVersion: kops/v1alpha2
kind: Cluster
metadata:
creationTimestamp: 2017-02-12T20:24:44Z
name: k8s.eu.prod.x.z
spec:
api:
loadBalancer:
type: Public
authorization:
@phillipj
phillipj / pack.js
Last active September 29, 2016 12:16
A node.js script to create a bundle containing an npm package, and all of its dependencies.
/*
* This script will download a package (and all of its dependencies) from the
* online NPM registry, then create a gzip'd tarball containing that package
* and all of its dependencies. This archive can then be copied to a machine
* without internet access and installed using npm.
*
* The idea is pretty simple:
* - npm install [package]
* - rewrite [package]/package.json to copy dependencies to bundleDependencies
* - npm pack [package]
@phillipj
phillipj / index.js
Created August 10, 2015 19:23
Handling network errors
var net = require('net');
net.connect(1216, myListener).on('error', myErrHandler);
function myListener() {
console.log('myListener got called');
}
function myErrHandler(err) {
console.log('woopsie, got error!', err);
@phillipj
phillipj / gist:9aa46af4ef0adc03017a
Created December 8, 2014 08:00
Stream -> promise -> stream
var lifestyle = require('lifestyle');
var through2 = require('through2');
var client = new lifestyle.FinnClient('http://api.finn.no/iad/');
var mapToAd = through2.obj(function (adId, encoding, callback) {
client.getAd(adId).then(function(ad) {
this.push(ad);
}.bind(this), function(err) {
console.error('YIKES, GOT ERROR!', err);
@phillipj
phillipj / fn-wrapping.js
Last active August 29, 2015 14:01
JavaScript functional wrapping experiment
// doing some functional wrapping as a proof-of-concept for extensibility
var multiply = (function createMultiplier(invokeFn) {
var invoke = invokeFn || function (a, b) {
return a * b;
};
return {
wrap: function (fn) {
return createMultiplier(fn(invoke));
Alice's Adventures in Wonderland
ALICE'S ADVENTURES IN WONDERLAND
Lewis Carroll
THE MILLENNIUM FULCRUM EDITION 3.0
@phillipj
phillipj / moreReadable.java
Created August 29, 2012 11:34
Whether or not to use multiple return statements
private boolean isReadable(String myString) {
boolean isValid = true;
// as I expect my string to be valid by default, I only need to check when the string is NOT valid
// which also means I can get rid of the second if-statement in notReadable.java
if (myString.length() == 0) {
isValid = false;
}
// ..