Skip to content

Instantly share code, notes, and snippets.

@insom
insom / fpmunix.conf
Created July 19, 2013 10:26
Monitor the state of an FPM Unix FastCGI socket, to get the "queue length" from the kernel
LoadPlugin curl_json
<Plugin curl_json>
<URL "http://localhost:5000/">
Instance "fpmunix"
<Key "connecting">
Instance "connecting"
Type "listen_queue"
</Key>
<Key "connected">
Instance "connected"
/*
* Copyright (C) 2013 Aaron Brady
* Copyright (C) 2008-2012 Red Hat, Inc.
* Copyright (C) 2008 IBM Corp.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
@insom
insom / lxc2.c
Created May 9, 2013 22:46
Enough LXC to create separate networking stack and to bring up a usable getty.
#include <sched.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
@insom
insom / geoip-from-apache.py
Last active December 17, 2015 03:59
Get a breakdown of traffic from an Apache log file, by country. `pip install pygeoip` first.
import re
import sys
from pygeoip import GeoIP
g = GeoIP('GeoIP.dat')
r = re.compile(r'20. ([0-9]+) "')
d = {}
@insom
insom / lxc.c
Last active December 17, 2015 01:29
Just enough LXC to create a new process in a private PID tree. (Some bits ripped from libvirt's LXC implementation)
$ sudo ./a.out
PID: 7780
Child!
ERR: 0!
Success
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 1852 344 pts/3 S+ 23:16 0:00 ./a.out
root 2 0.0 0.0 1932 504 pts/3 S+ 23:16 0:00 sh -c ps auxwf
root 3 0.0 0.0 4336 1008 pts/3 R+ 23:16 0:00 \_ ps auxwf
@insom
insom / moon.py
Created April 26, 2013 16:14
Emoji Phases of the Moon in Python
import sys, time
while True:
for i in range(311, 319):
print "\r", eval("u'\U0001f%d'" % i), "",
sys.stdout.flush()
time.sleep(0.1)
""""Create "The Matrix" of binary numbers scrolling vertically in your terminal.
original code adapted from juancarlospaco:
- http://ubuntuforums.org/showpost.php?p=10306676
Inspired by the movie: The Matrix
- Corey Goldberg (2013)
Requires:
@insom
insom / libvirtnovnc.py
Created November 8, 2012 11:30
Libvirt NoVNC Proxy
#!/usr/bin/python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Based on work Copyright (c) 2012 Openstack, LLC.
import Cookie
import os
import socket
import sys
import websockify
@insom
insom / glacier.py
Created August 22, 2012 09:51 — forked from almost/glacier.py
Amazon Glacier from Python. Based on Boto, will contribute to Boto when it's a little more finished if it's any good at that point :)
# Thomas Parslow http://almostobsolete.net
# Just a work in progress and adapted to what I need right now.
# It does uploads (via a file-like object that you write to) and
# I've started on downloads. Needs the development version of Boto from Github.
#
# Example:
#
# glacierconn = GlacierConnection(AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY)
# writer = GlacierWriter(glacierconn, GLACIER_VAULT)
# writer.write(somedata)
@insom
insom / .daz.bashrc
Created May 14, 2012 09:59
Daz-inspired .bashrc
alias ss="ssh $1.manc.iws-hosting.co.uk"
# Color codes
RED='\[\033[01;31m\]'
GREEN='\[\033[01;32m\]'
YELLOW='\[\033[01;33m\]'
BLUE='\[\033[01;34m\]'
PURPLE='\[\033[01;35m\]'
CYAN='\[\033[01;36m\]'
WHITE='\[\033[01;37m\]'
NIL='\[\033[00m\]'