Skip to content

Instantly share code, notes, and snippets.

Anders K. Madsen lillesvin

View GitHub Profile
@lillesvin
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 https://github.com/BurntSushi/xsv
View csvize-server-status.rb
#!/usr/bin/ruby
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"
exit
@lillesvin
lillesvin / shplit.sh
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…
View shplit.sh
#!/bin/bash
if [[ "${1}x" == "x" ]]; then
USE_PIPE=false
else
USE_PIPE=true
PIPE=${1}
fi
FORMAT="%s.%2N"
@lillesvin
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
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 <lillesvin@gmail.com>
# Licence: MIT <https://opensource.org/licenses/MIT>
#
# Description:
# ------------
@lillesvin
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
#!/bin/bash
files=$(git status --porcelain | sed -e 's/^.* //' | grep -P '\.php$')
for f in $files; do
php -l $f
done
@lillesvin
lillesvin / get_git_branch.sh
Last active Aug 29, 2015
Show active git branch in Bash prompt
View get_git_branch.sh
#!/bin/bash
# Put this in $HOME/bin/get_git_branch.sh
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
branch='detached*'
fi
fi
@lillesvin
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
lillesvin / fix_dropbox_icons.sh
Last active Aug 29, 2015
Fixed broken Dropbox icons in i3 (and probably other WMs with a few adjustments).
View fix_dropbox_icons.sh
#!/bin/bash
WD="$HOME/.dropbox-dist/dropbox-lnx*/images/hicolor/16x16/status"
BGCOLOR=`ruby -e "puts File.read(ENV['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 ... "
You can’t perform that action at this time.