Skip to content

Instantly share code, notes, and snippets.

@rhwlo
rhwlo / extra-bg.sh
Created August 25, 2016 18:26
background a process in another shell by pid, for @vruba
#!/bin/sh
ppid_tty=$(readlink /proc/$(cut -d' ' -f4 /proc/$1/stat)/fd/0)
kill -TSTP $1 && (/bin/echo "backgrounded $1" >> $ppid_tty) && kill -CONT $1
@rhwlo
rhwlo / Literate.hs
Last active August 7, 2016 21:10
the pandoc part is as yet unnecessary
{-# LANGUAGE FlexibleContexts #-}
{- I really like “literate” code as a writing style. Especially when I’m explaining or exploring
complicated ideas, writing comments in a longer form and explaining as I go along keeps me moored
to reality and attached to what I’m trying to do. Since I wanted a tool to convert into this
format, I decided to write one; since I like this format, I decided to write the tool using it.
I decided to use Haskell because it has [some history][0] with “literate code”, and because I
really like the Pandoc library for converting from Markdown to HTML. -}
@rhwlo
rhwlo / routes.elm
Created May 29, 2016 22:09
An Elm program to visualize BART routes
{- this is hosted currently at http://fearchar.net/2016/May/29/bart-elm-routes -}
import Debug exposing (log)
import Dict exposing (Dict)
import Json.Decode as Json exposing ((:=))
import Maybe
import Result
import String
import Html.App as Html
import Html exposing (Html)
import Svg exposing (..)
@rhwlo
rhwlo / sinebow.js
Created March 23, 2016 19:24
JS to create a sine-rainbow
// Translated from code from Sam Kimbrel and Charlie Loyd
// via http://basecase.org/env/on-rainbows
const PHI = (1 + Math.pow(5, 0.5)) / 2;
function sinebow(hue) {
// Choose a color from a sin^2-softened rainbow.
var red = Math.pow(Math.cos(Math.PI * hue), 2) * 255;
var green = Math.pow(Math.cos(Math.PI * (hue + 1/3)), 2) * 255;
var blue = Math.pow(Math.cos(Math.PI * (hue + 2/3)), 2) * 255;
@rhwlo
rhwlo / remind_me.py
Created February 22, 2016 20:28
friendly reminders on Linux
#!/usr/bin/env python3
#
# alias remind-me="$HOME/bin/remind_me.py"
from sys import argv, exit, stderr
import subprocess
import time
USAGE_STRING = """
usage: remind-me @time "your message goes here"
@rhwlo
rhwlo / TestPass.hs
Last active December 27, 2015 23:18
Haskell utility for training yourself on a new password.
import Control.Exception (bracket_)
import Control.Monad.Except (catchError, throwError)
import Data.ByteString.Lazy.Char8 (pack)
import Data.Digest.Pure.SHA (sha256)
import System.IO (hGetEcho, hSetEcho, hFlush, hGetLine, hPutStrLn, stdin, stdout, withFile, IOMode(ReadMode,WriteMode))
import System.IO.Error (isDoesNotExistError)
withEcho :: Bool -> IO a -> IO a
withEcho echo action = do
old <- hGetEcho stdin
@rhwlo
rhwlo / fish.config
Created November 16, 2015 02:32
configurations for fish!
set -u tmux_session (whoami)
set -u EDITOR /usr/bin/vim
set -u GIT_EDITOR /usr/bin/vim
fish_vi_mode
source $HOME/.config/fish/functions/pasteboard.fish
if test $TERM != "screen"
if tmux list-windows -t $tmux_session
// a Modifier implements a modifier function
sealed abstract class Modifier {
def modify(measure: Measure): Measure
}
case class Prefix(prefix: String, modify(measure: Measure): Measure) extends Modifier
class Exponent(power: Int) extends Modifier {
def modify(measure: Measure): Measure = {
Range(1, power).foldLeft(measure)(case (m, _) => m.multiply(measure))
}
}
@rhwlo
rhwlo / AddingPageMarkers.hs
Last active October 6, 2015 19:57
Adding section/page markers to a list
{- I’m trying to add section/page markers to a list of Monoids. In the first
case here, the Monoids are actually strings, but in the second, they aren't. -}
{- Case #1 -}
import Data.Char (chr)
sectionLength :: Int
sectionLength = 3
myVocab :: [String]
@rhwlo
rhwlo / amo, amas, amat
Created September 16, 2015 01:01
the output of AmoAmasAmat.hs
meilichios % ghc AmoAmasAmat.hs && ./AmoAmasAmat
Present
amo amas amat
amamus amatis amant
Imperfect
amabam amabas amabat
amabamus amabatis amabant
Future