Skip to content

Instantly share code, notes, and snippets.

@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 / 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/ )
<?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 / 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'
@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 / 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 / ls_recursive_to_plain_listing.py
Created July 18, 2012 14:30
Convert `ls -UR1` output (fastest way to get recursive listing) to plain file listing
#!/usr/bin/env python
import sys
import argparse
def self_check():
from subprocess import check_output, check_call
from StringIO import StringIO
ls_r = StringIO(check_output(['ls', '-1RU']))
@overplumbum
overplumbum / gist:3043615
Created July 3, 2012 21:55
redis memory per db analysys
apt-get install unzip python-pip
pip install https://github.com/sripathikrishnan/redis-rdb-tools/zipball/master
KEYS=$(redis-cli info | perl -nle '/^db.:keys=([0-9]+)/ and print $1' | awk '{ a+=$1 } END { print a }')
rdb -c memory /var/lib/redis/dump.rdb | perl -nle '/^(\d+),.*,(\d+),(\d+)$/ and print $1, " ", $2' | pv -ltpe -s $KEYS | gzip -1 > memory.csv.gz
zcat memory.csv.gz | awk '{ c[$1]++; a[$1] += $2} END { for(i in a) print "db:" i "\t" int(a[i]/1024/1024) "Mb\t" c[i] " keys\t" int(a[i]/c[i]) " b/key" }'
@overplumbum
overplumbum / gist:3037065
Created July 3, 2012 02:05
max fd count per process and per user
for f in /proc/*/fd/ ; do ls -U1 $f | wc -l ; done | sort -gr | head -n1
lsof | awk '{ a[$3]++ } END { for(i in a) print a[i] "\t" i }' | sort -bgr
@overplumbum
overplumbum / gist:2965503
Created June 21, 2012 12:34
Per Process Group memory usage
ps auxw | awk '{ g[$11 " " $12] += $6 } END { for (i in g) { print g[i] "\t" i }}' | sort -bgr