Skip to content

Instantly share code, notes, and snippets.

View hallettj's full-sized avatar

Jesse Hallett hallettj

View GitHub Profile
@hallettj
hallettj / global-variables-are-bad.js
Created February 14, 2009 21:15
How and why to avoid global variables in JavaScript
// It is important to declare your variables.
(function() {
var foo = 'Hello, world!';
print(foo); //=> Hello, world!
})();
// Because if you don't, the become global variables.
(function() {
@hallettj
hallettj / rust-on-nix.md
Created March 8, 2024 15:22
Building Rust binaries with Nix draft

#nix #rust

Packaging Rust Binaries

Requires flakes to be enabled. {.is-warning}

There are a few pieces that make up a complete Nix workflow for building Rust crates:

@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 / xmonad.hs
Created March 6, 2012 19:45
XMonad configuration for a left-handed Tall layout
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
-- FlexibleInstances and MultiParamTypeClasses are necessary for the
-- LayoutClass instance declaration of Flip.
-- I use two monitors. The default tiled layout in XMonad, Tall, puts
-- the master window on the left side of the screen. That feels right
-- for my right screen. But for my left screen I would prefer the
-- master window to be on the right side of the screen because that side
@hallettj
hallettj / userChrome.css
Last active June 23, 2023 18:05
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.
@-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 / fractional-scaling-mutter.md
Last active January 10, 2023 20:25
How I set up fractional scaling in Gnome

Fractional Scaling

With a bigger display 2x scaling might be too big. I'm trying out experimental support for fractional scaling in Gnome. To opt out again it is necessary to undo this experimental features setting:

$ gsettings set org.gnome.mutter experimental-features "['scale-monitor-framebuffer']"

In addition to fractional scaling that setting allows different scaling factors per monitor!

The only issue I'm seeing so far is that apps running with XWayland look fuzzy. That includes web browsers. But! Firefox and Chrome both have opt-in support for Wayland which fixes the problem.

@hallettj
hallettj / _redirects
Created November 20, 2022 23:24
Netlify configuration to redirect a Mastodon handle
# Netlify configuration to set up a Mastodon handle for your own domain that
# forwards to your real account. This configuration allows people to search for
# me with @jesse@sitr.us, and to find me @hallettj@hachyderm.io.
#
# Put a configuration like this in a file called _redirects in the *publish
# directory* of your Netlify project. For my Gatsby site I put the file in
# static/_redirects, and at build time it gets copied to public/_redirects.
#
# Redirect documentation for Netlify is at https://docs.netlify.com/routing/redirects/redirect-options/
# Test redirect rules in the playground, https://play.netlify.com/redirects
@hallettj
hallettj / state-example-game.js
Created November 9, 2012 04:41
Implementation of a State monad in JavaScript
/*
* Example of a state monad in use. This is adapted from an example on
* the Haskell Wiki:
* http://www.haskell.org/haskellwiki/State_Monad#Complete_and_Concrete_Example_1
*/
require(['state', 'qunit'], function(state, qunit) {
/*
* playGame() is a recursive function that given an array of moves
* defines an algorithm for constructing a final game score. Along
@hallettj
hallettj / sbt
Created October 10, 2011 02:51
Install and launch script for sbt, a Scala build tool
#!/bin/sh -e
if [ ! $SBT_VERSION ]; then SBT_VERSION=0.11.0; fi
if [ ! $SBT_DIR ]; then SBT_DIR=$HOME/.sbt; fi
if [ ! $SBT_FILENAME ]; then SBT_FILENAME=sbt-launch-$SBT_VERSION.jar; fi
if [ ! $SBT_LOCATION ]; then SBT_LOCATION=$SBT_DIR/$SBT_FILENAME; fi
if expr match $SBT_VERSION "0.7" > /dev/null;
then
SBT_URL="http://simple-build-tool.googlecode.com/files/$SBT_FILENAME"