Skip to content

Instantly share code, notes, and snippets.

View shrkw's full-sized avatar

Hiroyuki Shirakawa shrkw

  • Nagano, Japan
View GitHub Profile
yum -y install python-setuptools
easy_install fabric
@shrkw
shrkw / fw_rule_flattener.py
Created April 26, 2013 06:52
flattening firewall rules
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# sample src
#
# D-U-DENY-1,match,source-address,any
# D-U-DENY-1,match,destination-address,192.0.2.163/32
# D-U-DENY-1,match,destination-address,198.51.100.202/32
# D-U-DENY-1,match,application,any
# D-U-DENY-1,then,deny,
@shrkw
shrkw / edit_jenkins_config.sh
Created July 3, 2013 09:33
Manually editing Jenkins config xml
#!/bin/bash
IFS='
'
i=1
for l in `grep -n '<hudson.triggers.SCMTrigger>' /disk1/jenkins/jobs/*/config.xml`
#for l in `head -1 /tmp/src`
do
n=`echo $l | cut -d':' -f2`
@shrkw
shrkw / userparameter_postgresql.conf
Last active December 20, 2015 02:49
Zabbix template xml and user parameter config file for PostgreSQL 8.2 You need to make public.pg_stat_activity_as_admin view before using postgres.pg_stat_activity.waiting since seeing other owner's processes without superuser permission. http://postgres.sios.com/modules/newbb/viewtopic.php?viewmode=thread&topic_id=117&forum=1
UserParameter=postgres.pg_stat_database[*],$PGSQL_HOME/bin/psql -h localhost -p 5432 -U zabbix-mon YOUR_DB -At -c "SELECT SUM($1) FROM pg_stat_database;"
UserParameter=postgres.pg_locks[*],$PGSQL_HOME/bin/psql -h localhost -p 5432 -U zabbix-mon YOUR_DB -At -c "SELECT COUNT(*) FROM pg_locks WHERE mode='$1';"
UserParameter=postgres.pg_stat_activity.waiting,$PGSQL_HOME/bin/psql -h localhost -p 5432 -U zabbix-mon YOUR_DB -At -c "SELECT COUNT(*) FROM public.pg_stat_activity_as_admin WHERE waiting = false;"
UserParameter=postgres.version,$PGSQL_HOME/bin/psql --version | head -1
@shrkw
shrkw / capturing_server.js
Last active December 21, 2015 19:09
1 file screen capturing server depended on phantomjs
var page = require('webpage').create();
var server = require('webserver').create();
var system = require('system');
var host, port;
if (system.args.length !== 2) {
console.log('Usage: server.js <some port>');
phantom.exit(1);
} else {
port = system.args[1];
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# gunzip -c proxy_access_8844_log-20130720.gz | python ~/ResponseTimeParser.py >> /tmp/proxy_access_8844_log
import sys
import math
class ResponseResult(object):
count = 1
@shrkw
shrkw / db.sqlite3
Created October 28, 2013 16:06
ForeingKey experiments on SQLAlchemy. It seems following 2 python codes are equivalent. According to my experiments, if you want to have `relationship`, you need to use explicitly any `foreign` by `ForeignKey` schema or `foreign` annotation. Anyway you can get the power of `relationship` with or without the foreign key constraints.
CREATE TABLE addresses (
id INTEGER NOT NULL,
email VARCHAR NOT NULL,
owner_id INTEGER,
PRIMARY KEY (id)
);
CREATE TABLE users (
id INTEGER NOT NULL,
name VARCHAR NOT NULL,
PRIMARY KEY (id)
@shrkw
shrkw / mvrck.scala
Last active January 30, 2016 14:05
scalamatsuri 2016
/*
* MAVE
* + RIcK
* -------
* Scala
*/
import scala.annotation.tailrec
@tailrec
@shrkw
shrkw / niagara_rule.ja.md
Last active February 5, 2016 07:50
ナイアガラ ルール 日本語 意訳。ルールは20xx年発売 ドイツ版に基づく。
'##::: ##:'####::::'###:::::'######::::::'###::::'########:::::'###::::
 ###:: ##:. ##::::'## ##:::'##... ##::::'## ##::: ##.... ##:::'## ##:::
 ####: ##:: ##:::'##:. ##:: ##:::..::::'##:. ##:: ##:::: ##::'##:. ##::
 ## ## ##:: ##::'##:::. ##: ##::'####:'##:::. ##: ########::'##:::. ##:
 ##. ####:: ##:: #########: ##::: ##:: #########: ##.. ##::: #########:
 ##:. ###:: ##:: ##.... ##: ##::: ##:: ##.... ##: ##::. ##:: ##.... ##:
 ##::. ##:'####: ##:::: ##:. ######::: ##:::: ##: ##:::. ##: ##:::: ##:
..::::..::....::..:::::..:::......::::..:::::..::..:::::..::..:::::..::
@shrkw
shrkw / playground.swift
Last active February 28, 2016 11:39
swift playground
//: Playground - noun: a place where people can play
import Cocoa
// string
var str = "Hello, playgroundaaa"
var ihoho = 34343
print(str)
str = "ニーハオ" + str