Skip to content

Instantly share code, notes, and snippets.

View gjedeer's full-sized avatar
💭
Fucking kittens

GDR! gjedeer

💭
Fucking kittens
View GitHub Profile
@gjedeer
gjedeer / show_varnish_utilization
Created August 26, 2013 19:33
Show Varnish cache utilization in percents and megabytes
v_bytes=`varnishstat -1 | grep s0.g_bytes | awk '{print $2}'`
v_space=`varnishstat -1 | grep s0.g_space | awk '{print $2}'`
v_total=$(( v_bytes + v_space ))
v_percent=$(( 100 * v_bytes / v_total ))
v_total_mb=$(( v_total/1024/1024 ))
v_bytes_mb=$(( v_bytes/1024/1024 ))
echo $v_percent % \($v_bytes_mb / $v_total_mb MB\)
@gjedeer
gjedeer / varnish-watchdog.sh
Created July 11, 2013 11:06
Simplest Varnish watchdog possible
#!/bin/bash
/usr/bin/varnishadm quit >/dev/null 2>&1
RETVAL=$?
if [ $RETVAL -eq 2 ]
then
/etc/init.d/varnish restart
fi
@gjedeer
gjedeer / gist:5430144
Created April 21, 2013 16:22
mdadm resync RAID1 array
root@rescue:~# mkdir --parent /dev/md
root@rescue:~# mdadm --assemble --scan --auto=yes --symlink=no
mdadm: /dev/md/le02:1 has been started with 1 drive (out of 2).
mdadm: /dev/md/le02:0 has been started with 1 drive (out of 2).
root@rescue:~# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath] [faulty]
md126 : active raid1 sdb1[1]
40957880 blocks super 1.2 [2/1]
@gjedeer
gjedeer / gist:5397996
Created April 16, 2013 17:50
How I generate an email with planned server restart time, in all time zones
import pytz
from datetime import datetime, timedelta
time_cet = datetime(2013,04,18, 6,0,0, tzinfo=pytz.utc)
for tz in pytz.all_timezones:
print tz.ljust(30), time_cet.astimezone(pytz.timezone(tz)).strftime('%Y %B %d, %H:%M')
@gjedeer
gjedeer / gist:5134047
Created March 11, 2013 12:56
C# 0.1024 -> colormap RGB implementation
int r;
int g;
int b;
if (point <= 128) // 1/8
{
r = 0;
g = 0;
b = 127 + point; // 0.5 ... 1
}
else if (point <= 384) // 3/8
@gjedeer
gjedeer / gist:4514435
Created January 11, 2013 22:16
redmine supervisord script
[program:redmine]
command = /usr/bin/ruby /path/to/redmine/script/fastcgi
process_name = redmine
autostart = true
startsecs = 40
user = www-data
redirect_stderr = true
stdout_logfile = /var/log/redmine.log
environment = RAILS_ENV=production
@gjedeer
gjedeer / gist:4514423
Created January 11, 2013 22:14
Rails with configurable socket path
#!/usr/bin/env ruby
# Run me from scripts/
require File.dirname(__FILE__) + "/../config/environment"
require 'fcgi_handler'
require 'ruby_version_check'
require 'initializer'
require 'dispatcher'
@gjedeer
gjedeer / gist:4136492
Created November 23, 2012 17:06
Add noatime option to fstab for all ext* filesystems
#!/bin/bash
#
# Add noatime option to fstab for all ext* filesystems
#
sed -i -r 's/(ext[2-4]\s+)defaults\s/\1defaults,noatime /g' /etc/fstab
@gjedeer
gjedeer / gist:3422797
Created August 22, 2012 06:14
Mass-change database prefixes in Joomla!
#!/bin/bash
#
# mass change prefixes in Joomla database
# massivescale.net 2012
#
echo "SELECT concat('rename table ', table_name, ' to ', 'iddqd', substr(table_name,4), ';') FROM information_schema.tables WHERE table_name like 'jos%';" | mysql | tail -n +2 | mysql `grep db\ /var/www/configuration.php | awk -F"'" '{print $2}'`
sed -i -e 's/jos_/iddqd_/' /var/www/configuration.php
@gjedeer
gjedeer / logging_wrapper.py
Created March 7, 2012 18:51
Logging wrapper for any command
#!/usr/bin/python
#
# Some command in the system being called in mysterious conditions?
# Use the logging wrapper!
# It will log all calls of a command along with process tree
# ("stack trace" of all calling processes)
#
# Usage:
# pip install psutil
# mv /usr/bin/snoopedcommand /usr/bin/snoopedcommand_wrapped