Skip to content

Instantly share code, notes, and snippets.

View mbarkhau's full-sized avatar
💭

mbarkhau

💭
  • Cyberspace
View GitHub Profile
def eval_sexpr(sexpr):
fn = sexpr[0]
args = sexpr[1:]
args = tuple(eval_sexpr(e) if isinstance(e, tuple) else e for e in args)
return fn(*args)
import operator as op
eval_sexpr((op.add, (op.mul, 3, 4), (op.mul, 2, 5)))
@mbarkhau
mbarkhau / KSON.js
Last active December 26, 2015 13:31
KSON: Keyless Schemafied Object Notation
/* KSON: Keyless Schemafied Object Notation
*
* Version: 0.1 Alpha
*
* A serialization format with two goals in mind:
* 1. Easily parsable using minimal javascript.
* 2. Reduce serialized size compared to JSON.
*
* 1. is accomplished by using the (comparativly fast) JSON parse/stringify
* functions, thus reducing the task of KSON to packing/unpacking the values
@mbarkhau
mbarkhau / parse_json_cfg.py
Last active March 29, 2016 16:34
Parses JSON allowing for trailing commas and comments using //
import re
import json
ONELINE_COMMENT_RE = re.compile(r"""
^ # comment must be at the start of the line
\s* # arbitrary whitespace
// # start of the comment
(.*) # the comment
$ # until the end of line
""", re.MULTILINE | re.VERBOSE)
@mbarkhau
mbarkhau / pysix.py
Last active April 16, 2016 20:50
pysix.py
# -*- coding: utf-8 -*-
# "Writing Python 3 code that's compatible with Python 2 is
# much more rewarding than the opposite. Not only does that
# make your code more future-proof, but Python 3’s advantages
# (like the saner string handling) start shining quickly.
# Dealing with Python 2 becomes a backwards compatibility
# requirement" – "Porting to Python 3" from the Django Project
# This file provides boilerplate for scripts to run in both
# python2.7 and python3.4. As much as possible it attempts
class Memoizer(object):
"""Memoizer for pure functions with positional hashable arguments.
Eviction from cache is done more or less at random, which
in practice is surprisingly close to a LRU strategy.
"""
def __init__(self, func, maxsize=10000):
self.func = func
self.maxsize = maxsize
@mbarkhau
mbarkhau / .gitconfig
Last active June 8, 2016 22:34
.gitconfig
[user]
name = Manuel Barkhau
email = mb@nexttuesday.de
[push]
default = simple
[alias]
co = checkout
amend = commit --amend
sts = status --short
stt = status --untracked-files=no
@mbarkhau
mbarkhau / .config_terminator_config
Last active June 9, 2016 07:45
utility configuration
[global_config]
inactive_color_offset = 0.92
[keybindings]
close_window = None
group_tab = <Primary><Alt>t
broadcast_group = <Super>g
broadcast_all = <Super>b
broadcast_off = <Shift><Super>b
new_tab = <Primary><Shift>t
ungroup_tab = <Primary><Shift><Alt>t
@mbarkhau
mbarkhau / unicode_test.txt
Last active June 23, 2016 14:27
i18n test string
イërnâ七iônàنلzætiøn
@mbarkhau
mbarkhau / pretty_json.py
Last active February 8, 2017 11:17
pretty_json.py
# -*- coding: utf-8 -*-
"""Prettify JSON
Usage:
pjson --help
pjson --test
cat my.json | pjson
"""
@mbarkhau
mbarkhau / placepaintbot.js
Last active April 2, 2017 02:47
placepaintbot.js
// ==UserScript==
// @name PlacePaintBot
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Domination of Place!
// @author mbarkhau
// @match https://www.reddit.com/place?webview=true
// @grant none
// ==/UserScript==