Skip to content

Instantly share code, notes, and snippets.

@gatlin
gatlin / cont.hs
Last active May 22, 2020
Delimited continuation monad transformer
View cont.hs
{- cabal:
build-depends: base
-}
module ContT
( ContT
, reset
, shift
, liftIO
)
@gatlin
gatlin / twitch
Created Apr 26, 2020
Stream arbitrary video files to twitch via gstreamer
View twitch
#!/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"
View rec.py
class cont:
def __init__(self, fn):
self.fn = fn
def __call__(self, *args, **kwargs):
return (lambda: self.fn(*args, self, **kwargs))
class tailrec:
View write_to_fd.c
/* 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 Jul 19, 2019
Use VLC without a UI to cast videos to chromecast
View cast.sh
#!/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"
@gatlin
gatlin / gist:d89ee5442c10ca59ac9a8b621392ed10
Last active May 10, 2020
Oleg's CK machine macro system - ever so slightly easier to find cross device here
View gist:d89ee5442c10ca59ac9a8b621392ed10
#lang r5rs
; Composable syntax-rules macros via the CK abstract machine
;
; We demonstrate (mutually-) recursive, higher-order applicative
; macros with clausal definitions, defined in the style that looks very
; much like that of ML or (strict) Haskell.
; We write composable, call-by-value--like macros without
; resorting to the continuation-passing-style and thus requiring no
; macro-level lambda. The syntax remains direct-style, with
; nested applications.
@gatlin
gatlin / psilo-typeclass.sl
Last active Jun 19, 2020
Hask-- I mean, psilo with zero real typeclasses and one virtual typeclass
View psilo-typeclass.sl
;; Hask-- I mean, psilo with no real typeclasses and one virtual typeclass.
; Inspired by [1], this is an exploration of representing all typeclasses
; through one distinguished class.
;
; This version of psilo does not have "real" typeclasses. However faking them
; with explicit dictionary passing does seem to correctly infer and check the
; constraints.
;
; The goal then is to figure out how best to represent "real" typeclasses as a
; distinguished feature in the language implementation given that we are
View io.hs
{-# LANGUAGE RankNTypes #-}
import Prelude hiding (IO, getLine)
import qualified Prelude as P
import System.IO.Unsafe
-- * The Foreign Function Interface
-- | FFI values permit interfacing with foreign functions, such as low-level IO
-- operations, memory management operations, or bindings to other user-level
@gatlin
gatlin / install-arch-linux-rpi-zero-w.sh
Created May 27, 2018 — forked from larsch/install-arch-linux-rpi-zero-w.sh
Install Arch Linux ARM for Raspberry Pi Zero W on SD Card (with commands to configure WiFi before first boot).
View install-arch-linux-rpi-zero-w.sh
#!/bin/sh -exu
dev=$1
cd $(mktemp -d)
function umountboot {
umount boot || true
umount root || true
}
# RPi1/Zero (armv6h):
View free-compiler.hs
{-|
- Example of using free constructions to build a flexible little compiler.
-
- The goal here is not necessarily efficiency but readability and flexibility.
-
- The language grammar is represented by an ADT; however, instead of
- recursively referring to itself it instead references a type variable.
-
- We derive instances of 'Functor' and 'Traversable' for this type.
-
You can’t perform that action at this time.