Skip to content

Instantly share code, notes, and snippets.

View shrkw's full-sized avatar

Hiroyuki Shirakawa shrkw

  • Nagano, Japan
View GitHub Profile
@shrkw
shrkw / etc init.d unicorn-redmine
Last active July 6, 2016 01:22
init script for unicorn on RHEL, Cent OS, Scientific Linux way
#!/bin/sh
#
# unicorn_redmine Startup script for unicorn for redmine
#
# chkconfig: - 86 14
# processname: unicorn_rails
# pidfile: /opt/redmine/tmp/pids/unicorn.pid
# description: Rails application server for Redmine
#
### BEGIN INIT INFO
@shrkw
shrkw / useradd_wih_ssh_key.sh
Created February 8, 2013 01:53
create new user with ssh key
read USER_NAME
useradd ${USER_NAME}
mkdir -m 700 /home/${USER_NAME}/.ssh
cat << _EOF_ > /home/${USER_NAME}/.ssh/authorized_keys
chmod 400 /home/${USER_NAME}/.ssh/authorized_keys
chown ${USER_NAME}:${USER_NAME} -R /home/${USER_NAME}/.ssh
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 / gunicorn_with_virtualenv
Created October 31, 2013 10:51
CentOS init script for Gunicorn with Virtualenv
#!/bin/sh
#
# gunicorn_sr Startup script for gunicorn for sr
#
# chkconfig: - 86 14
# processname: gunicorn
# pidfile:
# description: Python application server
#
### BEGIN INIT INFO