Skip to content

Instantly share code, notes, and snippets.

View hallettj's full-sized avatar

Jesse Hallett hallettj

View GitHub Profile
@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 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 / 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 / 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 / routes.elm
Last active May 30, 2017 19:52
Example of a graph in Elm
import Html exposing (text)
import List exposing (concatMap, filter)
import List.Extra exposing (uniqueBy)
type alias CityId = Int
type alias City =
{ id: CityId
, name: String
}
@hallettj
hallettj / promisify.js
Created September 25, 2017 18:32
Flow type for a function that modifies an input function while preserving argument arity and types
function promisify<T, Args: *> (
taskFn: (...args: Args) => Task<T>
): Task<(...args: Args) => Promise<T>> {
/* ... */
}
@hallettj
hallettj / FloatFullScreenFirefox.hs
Created October 21, 2017 18:19
Attempt to hack full screen support for Firefox in XMonad
{-# LANGUAGE NamedFieldPuns #-}
--------------------------------------------------------------------------------
-- |
-- Module : Custom.Hooks.FloatFullScreenFirefox
--
-- Maintainer : Jesse Hallett <[email protected]>
--
-- As of version 57 Firefox for Linux does not set full screen state in Xorg
-- when entering full screen mode. This module exports an event hook that
@hallettj
hallettj / userChrome.css
Last active November 5, 2024 01:08
Customize Firefox Quantum to hide tab bar, and to hide navigation bar when it is not focused. Press Ctrl+L to reveal navigation bar. To make this work open about:config and set toolkit.legacyUserProfileCustomizations.stylesheets to true. Put this file in ~/.mozilla/firefox/<profile-name>/chrome/
@-moz-document url(chrome://browser/content/browser.xul),
url(chrome://browser/content/browser.xhtml) {
/* hide horizontal tabs at the top of the window */
#TabsToolbar > * {
visibility: collapse;
}
/* hide navigation bar when it is not focused; use Ctrl+L to get focus */
#main-window:not([customizing]) #navigator-toolbox:not(:focus-within):not(:hover) {
@hallettj
hallettj / HKT.js
Last active June 27, 2019 15:19
Concept for emulating higher-kinded types in Flow via type-level functions
/*
* Concept for emulating higher-kinded types using Flow. Instead of passing
* a type that has not been applied to parameters, this pattern passes
* a type-level function that will map a parameter type to the desired
* higher-kinded type applied to the given parameter.
*
* @flow
*/
// a higher-kinded type is represented indirectly via a type-level function from
@hallettj
hallettj / datetime.tsx
Last active April 27, 2020 06:49
Custom timezone-aware datetime input component for Sanity CMS
import styles from "part:@sanity/base/theme/forms/text-input-style"
import FormField from "part:@sanity/components/formfields/default"
import { withDocument } from "part:@sanity/form-builder"
import PatchEvent, { set, unset } from "part:@sanity/form-builder/patch-event"
import * as React from "react"
import Datetime from "react-datetime"
class DatetimeInputRaw extends React.Component {
render() {