Skip to content

Instantly share code, notes, and snippets.

I had a dream. Like there is ahead
An endless, empty and the wildest plane,
And I stand there, held by iron chain,
Under the tall rock made from finest stone,
And next to me are thousands just like me.
The face of each is marked by life and sorrow,
Love's favour burn in each and every eye,
And hands of everyone are chained with snakes of iron,
And every shoulder's bent low to the ground,
@Minoru
Minoru / gist:5185160
Created March 18, 2013 04:49
Bash (sorry!) script that implements idea from here: https://bnw.im/p/QBRE4F In short: it plays an audio file, pausing periodically to check if user is asleep already. If user doesn't respond (by making some noise), the script remembers current position in the file and quits. Next time script is run on the same file, playback is resumed from the…
#!/bin/bash
# I hereby place this script into public domain.
# database is CSV file containing position (in seconds) and filename, separated by a comma
db="$HOME/.mama.db"
# timeout is number of seconds to wait between checks if user is asleep
# default is 10 minutes
timeout="600"
@Minoru
Minoru / andOrList.c
Created September 11, 2011 17:27
Sample implementation of shell AND-OR list in C89
#include <stdlib.h>
#include <string.h>
#include "routines.h"
int main(int argc, const char *argv[]) {
int status,
status0,
status1;
char **argv0,
**argv1,
@Minoru
Minoru / task2.hs
Created November 3, 2010 20:32
Shell to C translator (using new intermediate represantation)
import IR
type C = String
genC x = helper "" "" 0 x
where helper :: C -> C -> Int -> Statement -> C
helper defs code n (Sequence (x:[])) = helper (defs ++ genDefs n True x) (code ++ genCode n True x) (n + countDefs x) (Sequence [])
helper defs code n (Sequence (x:xs)) = helper (defs ++ genDefs n False x) (code ++ genCode n False x) (n + countDefs x) (Sequence xs)
helper defs code n (Sequence _ ) = "#include \"routines.h\"\nint main(){" ++ defs ++ code ++ "}"
@Minoru
Minoru / routines.h
Created October 29, 2010 22:57
VERY simple Haskell shell to C translator
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
int exec_command(const char**);
@Minoru
Minoru / task1.c
Created October 27, 2010 23:19
C implementation of simple shell script
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> // sleep()
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
int make_redirection(int stream, const char* file) {