Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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 / 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 / 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 / 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 / show-maps.c
Last active July 16, 2017 12:04
Linux: show the memory map of current process
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int fd, fail;
@iamahuman
iamahuman / trayopen.c
Created May 22, 2017 08:35
Linux: check CD-ROM tray status
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <libgen.h>
#include <linux/cdrom.h>
@iamahuman
iamahuman / spin.sh
Created May 19, 2017 15:54
(2015) A spinner which you can put on your terminal and waste some time staring at it doing nothing
#!/bin/bash
spin=("|" "/" "-" "\\");((i=j=0,n=$(tput cols)-10))
echo -ne "\r"; tput sc
trap "echo;exit 0" SIGTERM SIGINT SIGHUP
while true;do tput rc;s="\r${spin[$i]} ";k=0;while [[ $k -lt $((j < 0 ? -j - 1 : j)) ]]; do
if [[ $j -ge 0 ]]
then s=$s"=";else s=$s" ";fi;((++k));done;((i++))
if [[ $j -lt 0 ]];then ((--j));else ((++j)); fi; if [ $i -ge ${#spin[@]} ]; then i=0;fi
if [ $j -ge $n ]; then j=-1;else if [ $((-j)) -gt $n ]; then j=0; fi; fi;
printf "$s";sleep 0.05;read -t 0.0001 -n 1 -s ans;if [ "$ans" == "q" ];then break;fi;done;echo;