Skip to content

Instantly share code, notes, and snippets.

Gatlin Johnson gatlin

Block or report user

Report or block gatlin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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:
@gatlin
gatlin / audio
Last active Oct 6, 2019
Shell script to make jackd and pulseaudio (and optionally fluidsynth) coexist with minimal interruption to my youtubing. Also it Works For Me™ on my laptop, will keep working on it
View audio
#!/bin/bash
###
# Script to launch jackd and reroute PulseAudio through it. And optionally
# start fluidsynth.
#
# READ THE NOTES PLEASE
###
# Usage (assuming this script is named `audio`, is in your PATH, and is
@gatlin
gatlin / uninstall-haskell-osx.sh
Created Oct 10, 2012
Uninstall Haskell from Mac OS X
View uninstall-haskell-osx.sh
#!/bin/bash
# source: http://www.haskell.org/pipermail/haskell-cafe/2011-March/090170.html
sudo rm -rf /Library/Frameworks/GHC.framework
sudo rm -rf /Library/Frameworks/HaskellPlatform.framework
sudo rm -rf /Library/Haskell
rm -rf .cabal
rm -rf .ghc
rm -rf ~/Library/Haskell
@gatlin
gatlin / imperative.lhs
Last active Sep 16, 2019
Imperative Programming in Haskell
View imperative.lhs
How to add imperative programming to a pure functional language
===
Many people bemoan languages such as Haskell for not supporting imperative
programming; they decry the need for math in their computer science.
![Math? In my computer? Yeah right.](http://i.imgur.com/YDIaEPB.jpg)
I'm here to tell you that not only does Haskell make imperative programming a
cinch, but safe and correct as well. Follow along! This post is written in
View powerlist.hs
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
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
Created May 1, 2019
Oleg's CK machine macro system - ever so slightly easier to find cross device here
View gist:d89ee5442c10ca59ac9a8b621392ed10
; 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.
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.
-
@gatlin
gatlin / monads.lhs
Created Nov 25, 2012
My explanation of monads
View monads.lhs
It's said that all Haskell programmers eventually write a blog post explaining
Monads. Today I fulfill my destiny. The basic format is ripped from "Learn You A
Haskell For Great Good," but these are my own crappy examples.
This blog post is literate Haskell; you can get it
[here](https://gist.github.com/4145341). You can import it into ghci and type
the functions to see their output (`ghci monads.lhs`). For this to work, we'll
need to import one module for use later:
> import Control.Applicative
You can’t perform that action at this time.