Skip to content

Instantly share code, notes, and snippets.

@nikushi
nikushi / thor.rb
Last active December 14, 2015 12:29
$ bundle gem myapp; cd myapp
$ mkdir bin
$ vim bin/myapp
#!/usr/bin/env ruby
require 'pathname'
lib = Pathname.new(__FILE__).dirname.join('..', 'lib').expand_path
$LOAD_PATH.unshift lib.to_s
@nikushi
nikushi / optparse.rb
Created March 5, 2013 23:46
example of optparse
require 'optparse'
opt = OptionParser.new
OPTS = {}
opt.on('-a') {|v| OPTS[:a] = v }
opt.on('-b') {|v| OPTS[:b] = v }
opt.parse!(ARGV)
p ARGV
@nikushi
nikushi / demo-of-thor.sh
Created March 7, 2013 03:55
Thorで作ったコマンドのデモ
### ヘルプメッセージはThorが組み立ててくれる
$ ./app.rb
Tasks:
app.rb greet [NAME] # greet to people
app.rb hello # Let's say hello!
app.rb help [TASK] # Describe available tasks or one specific task
app.rb konichiwa NAME # say hello to NAME san in Japanese
$ ./app.rb hello
Hello world!
@nikushi
nikushi / logrotate-myapp
Last active December 14, 2015 15:09
1日1回、日付変更以後に前日分のログファイルを前日日付でcompressしてローテートするサンプル
/var/log/myapp/app.log {
rotate 30
daily
missingok
ifempty
compress
dateext
extension .log
lastaction
/bin/mv /var/log/myapp/app-`date '+%Y%m%d'`.log.gz /var/log/myapp/app-`date '+%Y%m%d' -d '1days ago'`.log.gz
@nikushi
nikushi / how-to-logging.rb
Last active December 15, 2015 20:18
How to create a logger and integrate a logger with your app
# encoding: utf-8
class Bootstrap # <- example
def logger(name, level = 'debug')
if development?
STDOUT.sync = true
Logger.new(STDOUT).tap do |logger|
logger.formatter = proc do |level, _, _, message|
"[#{level}] #{message}\n"
@nikushi
nikushi / memo.sh
Created April 16, 2013 11:12
cairoを手動ビルドするときにPKG_CONFIG_PATHの指定が必要
PKG_CONFIG_PATH=/home/growthforecast/local/lib/pkgconfig/ ./configure --prefix=$HOME/local
make
make install
@nikushi
nikushi / gist:5395430
Created April 16, 2013 12:07
RHLE-5でcpanm Alien::RRDtoolするとcairo, libxml2関連でbuildに失敗した時の対策
yum install pango-devel cairo-devel libxml2-devel
https://github.com/yoppi/fluentd.vim/blob/master/syntax/fluentd.vim
を ~/.vim/syntax/において
set syntax=fluentd
@nikushi
nikushi / exec
Last active December 16, 2015 15:49
helper shell-script to run a ruby script on rvm enviroment
# encoding: utf-8
#!/bin/sh
#
# Usage:
#
# APP_ROOT=/usr/local/app HOME=/home/app_user ./exec script/script.rb [options]
#
usage()
@nikushi
nikushi / tcpdump.sh
Created May 8, 2013 02:03
dump packets with automatic rotation
tcpdump -C 500 -W 5 -w dump.pcap