Skip to content

Instantly share code, notes, and snippets.

View mbarkhau's full-sized avatar
💭

mbarkhau

💭
  • Cyberspace
View GitHub Profile
@mbarkhau
mbarkhau / minify.py
Last active August 29, 2015 14:25
script to minify javascript using google closure compiler
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
import json
from zlib import compress
from httplib import HTTPSConnection
from urllib import urlencode
COMPILER_JAR_PATH = os.path.expanduser("~/closure-compiler/compiler.jar")
@mbarkhau
mbarkhau / todo.py
Created July 14, 2015 12:18
todo completion plugin for sublime
import datetime as dt
import sublime_plugin
DEV_NAME = "mb"
class TODOCommand(sublime_plugin.EventListener):
def _todo_str(self):
@mbarkhau
mbarkhau / unchain.py
Created June 23, 2015 16:41
unchain.py
import sys
import itertools as it
PY2 = sys.version_info.major == 2
if PY2:
range = xrange
def unchain(elems, chain_size):
@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
@mbarkhau
mbarkhau / .gitconfig
Last active June 8, 2016 22:34
.gitconfig
[user]
name = Manuel Barkhau
email = [email protected]
[push]
default = simple
[alias]
co = checkout
amend = commit --amend
sts = status --short
stt = status --untracked-files=no
@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 / install_rusti.sh
Last active August 29, 2015 14:22
Installation script for rusti with racer (autocompletion) support
cd rust-nightly-x86_64-unknown-linux-gnu
cd $HOME/rust-nightly-x86_64-unknown-linux-gnu
bash install.sh
cd $HOME
chown -R $USER:$USER rust-nightly-x86_64-unknown-linux-gnu
git clone https://github.com/murarth/rusti.git
chown -R $USER:$USER rusti
cd $HOME/rusti
cargo build
@mbarkhau
mbarkhau / getarg.py
Last active April 1, 2022 14:24
mimimal arg parsing
import sys
def getarg(argname, args=sys.argv[1:]):
long_arg = '--' + argname
short_arg = '-' + argname[:1]
for idx, arg in enumerate(args):
if arg.startswith(long_arg):
if arg == long_arg:
# check for parameter
@mbarkhau
mbarkhau / pp_timeit.py
Last active August 29, 2015 14:15
Pretty print replacement for timeit
# coding: utf-8
"""
Pretty print replacement for timeit
pp_timeit.auto_timeit runs a statement and automatically
determines the number of repetitions required to gain
satisfactory accuracy (similar to timeit.main).
pp_timeit uses auto_timeit and prints the result so that the
different magnitudes of results are visible by their alignment.
@mbarkhau
mbarkhau / multisort.py
Created September 5, 2014 12:32
Sort items in a list by multiple fields
from operator import itemgetter
def multisort(vals, sort_spec, in_place=False):
comparers = []
for i, spec in enumerate(sort_spec):
if isinstance(spec, tuple):
key, polarity = spec
elif isinstance(spec, (str, unicode)):
key = spec.replace("-", "", 1)
polarity = 1