Skip to content

Instantly share code, notes, and snippets.

Avatar

Jesse Hallett hallettj

View GitHub Profile
@hallettj
hallettj / datetime.tsx
Last active Apr 27, 2020
Custom timezone-aware datetime input component for Sanity CMS
View datetime.tsx
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() {
@hallettj
hallettj / HKT.js
Last active Jun 27, 2019
Concept for emulating higher-kinded types in Flow via type-level functions
View HKT.js
/*
* 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 / userChrome.css
Last active Nov 12, 2021
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 you must open about:config and set toolkit.legacyUserProfileCustomizations.stylesheets to true with. This version is tested with Firefox v78.
View userChrome.css
@-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 / FloatFullScreenFirefox.hs
Created Oct 21, 2017
Attempt to hack full screen support for Firefox in XMonad
View FloatFullScreenFirefox.hs
{-# LANGUAGE NamedFieldPuns #-}
--------------------------------------------------------------------------------
-- |
-- Module : Custom.Hooks.FloatFullScreenFirefox
--
-- Maintainer : Jesse Hallett <jesse@sitr.us>
--
-- 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 / promisify.js
Created Sep 25, 2017
Flow type for a function that modifies an input function while preserving argument arity and types
View promisify.js
function promisify<T, Args: *> (
taskFn: (...args: Args) => Task<T>
): Task<(...args: Args) => Promise<T>> {
/* ... */
}
@hallettj
hallettj / routes.elm
Last active May 30, 2017
Example of a graph in Elm
View routes.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 / blocker.go
Last active Mar 21, 2017
Experiment to see if saturating the goroutine worker pool with long-running tasks delays goroutines that are queued later
View blocker.go
// 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 Oct 28, 2021
Makefile for transpiling with Babel & Flow in a Node app, or in a client- or server-side shared library
View Makefile
# 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 Jun 5, 2019
Sealed algebraic data type (ADT) in Javascript with Flow
View adt.js
/* @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 Jun 6, 2016
Place in /etc/NetworkManager/dispatcher.d/ to automatically connect to VPN on network changes
View 50-vpn-up
#!/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 $?
}