Skip to content

Instantly share code, notes, and snippets.

View Boldewyn's full-sized avatar

Manuel Strehl Boldewyn

View GitHub Profile
@Boldewyn
Boldewyn / git-get
Last active December 22, 2016 10:37
The `git get` command to replace `git pull` with a sophisticated rebase strategy
#!/bin/bash
#
# git get
#
# Place this script in your path, so that git(1) can find it. Presto!
# You can now type `git get` instead of `git pull` and enjoy the
# advantages of rebasing atop instead of merging remote changes.
#
# If you have local changes, use `git get --stash` to stash and
# pop afterwards your changes automatically.
@Boldewyn
Boldewyn / slice.py
Last active December 16, 2016 20:17
>>> class X:
... def __getitem__(self, item):
... print isinstance(item, slice)
... print item
...
>>> y=X()
>>> y[1:3,5]
False
(slice(1, 3, None), 5)
>>> y[{'foo':'bar'}]
@Boldewyn
Boldewyn / git-cmpsize
Created March 15, 2016 12:55
Git command to compare size of file in working tree against index/commit
#!/bin/bash
if [[ $1 == "--help" || $1 == "-h" ]]; then
cat <<USAGE
usage: $(basename $0) FILE [REVISION]
Compare file size between version at REVISION (default: index) and
on disk.
USAGE
exit
@Boldewyn
Boldewyn / install-font
Created March 15, 2016 12:53
Small script to install a font under Linux by means of symlinking to it
#!/bin/bash
ERROR=0
mkdir -p "$HOME/.fonts"
for name in "$@"; do
if [[ ! -f $name ]]; then
echo "Can't find $name" >&2
ERROR=1
@Boldewyn
Boldewyn / http-states
Created February 18, 2016 15:37
Read HTTP status codes from the RFC in your shell
#!/bin/bash
_usage() {
cat <<USAGE
usage: $(basename $0) STATUS_CODE
Print the RFC information about an HTTP status code.
USAGE
}
@Boldewyn
Boldewyn / md
Last active January 13, 2016 10:53
Enhanced Markdown viewer
#!/usr/bin/env python3
"""Render Markdown and show the result in the browser
"""
import argparse
from http.server import HTTPServer, BaseHTTPRequestHandler
from markdown import markdown
import os
import sys

Track deployments with Piwik's Annotation API

If you use analytics tools to monitor your website, a good metric for determining the effect of changes is the time of a deployment. Does the conversion rate really improve with the latest adjustments? Has the number of 404 errors decreased since we fixed that script?

Like other analytics products, Piwik allows you to annotate your data. Wouldn't it be great if all deployments were noted automatically? With the Annotation API it's actually quite simple.

In your deployment process, just add the following line to your script or post-receive hook and fill in the placeholders:

curl "http://YOUR_PIWIK_DOMAIN/?module=API&amp;\
@Boldewyn
Boldewyn / README.md
Last active January 1, 2016 11:29
ZeroClipboard: Minimal testcase for mal-functioning copying

The set-up: place both files in a directory, add ZeroClipboard 1.2.3 and Require.JS so that they're found.

Open testcase.html and watch console output: Sometimes the text is copied, sometimes not:

22:16:08.959 "Copied text to clipboard: " testcase.js:5
22:16:10.141 "Copied text to clipboard: a" testcase.js:5
22:16:11.544 "Copied text to clipboard: a" testcase.js:5
22:16:12.057 "Copied text to clipboard: " testcase.js:5
22:16:12.816 "Copied text to clipboard: a" testcase.js:5
if (!document.querySelectorAll) {
document.querySelectorAll = function(selector) {
var doc = document,
head = doc.documentElement.firstChild,
styleTag = doc.createElement('STYLE');
head.appendChild(styleTag);
doc.__qsaels = [];
styleTag.styleSheet.cssText = selector + "{x:expression(document.__qsaels.push(this))}";
window.scrollBy(0, 0);
@Boldewyn
Boldewyn / format_number.js
Created October 10, 2013 14:10
JS: format number the hard way
/**
* format a number to look like "12.300 Mio." (german format)
*
* Spec:
* * numbers equal or larger than 100000 are suffixed with "Mio.".
* * three significant digits
* * dots after each 3 consecutive digits
*
* Why not use .toPrecision() alone? Because it might end up in
* "scientific notation" (1.23e9). Yeah, that makes sence, JS!