Skip to content

Instantly share code, notes, and snippets.

View TimMensch's full-sized avatar

Tim Mensch TimMensch

View GitHub Profile
#!/usr/bin/env python
# -*- mode: python -*-
from __future__ import print_function, with_statement
import sys
import hashlib
import tempfile
import os
import subprocess
@TimMensch
TimMensch / validateSchema.js
Created December 4, 2017 16:26
Validation of JSON based on a TypeScript declaration
/*
Copyright 2017, Tim Mensch.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject
to the following conditions:
@TimMensch
TimMensch / example.graphql
Last active January 15, 2018 21:28
Example GitHub v4 API Query that fails
{
repository(name: "MidiPlayerJS", owner: "TimMensch") {
ref(qualifiedName:"tim") {
name
target {
... on Commit {
author {
name
}
blame(path:"package.json") {
@TimMensch
TimMensch / auth-complex.js
Created November 8, 2018 01:10
A slightly more complex counterexample to the "Functional River" that would be much uglier in promise form.
// Easier to follow. Equally easy to test -- and with one fewer function in need of testing.
import { userInfo } from "os";
const Promise = require("bluebird");
const { hashStringAsync } = Promise.promisifyAll(require("./lib/crypto"));
const { logEventAsync } = Promise.promisifyAll(require("./lib/log"));
const { openAsync } = Promise.promisifyAll(require("./lib/db"));
const { TimeoutError, ValidationError, NotFoundError } = require("./errors");
@TimMensch
TimMensch / auth.js
Last active November 8, 2018 23:11
An alternative to the "Functional River"
// Easier to follow. Equally easy to test -- and with one fewer function in need of testing.
const Promise = require("bluebird");
const { hashStringAsync } = Promise.promisifyAll(require("./lib/crypto"));
const { logEventAsync } = Promise.promisifyAll(require("./lib/log"));
const { openAsync } = Promise.promisifyAll(require("./lib/db"));
const { TimeoutError, ValidationError, NotFoundError } = require("./errors");
const _openHandle = openAsync(); // FYI: Promises include memoization (caching) built into same API
@TimMensch
TimMensch / keybase.md
Created November 29, 2018 17:39
keybase.md

Keybase proof

I hereby claim:

  • I am timmensch on github.
  • I am timmensch (https://keybase.io/timmensch) on keybase.
  • I have a public key ASCBoS_QiHMPU0cE8Mot3Bd-qPHogMfycz9Ujo-tmFLQigo

To claim this, I am signing this object: