Skip to content

Instantly share code, notes, and snippets.

@iamahuman
iamahuman / dial.html
Last active July 17, 2017 14:52
Some practice around using HTML5 Javascript APIs, especially AudioContext. Not meant to be clean, readable or well-written.
<!DOCTYPE html>
<html>
<head>
<title>Dial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
<!--
button.dial {
padding: 10px 0;
width: 3.5em;
@iamahuman
iamahuman / brainfuck
Created August 30, 2017 12:03
Brainfuck interpreter?
NUMBER SIGN
LATIN SMALL LETTER I
LATIN SMALL LETTER N
LATIN SMALL LETTER C
LATIN SMALL LETTER L
LATIN SMALL LETTER U
LATIN SMALL LETTER D
LATIN SMALL LETTER E
SPACE
LESS-THAN SIGN
@iamahuman
iamahuman / git-sync-upstream.sh
Last active April 4, 2021 13:08
[[Archived bad quality mess when I used to not know better - just use git fetch && git push upstream 'refs/remotes/A/*:refs/heads/*' instead of this crap!]] Synchronize origin's branches with upstream counterparts (NOTE: assumes development model of keeping track of local changes with separate branch names)
#!/bin/bash
set -e
old_pwd="$PWD"
do_msg() {
printf "\\r[%s:%s] - %s" "$reponame" "$branch" "$*" >&2
}
do_end_msg() {
printf "\\r[%s:%s] - %s" "$reponame" "$branch" "$*" >&2
@iamahuman
iamahuman / calc.sed
Last active June 19, 2022 17:21
infix expression evaluator in sed (integers in decimal base only)
#!/bin/sed -nf
x ; s/^$/\n/ ; x ; t scan_unop
:scan_unop
/^[ ]*[-+][ ]*)/{i\
unary op expected an operand, got ')'
x ; b hold_bailout
}
/^[ ]*[-+][ ]*$/{i\
unary op expected an operand, got EOF
x ; b hold_bailout
@iamahuman
iamahuman / nat.hs
Created February 17, 2018 17:50
(exercise) Peano numbers in Haskell
module MyNat (MyNat) where
import Data.Ratio
data MyNat = Z | S !MyNat deriving (Read, Show, Eq)
natapl :: MyNat -> (a -> a) -> a -> a
natapl Z f n = n
natapl (S x) f n = natapl x f (f n)
natsub :: MyNat -> MyNat -> (MyNat -> a) -> (MyNat -> a) -> a -> a
@iamahuman
iamahuman / cc-wrapper.pl
Last active February 22, 2018 07:14
clang wrapper for use with NDK
#!/usr/bin/perl
# NOTE symlinked from NDK, be cautious!
use strict;
use warnings;
use File::Basename;
use File::Spec;
use File::Copy;
our $DEBUG = '';
@iamahuman
iamahuman / kalzip
Last active October 15, 2018 12:11
Create and extract Zip archives with KS X 1001(euc-kr / MS949) encoded filenames
#!/usr/bin/env python
import zipfile
import os
import stat
import sys
import codecs
import time
import datetime
import unicodedata
import sys
module Main where
import Control.Applicative
import Control.Exception
import Data.List
import Data.Char
import qualified Data.Map as Map
import System.IO
import System.IO.Error
import System.Environment
@iamahuman
iamahuman / PureRef.hs
Last active April 4, 2021 13:02
A pure ST monad transformer with coercible references
{-# OPTIONS_HADDOCK show-extensions #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ExistentialQuantification #-}
-----------------------------------------------------------------------------
-- |
-- Module : Data.PureRef
-- Copyright : (c) Jinoh Kang, 2019
-- License : MIT
@iamahuman
iamahuman / ContLabel.hs
Created May 1, 2019 08:02
"setjmp / longjmp" in Haskell (continuations)
module ContLabel where
import Control.Monad.Trans.Cont
import Control.Monad.IO.Class
type Jmp r m a = (Maybe a, Label r m a)
newtype Label r m a = Label (Jmp r m a -> m r)
setjmp :: ContT r m (Jmp r m a)
setjmp = ContT $ \ c -> c (Nothing, Label c)