Skip to content

Instantly share code, notes, and snippets.

Anders K. Madsen lillesvin

Block or report user

Report or block lillesvin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
lillesvin / git-lint-php
Created Aug 28, 2015
Creates a git command 'lint-php' (if this script exists in your PATH and is executable) that syntax checks all modified/added files that end in ".php".
View git-lint-php
files=$(git status --porcelain | sed -e 's/^.* //' | grep -P '\.php$')
for f in $files; do
php -l $f
lillesvin /
Last active Aug 29, 2015
Fixed broken Dropbox icons in i3 (and probably other WMs with a few adjustments).
BGCOLOR=`ruby -e "puts['HOME'] + '/.i3/config').gsub(/^.*bar\s\{.*colors\s\{.*background\s(#[0-9a-f]{6}).*$/m, '\1')"`
cd $WD
mkdir backup
cp ./*.png backup/
for i in ./*.png; do
echo -n "Adding background ($BGCOLOR) to $i ... "
lillesvin / shutdown_handler.php
Created May 26, 2015
Handler for logging last error even when fatal
View shutdown_handler.php
class ShutdownHandler
private $catch;
private $error;
public function __construct($catch = null)
$this->catch = $catch ?: E_ERROR | E_PARSE;
lillesvin /
Last active Aug 29, 2015
Show active git branch in Bash prompt
# Put this in $HOME/bin/
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
lillesvin / bytescramble.rb
Last active Sep 20, 2015
Data bending is fun!
View bytescramble.rb
#!/usr/bin/env ruby
# ByteScramble
# Copyright 2015 Anders K. Madsen <>
# Licence: MIT <>
# Description:
# ------------
lillesvin / cron-hack
Last active Mar 2, 2016
Hack to run bi-weekly jobs via Cron
View cron-hack
# Hack to run every 2nd Tuesday:
# - Cron notation to run every Tuesday
# - PHP exits with (effectively): date("W") % 2
# - Hacked to remove all '%' because cron can't handle them
# - Use shell chaining (&& and ||) to determine even/odd weeks
# - && for even week numbers, || for odd
# So to run `echo "Still here ..."` every other Tuesday at 10:30 AM:
30 10 * * 2 php -r 'exit((int)fmod(date("W"),2));' && echo "Still here ..."
# Note: PHP can obviously be replaced with anything that
lillesvin / csvize-server-status.rb
Last active Mar 15, 2019
Parses Apache Extended Server Status pages and converts them to CSV. Great in combination with
View csvize-server-status.rb
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'csv'
if ARGV.length < 1
puts "Error: Please supply a URL pointing to an Apache Extended Server Status page"
lillesvin /
Last active Dec 11, 2019
Monitor a file looking for a string. If the moving average of the interval is lower than THRESHOLD, do something!
# This is executed whenever conditions are met
# Change this to whatever you would like to have happen
alert() {
echo 'ALERT, ALERT!!!'
printf "Average hit interval: %.2f sec.\n" "$AVG"
printf "Threshold: %d sec.\n" "$THRESHOLD"
printf "Window length: %d\n" "$WINDOW_LENGTH"
printf "Last window: %s\n" "${INTERVALS[*]}"
lillesvin /
Created Aug 3, 2016
Command line split timer that optionally uses a file as a pipe. You can have OBS read the contents of that file to display your timer in a video/stream if you don't want to just capture part of the terminal window. You can "split" by hitting Return/Enter (in the terminal) while the timer is running, and stop the timer with Ctrl-C (in the termina…
if [[ "${1}x" == "x" ]]; then
You can’t perform that action at this time.