Skip to content

Instantly share code, notes, and snippets.

View Boldewyn's full-sized avatar

Manuel Strehl Boldewyn

View GitHub Profile
@Boldewyn
Boldewyn / mk
Last active December 17, 2015 07:48
Search Makefiles recursively and run make(1) there, if one is found
#!/bin/bash
#
# Search Makefiles recursively and run make(1) there, if one is found
#
DEPTH=$(pwd | tr -c -d / | wc -c)
MOD=.
while [[ $DEPTH > 0 ]]
do
@Boldewyn
Boldewyn / evaluate_404s
Created August 28, 2013 09:27
Use bash-foo to print all Apache log 404s in the order how often they appeared
#!/bin/bash
LOGFOLDER=/var/log/apache2
FIELD=7
HTTP_CODE=404
LOG_BASENAME=access.log
cd "$LOGFOLDER"
# print all zipped logfiles (suppressing errors)
@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!
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 / 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

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&\
@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.
javascript:
'search_unicode.bookmarklet.js',
(function(){
var x='http://codepoints.net/U+'+(function(r){
var n=r.startContainer,
p=r.startOffset,
u=(n.nodeType==3)?n.nodeValue.substr(p,2):n.childNodes[p].textContent.substr(0,2),
v=u.charCodeAt(0);
return 0xD800<=v&&v<=0xDB7F?((v&0x3FF)<<10|u.charCodeAt(1)&0x3FF)+0x10000:v;
})(getSelection().getRangeAt(0)).toString(16);
@Boldewyn
Boldewyn / urlencode
Created April 15, 2014 10:39
a small URL encoding script
#!/usr/bin/python
"""Simple URL encoder"""
import argparse
import urllib
parser = argparse.ArgumentParser(description='URL-encode a string')

Keybase proof

I hereby claim:

  • I am Boldewyn on github.
  • I am boldewyn (https://keybase.io/boldewyn) on keybase.
  • I have a public key whose fingerprint is D0A7 AC8C B2F0 3D52 D4DA A2FD E490 CD2B 2D29 0A4B

To claim this, I am signing this object: