Skip to content

Instantly share code, notes, and snippets.

@gatlin
gatlin / ucv.sh
Last active January 12, 2023 16:09
unicode character viewer. download the unicode data txt file here: https://github.com/latex3/unicode-data/blob/main/UnicodeData.txt
#!/usr/bin/env bash
############################
# Unicode Character Viewer #
# v1.0 #
# ~*~*~*~*~*~*~*~*~*~*~*~* #
# Author: Gatlin Johnson #
# <gatlin@niltag.net> #
# ~*~*~*~*~*~*~*~*~*~*~*~* #
# Runtime dependencies: #
# - fzf #

Keybase proof

I hereby claim:

  • I am gatlin on github.
  • I am marcus4realius (https://keybase.io/marcus4realius) on keybase.
  • I have a public key whose fingerprint is 5B99 A8B5 30FB 7B4E 8676 A642 06EA 942B A243 5748

To claim this, I am signing this object:

@gatlin
gatlin / a.vm.ts
Created July 27, 2021 02:28
Interpreter for call-by-push-value language with side effects built with robot state machine and my precursor library.
import { readFile } from "fs/promises";
import { createInterface } from "readline";
import type { Interface } from "readline";
import { CESKM, parse_cbpv, scalar, continuation, topk } from "precursor-ts";
import type { State, Value, Store } from "precursor-ts";
import {
createMachine,
state,
transition,
reduce,
@gatlin
gatlin / ctx.ts
Last active May 10, 2021 22:42
something relating reactive UIs and spreadsheets
/**
* outputs:
* a { a: 3, b: 6, c: 12 }
* b { a: 5, b: 10, c: 18 }
* c { a: 8, b: 16, c: 27 }
* { a: '25', b: '196', c: '900' }
* c 900
*/
// todo: use type system to statically verify the key exists in the object.
@gatlin
gatlin / arith.ts
Last active December 16, 2020 00:47
Demonstrates a useful pattern of defining and (semi-)automatically deriving evaluators for domain-specific languages in TypeScript
import { _, Functor, Fix, _in, cata, Algebra } from './base';
import { strict as assert } from 'assert';
// The type parameter goes where the grammar would otherwise reference itself.
type ArithF<A>
= { tag: 'add' ; lhs: A ; rhs: A }
| { tag: 'mul' ; lhs: A ; rhs: A }
| { tag: 'num' ; n: number }
| { tag: 'paren' ; e: A } ;
@gatlin
gatlin / cont.hs
Last active May 22, 2020 17:42
Delimited continuation monad transformer
{- cabal:
build-depends: base
-}
module ContT
( ContT
, reset
, shift
, liftIO
)
@gatlin
gatlin / twitch
Created April 26, 2020 22:53
Stream arbitrary video files to twitch via gstreamer
#!/usr/bin/env bash
###
# Usage
###
# twitch <path-to-file>
PATH_TO_TWITCH_KEY="$HOME/.config/twitch.key"
if [ ! -f "$HOME/.config/twitch.key" ]; then
echo "Please write your twitch key to $PATH_TO_TWITCH_KEY"
class cont:
def __init__(self, fn):
self.fn = fn
def __call__(self, *args, **kwargs):
return (lambda: self.fn(*args, self, **kwargs))
class tailrec:
/* Helper function which writes a string to a file descriptor.
*/
static gboolean
write_to_fd (int fd, const gchar *message) {
gsize bw;
GIOChannel *channel = g_io_channel_unix_new (fd);
GString *message_str = g_string_new (message);
g_string_append (message_str, "\n");
g_io_channel_write_chars (channel,
message_str->str,
@gatlin
gatlin / cast.sh
Created July 19, 2019 17:22
Use VLC without a UI to cast videos to chromecast
#!/bin/bash
MEDIA_FILE="$1"
if [ -z "$1" ]; then
echo "Please specify a media file as the first argument."
exit 1
fi
CHROMECAST_IP4_ADDRESS="$2"