Skip to content

Instantly share code, notes, and snippets.

@overplumbum
overplumbum / gist:3170968
Created July 24, 2012 16:16
LXC Containers Static IP
grep address /var/lib/lxc/*/rootfs/etc/network/interfaces | perl -ple 's|.*/([^/]+)/rootfs/.*:\s*address\s+(.*)|$2 $1|' | sort -V
@overplumbum
overplumbum / bench.py
Created September 20, 2012 10:59
Slow queries log benchmark automation
#!/usr/bin/env python
import csv
import psycopg2
from datetime import datetime
COLS = ('id', 'date', 'connection', 'database', 'user', 'duration', 'query')
IDX = dict(zip(COLS, range(len(COLS))))
IDX_QUERY = IDX['query']
conn = psycopg2.connect('')
@overplumbum
overplumbum / detect_active_login
Created October 3, 2012 13:14
Detects logged in user even under sudo
#!/usr/bin/env python
import os
import psutil
if __name__ == "__main__":
p = psutil.Process(os.getpid())
while p and p.username == 'root':
p = p.parent
print p.username if p else 'root'
<?php
$wgExtensionCredits['other'][] = array(
'name' => 'Google Apps Authentication',
'version' => '1.0',
'path' => __FILE__,
'author' => array( 'Emanuele Nanetti', 'Bertrand Gorge' ),
'url' => 'http://www.mediawiki.org/wiki/Extension:GoogleAppsAuthentification',
);
@overplumbum
overplumbum / lxc-shm-fix.sh
Created November 16, 2012 15:23
Permament fix for /run/shm creation in Ubuntu LXC guest systems (oneiric..precise)
#!/bin/bash
# https://bugs.launchpad.net/launchpad/+bug/974584
# common oneiric-lxc-guest bug
grep --silent "/run/shm" /lib/init/fstab || echo "none /run/shm tmpfs nosuid,nodev 0 0" >> /lib/init/fstab
mkdir -p /run/shm
mount /run/shm
# required for systems after manual dirty fixing
test -L /dev/shm || ( umount /dev/shm ; rm -fr /dev/shm && ln -s /run/shm /dev/ )
@overplumbum
overplumbum / sentry-autoregistration.sh
Created November 21, 2012 15:04
Sentry: Add users without teams to all the teams as admins
su -l postgres -c "psql sentry -c '
INSERT INTO sentry_teammember (team_id, user_id, is_active, type, date_added)
SELECT t.id, u.id, true, 0, now() from sentry_team t, auth_user u
WHERE not exists (select 1 from sentry_teammember m where u.id = m.user_id);
'"
@overplumbum
overplumbum / README
Last active October 13, 2015 12:37
Update Yandex DNS A record with host IP
curl -sL https://gist.github.com/overplumbum/4196574/raw/install.sh > tmp.sh && sudo sh tmp.sh
@overplumbum
overplumbum / gist:4473076
Last active March 15, 2022 12:03
OpenVPN server as an LXC container
#!/bin/bash
set -ve
lxc-create -n vpn -t ubuntu
# ln -s /var/lib/lxc/vpn/config /etc/lxc/auto/vpn.conf
perl -i -ple 's/#lxc.aa_profile = unconfined/lxc.aa_profile = unconfined/' /etc/lxc/auto/vpn.conf
perl -i -ple 's/^exit 0/# exit 0/' /etc/rc.local
cat >>/etc/rc.local <<hello
mkdir -p /var/lib/lxc/vpn/rootfs/dev/net/
#!/usr/bin/env python
# by denis@
import os
from subprocess import check_output as co, call
import time
def submit(value):
call("echo -n 'statsd.custom.cpuusage:{}|g' | nc -w 1 -u localhost 8125".format(value), shell=True)
@overplumbum
overplumbum / tzinfo_update_check.sh
Last active December 14, 2015 18:48
checks if tzinfo is up-to-date for different platforms
# correct output is -03:00
pip install --upgrade --verbose pytz
python -c "from pytz import timezone as z; from datetime import datetime as d; print str(z('America/Santiago').localize(d(2013, 03, 11)))"
# correct output is 07:00
gem install tzinfo
ruby -e 'require "Date"; require "TZInfo"; t=DateTime.strptime("2013-03-11 10-00-00", "%Y-%m-%d %H-%M-%S"); t=TZInfo::Timezone.get("America/Santiago").utc_to_local(t); print(t, "\n")'
# Perl's DateTime data
# correct output is also 07:00