Skip to content

Instantly share code, notes, and snippets.

View Boldewyn's full-sized avatar

Manuel Strehl Boldewyn

View GitHub Profile

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 / 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!
@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 / 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

Awesome PHP Libraries

A list of amazingly awesome PHP libraries that you should consider using (and some other shiny extras).

@Boldewyn
Boldewyn / cssgrep.sh
Last active March 20, 2023 13:49
cssgrep prints the part of HTML files, that match a given CSS selector. Solution based on this answer on StackOverflow: http://stackoverflow.com/a/14187086/113195
#!/bin/bash
function _usage() {
cat <<USAGE
usage: $(basename $0) PATTERN [FILES]
Print the HTML that matches the CSS selector PATTERN.
USAGE
}
@Boldewyn
Boldewyn / apply_mask.sh
Created December 18, 2012 08:58
Apply an alpha mask from mask.img on an image source.img and store in result.img.
#!/bin/sh
SOURCE=$1
MASK=$2
TARGET=$3
convert "$SOURCE" "$MASK" -compose CopyOpacity -composite "$TARGET"
@Boldewyn
Boldewyn / mdshow
Created December 16, 2012 19:38
Show a Markdown file rendered in the browser. The `markdown` program as well as `base64` must be installed. Assumes, that `x-www-browser` is correctly configured.
#!/bin/bash
MDFILE=$1
x-www-browser $(markdown "$MDFILE" | base64 -w0 | \
cat <(echo -n "data:text/html;charset=UTF-8;base64,") -)