Skip to content

Instantly share code, notes, and snippets.

View hallettj's full-sized avatar

Jesse Hallett hallettj

View GitHub Profile
@hallettj
hallettj / blocker.go
Last active March 21, 2017 19:14
Experiment to see if saturating the goroutine worker pool with long-running tasks delays goroutines that are queued later
// This is a test to get a better understanding of Go's scheduling.
// The hypothesis is that if the goroutine worker pool is saturated with
// long-running tasks, then a goroutine that is queued later will not be
// scheduled until the long-running tasks complete.
//
// Tested in Go 1.7 using this command:
//
// go build -gcflags '-N -l' blocker.go && ./blocker
//
// The `gcflags` setting is my attempt to disable inlining, to give
@hallettj
hallettj / Makefile
Last active December 10, 2023 13:32
Makefile for transpiling with Babel & Flow in a Node app, or in a client- or server-side shared library
# Makefile for transpiling with Babel in a Node app, or in a client- or
# server-side shared library.
.PHONY: all clean
# Install `babel-cli` in a project to get the transpiler.
babel := node_modules/.bin/babel
# Identify modules to be transpiled by recursively searching the `src/`
# directory.
@hallettj
hallettj / adt.js
Last active March 4, 2024 07:05
Sealed algebraic data type (ADT) in Javascript with Flow
/* @flow */
// Helper function for matching against an ADT.
export function match<A,B>(matcher: A): (match: (matcher: A) => B) => B {
return match => match(matcher)
}
@hallettj
hallettj / 50-vpn-up
Created June 6, 2016 18:52
Place in /etc/NetworkManager/dispatcher.d/ to automatically connect to VPN on network changes
#!/bin/bash
WIRED_ONSITE="eth0"
WIFI_ONSITE="onsite_ssid"
VPN_ONSITE="vpn-onsite"
VPN_OFFSITE="vpn-offsite"
function online {
nmcli con show --active | grep -qs "^$1"
return $?
}
@hallettj
hallettj / adt.js
Last active March 21, 2019 12:56
Proposed implementation of GADTs with Javascript and Flow
/*
* `match` is a helper function for writing pattern matches on types that are
* implemented using Scott encoding.
*
* @flow
*/
export function match<A,B>(matcher: A): (match: (matcher: A) => B) => B {
return match => match(matcher)
}
import Data.List (groupBy, sort, sortOn, transpose)
type Vector = [Double]
type Matrix = [Vector] -- two-dimensional matrix
{- Distance functions -}
-- type for a distance function
type Distance = Vector -> Vector -> Double
@hallettj
hallettj / 01_notes.md
Last active September 22, 2015 00:48
Changes required to adapt a React app to run in Electron

This is a patch that adds Electron support to the Redux TodoMVC example app.

The original app is found at: https://github.com/rackt/redux/tree/master/examples/todomvc

After changes are applied, the app can be run in Electron with the commands:

npm install && node_modules/.bin/webpack && npm run electron

@hallettj
hallettj / gulpfile.js
Created April 23, 2015 01:37
Gulpfile configured for use with Babel, Wepback, and Flow
var execFile = require('child_process').execFile;
var flow = require('flow-bin');
var gulp = require('gulp');
var path = require('path')
var util = require('gulp-util');
var webpack = require('webpack');
var gulpWebpack = require('gulp-webpack');
var _ = require('lodash');
gulp.task('build', ['flow:check'], function() {
@hallettj
hallettj / quickstart.markdown
Last active August 29, 2015 14:17
JavaScript development quickstart

Quickstart

Get a development environment and project scaffold set up in a jiffy.

Development environment

First install node and npm. There are instructions here:

@hallettj
hallettj / tree-no_classes.js
Last active October 22, 2021 15:14
Algebraic data type in Javascript with Flow
/* @flow */
type Tree<T> =
| { type: "Node", value: T, left: Tree<T>, right: Tree<T> }
| { type: "EmptyTree" }
function find<T>(p: (v: T) => boolean, t: Tree<T>): T | void {
var l, v
if (t.type === "Node") {