Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
"""Print a random number of lines in response to each input line.
Terminate each response with 'END'.
"""
import sys
import random
def log(msg):
@zed
zed / __main__.py
Last active June 3, 2017 10:59
Play Youtube video on remote VLC.
#!/usr/bin/env python
"""Play Youtube video on remote VLC.
Usage: play-youtube-video-on-remote-vlc <webpage-url>
Send media url to remote (desktop) VLC using (Lua) http interface
https://wiki.videolan.org/VLC_HTTP_requests/
"""
import base64
import os
/** Convert Roman numerals given on the command line to decimals.
$ ragel -F0 -o roman_numerals.c roman_numerals.rl
$ gcc -finput-charset=utf-8 -fexec-charset=utf-8 -o roman_numerals roman_numerals.c
$ ./roman_numerals IX Ⅻ CCCC
9
12
400
$ ./roman_numerals IIX && exit 1 || echo invalid
invalid
/scheme.png
@zed
zed / KV.ebnf
Last active March 6, 2017 10:01
# $ grako -o kv_parser.py KV.ebnf
@@grammar :: KV
# whitespace inside a string excluding the start/end of the line
@@whitespace :: /((?!^)(?![\r\n])\s)+/
@@eol_comments :: /#[^\r\n]*/
@@left_recursion :: False
# input is zero or more assignments
#!/usr/bin/env python3
r"""Parse space-separated key=value pairs.
Format from http://ru.stackoverflow.com/a/635295/23044
>>> from pprint import pprint
>>> pprint(parse(r'a=1 b="2" c=3.123 d=[1, 2, 3] e={"Ke\n":["h=4"],"Key2":{" ":1}}'))
{'a': 1,
'b': '2',
'c': 3.123,
@zed
zed / collatz-conjecture.py
Created December 20, 2016 20:37
Collatz conjecture
#!/usr/bin/env python3
"""Collatz conjecture."""
def collatz(n):
assert n > 0
while n != 1:
yield n
if n & 1: # odd
n = 3*n + 1
else:
@zed
zed / .gitignore
Last active March 28, 2017 09:30
shorten url using goo.gl
.cache*
@zed
zed / .gitignore
Last active January 31, 2018 18:23
/.cachedir/
/sites.json
@zed
zed / beep-evdev.py
Last active November 5, 2016 18:13
Beep PC Speaker using Linux evdev API.
#!/usr/bin/env python
"""Beep PC Speaker using Linux evdev API.
To make /dev/input/by-path/platform-pcspkr-event-spkr device available, run:
root# modprobe pcspkr
"""
import ctypes
import math
import os