Skip to content

Instantly share code, notes, and snippets.

View toke's full-sized avatar

Thomas Kerpe toke

View GitHub Profile
@toke
toke / bindzone.js
Created May 5, 2010 19:52
CouchDB Bind zone file generation as an example (CouchDB show function)
function(doc, req) {
// bind zone file generation as an example (CouchDB show function)
// see http://blog.fupps.com/2010/05/03/dns-backed-by-couchdb-redux/
// reused some code by the original author Jan-Piet Mens
// Warning very raw code below. It may eat your pants.
var soa_rr = function (mname, rname, serial, refresh, retry, expire, minimum){
return ("@ IN SOA " + mname + ". " + rname + ". ("+ serial+" "+ refresh + " "+ retry + " "+ expire +" "+ minimum +")\n\n");
};
@toke
toke / 50-touchpad2finger.conf
Created August 31, 2010 00:02
I used this configuration in /usr/lib/X11/xorg.conf.d/ on my peppermint linux (EeePC 1005PE) to get multi finger scroll enabled
Section "InputClass"
Identifier "Enable two finger scroll for synaptics touchpad"
MatchProduct "SynPS/2 Synaptics TouchPad"
MatchDevicePath "/dev/input/event10"
Option "VertTwoFingerScroll" "on"
Option "EmulateTwoFingerMinW" "8"
Option "EmulateTwoFingerMinZ" "40"
Option "SHMConfig" "on"
EndSection
@toke
toke / array_shuffle.js
Created August 27, 2011 14:11
Javascript effective Array shuffle
Array.prototype.shuffle = function () {
var randomIndex, temp, i = this.length;
while (--i) {
randomIndex = Math.floor(i * Math.random());
if (randomIndex !== i) {
temp = this[i];
this[i] = this[randomIndex];
this[randomIndex] = temp;
}
}
@toke
toke / git-cvsupdate.sh
Created December 6, 2011 14:57
git cvs update helper
#!/bin/bash
GIT="/usr/bin/git"
CVS_MODULE_BASE="BASEPATH/"
if [ -d .git ] ; then
if [ `git config --get cvsimport.module` ] ; then
echo "Good! Using the short cvsimport method"
${GIT} cvsimport
@toke
toke / hashmap_vs_if.pl
Created December 8, 2011 11:18
Check if small hashmap is faster than if-cascade. This test is just for fun not for real Performance reasons.
use Benchmark qw(:all);
use Benchmark ':hireswallclock';
my %special_tariffs = (1166 => 1, 1390 => 1,
1229 => 1,
1412 => 1, 1413 => 1
);
my $b;
my $count = 10000000;
$b = timethese($count, {t1 => \&fun1});
@toke
toke / siteupdate.sh
Created February 9, 2012 17:13
Update the website via jekyll
#!/bin/sh
REPPATH="/home/user/git/localgitrepository"
DEPLOYTARGET="/var/www/sites/mydomain"
LIVEURL="http://mydeploydomain.tld"
if [ -d ${REPPATH} ] ; then
cd "${REPPATH}"
git pull
jekyll --url "${LIVEURL}"
@toke
toke / receivehook.pm
Created February 9, 2012 17:18
Dancer github webhook receiver. More Info on: http://toke.de/blog/2012/02/09/how-i-post/ now has an own repo https://github.com/toke/dancing-github-webhooks
package receivehook;
use Dancer ':syntax';
our $VERSION = '0.3';
# Configuration for different projects
my $config = {
"PROJECTNAME" => {
run => "/home/user/bin/updateblog.sh",
},
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@toke
toke / gitsvnrelocate.sh
Created April 17, 2012 15:21
relocation of git-svn repositories
#!/bin/bash
# Helper to relocate git-svn urls.
OLD_REPO=`git config --local --get svn-remote.svn.url`
if [[ $1 ]] ; then
NEW_REPO=$1
else
NEW_REPO='https://defaultrepourl/lalal/'
@toke
toke / dockercleanup.sh
Last active March 3, 2017 04:39
Remove old docker containers and images
# Remove old docker containers
docker rm $(docker ps --no-trunc -aq)
# Remove unreferenced images
docker images | grep "<none>" | awk '{print $3}' | xargs docker rmi
#OR
#alias dockercleancontainers="docker ps -a -notrunc| grep 'Exit' | awk '{print \$1}' | xargs -L 1 -r docker rm"