Skip to content

Instantly share code, notes, and snippets.

View unakatsuo's full-sized avatar

Masahiro Fujiwara unakatsuo

View GitHub Profile
@unakatsuo
unakatsuo / celluloid-io-inotify.rb
Created June 1, 2015 12:02
Celluloid::IO & rb-inotify
require "celluloid/io"
require "rb-inotify"
require "forwardable"
module Celluloid
module IO
class INotify
extend Forwardable
def_delegators :@notifier, :watch, :close
@unakatsuo
unakatsuo / README.md
Created January 15, 2015 07:30
Shell: Check "return" behavior using at top level.

Check "return" behavior using at top level.

Run with ENV1.

% export ENV1=1
% /bin/sh ./test.sh
ENV1 found
a=1, b=2
% echo $?
@unakatsuo
unakatsuo / git-watch-folder.sh
Created October 14, 2014 11:40
Find modified files under the watching path between two git branches.
#!/bin/bash
set -ue
WATCH_PATH="config/db/migrations/"
MASTER_BRANCH="$1"
WORK_BRANCH="$2"
join -1 4 -2 4 -a 2 <(git ls-tree $MASTER_BRANCH -- $WATCH_PATH) <(git ls-tree $WORK_BRANCH -- $WATCH_PATH) | \
awk '$4 != $7 {print $1 " is changed"; found++; } END{ if (found > 0){ exit 1; } }'
require 'spec_helper'
feature "Feature1" do
scenario "Scenario1" do
step "Do something 1"
step "Do something 2"
step "Do something 3"
step "Do something 4"
end
@unakatsuo
unakatsuo / gist:3ec609b731ee0f2a0812
Created July 14, 2014 16:51
AWK example to print contents in **```shell** code blocks
#!/bin/sh
awk 'BEGIN{blkline=0; skip=0; }
$0 ~ /^## EXAMPLE:$/ && blkline == 1 { skip=1; }
$0 ~ /^```$/ && blkline > 0 {blkline=0;}
blkline > 0 && skip == 0 {print $0; blkline++; }
$0 ~ /^```shell$/ && blkline == 0 {blkline=1; skip=0;}
' <<'EXAMPLE_MD'
## Title
@unakatsuo
unakatsuo / rpmspec_depends.sh
Created January 9, 2014 12:07
Get dependency list from RPM spec in bash.
# Read dependency information from rpmbuild/SPECS/*.spec.
# % cat rpmbuild/SPECS/*.spec | rpmspec_depends
function rpmspec_depends() {
# 0. remove redhat meta variables.
# 1. convert space list to line list.
# 2. remove trailing spaces.
# 3. remove debian meta variables. i.e. ${shlib:Depends}
# 4. remove version conditions.
# 5. remove wakame-vdc packages.
awk -F: '$1 == "BuildRequires" || $1 == "Requires" { print substr($0, length($1)+2)}' | \
@unakatsuo
unakatsuo / gist:8143855
Last active April 21, 2017 00:32
yum updateで古いマイナーリリースへ固定する

RHEL系で新しいマイナーリリースができた時yum updateしてしまうと、システムが大きく更新される。本番環境などではこれを固定したいことがあるので、その方法。

yum.repoファイルへ現れる、$releasever 変数を固定する。

例: CentOS6.4で以降のリリースがある場合でも6.4のまま固定化する。

  1. --releaseverオプションを指定する。
@unakatsuo
unakatsuo / gist:7819587
Created December 6, 2013 06:47
curl example for converting github issue to pull request.
# http://developer.github.com/v3/pulls/#create-a-pull-request
curl -u "unakatsuo:your_oauth_token" https://api.github.com/repos/axsh/wakame-vdc/pulls -d '{"issue": "325", "head":"fix-instance-monitor", "base":"master"}'
@unakatsuo
unakatsuo / gist:7480034
Created November 15, 2013 06:24
Rescan backing store path online for tgt.

online=0 is the secret key make this happen.

# tgtadm --lld iscsi --op update --mode logicalunit --tid=1 --lun=1 --params 'online=0,path=/mnt/work1/testvol/vol2.img'
@unakatsuo
unakatsuo / gist:7349027
Created November 7, 2013 04:37
Run rpmbuild to extract source tree with bundled patch set.
% rpmbuild -bp --nodeps hoge.spec