Skip to content

Instantly share code, notes, and snippets.

View JoeStanton's full-sized avatar

Joe Stanton JoeStanton

  • DeepMind
  • London
View GitHub Profile
@JoeStanton
JoeStanton / pipe.js
Last active January 28, 2016 13:05
Piping - In the absence of the `|>` operator, a Clojure-like threading function
import {map, unique} from "prelude-ls";
function pipe(input, ...funcs) {
return funcs.reduce((step, f) => f(step), input);
}
function curry(fn, ...args) {
if (args.length >= fn.length) {
return fn(...args);
}
@JoeStanton
JoeStanton / pipe.js
Created January 28, 2016 11:36
Nice ES7 pipeline syntax
import {map, unique, sort} from "prelude-ls"
types
::map(v => v[type])
::unique
::sort
::map(toOption);
@JoeStanton
JoeStanton / flow-runtime-types.js
Last active October 2, 2016 23:05
Flow Runtime Types
type Suit =
| "Diamonds"
| "Clubs"
| "Hearts"
| "Spades";
// Babel transformed into Flow AST:
export const SuitType = {
type: 'UnionTypeAnnotation',
import {SuitType} from "./types";
import {generateSchema} from "flow-runtime";
const validate = (value, type) => {
return joi.validate(value, generateSchema(type), {
abortEarly: false
});
}
// Validation calls
// Type Definitions
type UserListing = {
users: Array<User>
}
type ProfilePic = {
url: string,
width: number,
height: number
@JoeStanton
JoeStanton / handler.js
Last active January 17, 2017 14:24
Lambda container lifetime
var startedAt = (new Date).toString();
var lastExecuted = null;
exports.ping = function(event, context, done) {
lastExecutedCopy = lastExecuted;
lastExecuted = (new Date).toString();
done(null, {
warm: !!lastExecutedCopy,
startedAt: startedAt,
last: lastExecutedCopy,
@JoeStanton
JoeStanton / ntlm.js
Last active February 11, 2026 20:07
NTLM Authentication with node-fetch
/* eslint-disable no-console */
const https = require('https');
const fetch = require('node-fetch');
const ntlm = require('httpntlm').ntlm;
const keepAlive = new https.Agent({ keepAlive: true });
const handleErrors = (response) => {
if (!response.ok) {