Skip to content

Instantly share code, notes, and snippets.

View phorward's full-sized avatar
🦎
Tokay!

Jan Max Meyer phorward

🦎
Tokay!
View GitHub Profile
@phorward
phorward / byterun.py
Created September 28, 2018 16:31
byterun.py
# -*- coding: utf-8 -*-
#
# Implementation of the byterun virtual machine demo by Allison Kaptur, as described in the article
# "A Python Interpreter Written in Python", http://aosabook.org/en/500L/a-python-interpreter-written-in-python.html
#
import dis, collections, operator, inspect, types, sys
Block = collections.namedtuple("Block", "type, handler, stack_height")
# Can also be put into .bashrc
if [ "$SSHD_STARTER" != "1" ] && [ "$SSH_CONNECTION" == "" ]
then
read -p "Start sshd? [Y/n]" answ
case $answ in
"n"|"N")
;;
*)
ip=`ip addr | egrep "wlan0$" | awk 'BEGIN { FS = "[ \t]+" } { print substr($3, 1, index($3, "/") - 1) }'`
@phorward
phorward / split-youtube-album.sh
Created February 27, 2018 11:09
Tool for splitting Youtube Albums into files
#/bin/bash
BIGFILE="/tmp/Magician - Big Song.ogg"
ARTIST="The Magician"
EXT=".ogg"
IFS="
"
tracks="0:00:00 0:08:37 Eurydice and Orpheus
@phorward
phorward / jetbrains-mps.desktop
Created February 22, 2018 10:48
/usr/share/applications
[Desktop Entry]
Name=JetBrains MPS
Icon=/opt/jetbrains-mps/bin/MPS_128.png
GenericName=Meta Programming System
Comment=Meta Programming System
Exec=/bin/mps
Terminal=false
Type=Application
Categories=Development;IDE;
StartupNotify=true
@phorward
phorward / recursive-descent-parser-with-backtracking.c
Created February 6, 2018 23:06
Parsing Techniques: Examples
/*
Fig. 6.13. A fully backtracking recursive-descent parser
from the Book Parsing Techniques, 2nd Edition.
*/
#include <stdio.h>
#define MAXSIZE 100
/* some large value */
import re
def eval(s):
def gen(r, prefix = "", inc = 0):
if not r[0][1]:
return prefix + r[0][0] + "\n"
p = r[0][1].split(",")
ret = ""
@phorward
phorward / repl.sh
Last active January 13, 2018 11:31
Replacing in source repos
#!/bin/sh
SEDSCR='
s/\bpgnonterminal\b/pgnonterm/g
s/\bpg_nonterminal_/pg_nonterm_/g
s/\bpgterminal\b/pgterm/g
s/\bpg_terminal_/pg_term_/g
s/\bpgproduction\b/pgprod/g
s/\bpg_production_/pg_prod_/g
s/\bpg_symbol_is_nonterminal\b/pg_symbol_is_nonterm/g
@phorward
phorward / split-into-dirs.py
Last active April 8, 2019 07:51
Split mobile device files into monthly parted directories
#!/usr/bin/python
import os, re, datetime
storepath = os.path.join(os.environ["HOME"], "storage", "shared")
pat = re.compile(r"\d{8}")
for root, dirs, files in os.walk("."):
for filename in files:
match = pat.findall(filename)