Skip to content

Instantly share code, notes, and snippets.

View yyuu's full-sized avatar
👽
Working from home

Yamashita, Yuu yyuu

👽
Working from home
View GitHub Profile
hello, gist
@yyuu
yyuu / gist:931016
Created April 20, 2011 11:18
unit conversion in awk
function atoix(a) {
if(a~/Pi?B/) return int(a)*1024^5;
if(a~/Ti?B/) return int(a)*1024^4;
if(a~/Gi?B/) return int(a)*1024^3;
if(a~/Mi?B/) return int(a)*1024^2;
if(a~/Ki?B/) return int(a)*1024^1;
return int(a);
}
function itoax(i) {
@yyuu
yyuu / gist:931210
Created April 20, 2011 12:33
Makefile to dump all Cassandra's SSTables to JSON (with LZO compression)
SRCDIR = /var/lib/cassandra/data
DSTDIR = .
SOURCES = $(wildcard $(SRCDIR)/*/*-Data.db)
ALL = $(foreach S,$(SOURCES),$(basename $(subst $(SRCDIR)/,,$(S))).json.lzo)
.SUFFIXES: .json.lzo
all: $(ALL)
@yyuu
yyuu / resolvconf.conf
Created May 24, 2011 17:12
upstart configuration for resolvconf (LP:448095)
# upstart script for resolvconf
start on ( virtual-filesystems and starting udev )
stop on runlevel [06]
pre-start script
invoke-rc.d resolvconf start
end script
@yyuu
yyuu / irc.alert
Created July 14, 2011 10:19
irc alert script for mon
#!/usr/bin/env ruby
require 'logger'
require 'net/irc'
require 'optparse'
require 'thread'
class IRCNotifier < Net::IRC::Client
def initialize(host, port, opts={})
super
@yyuu
yyuu / gist:1084613
Created July 15, 2011 12:46
fucking cardinal conversion in awk
function int2(str, card, rec) {
if(!card) card=10;
i = index("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", toupper(substr(str, 1, 1)))-1;
if(length(str) < 2) {
return rec*card+i;
} else {
return int2(substr(str, 2), card, rec*card+i);
}
}
@yyuu
yyuu / gist:1099104
Created July 22, 2011 08:44
tcp6? connection monitor for munin
#!/bin/sh
case $1 in
config)
cat <<EOF
graph_title Connections through firewall
graph_vlabel Connections
graph_category network
graph_args -l 0
established.label ESTABLISHED
@yyuu
yyuu / gist:1277579
Created October 11, 2011 08:33
aws-rds-benchmark.sh
#!/bin/sh -e
rds_db_instance_identifier() {
echo "$@" | sed -e 's/[^-0-9A-Za-z]/-/g'
}
rds_describe_db_instance() {
if test $# -lt 1; then
return 1
fi
@yyuu
yyuu / msgpack-rpc.monitor.rb
Created November 7, 2011 10:51
a mon's monitor plugin to monitor msgpack-rpc services
#!/usr/bin/env ruby
require 'rubygems'
require 'msgpack/rpc'
require 'optparse'
require 'yaml'
PROGRAM_NAME = File.basename($0)
EXIT_SUCCESS = 0
EXIT_FAILURE = 1
@yyuu
yyuu / gist:1414604
Created December 1, 2011 07:21
a coroutine implementation that can work with tornado.ioloop
#!/usr/bin/env python
import tornado.ioloop
class Coroutine(object):
"""
a coroutine implementation that can work with tornado.ioloop
def generator():
print('A')