Skip to content

Instantly share code, notes, and snippets.

View unakatsuo's full-sized avatar

Masahiro Fujiwara unakatsuo

View GitHub Profile
@unakatsuo
unakatsuo / gist:6351683
Last active December 21, 2015 19:08
bash rename/alias function.
#!/bin/bash
function alias_function(){
[[ $(type -t "$1") = 'function' ]] || return 1;
local buf
buf="function ${2}()"
buf="${buf} $(declare -f "${1}" | tail -n +2)"
eval "$buf"
}
@unakatsuo
unakatsuo / vmnetcfg.vbs
Last active December 21, 2015 22:09
VBScripted vmnetcfg UI for VMWare Player 5.
Option Explicit
Dim objWMI, objShell, osInfo, os
' http://hitaki.net/diary/20090522.html
' Prompt UAC elevated privilege dialog.
do while WScript.Arguments.Count = 0 and WScript.Version >= 5.7
Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set osInfo = objWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem")
@unakatsuo
unakatsuo / gist:6387005
Last active December 22, 2015 00:09
AWK script that converts YAML text to "/" delimitered format. Help shell script to retrieve complex YAML document.
function ydump() {
# nm: namespace array
# lv: namespace level
# cidt: current indent depth
# lidt: last indent depth
# ac: array counter
awk -v lv=1 -v ac=0 -v cidt=1 -v lidt=1 'BEGIN{ nm[1]=""; }
function path_join(ary, _i,_r,_s) { _r=""; for(_i = 1; _i <= lv; _i++){ _r = _r "/" ary[_i];}; sub("/$", "", _r); sub("^/+", "", _r); return _r; }
# get the current indent depth.
{ match($0, /[^ ]+/); cidt=RSTART;}
@unakatsuo
unakatsuo / Gemfile
Last active December 25, 2015 13:59
Capybara + rspec + PhantomJS (Poltergeist) 連携テスト
source 'https://rubygems.org/'
gem 'capybara'
#gem 'capybara-mechanize'
gem 'poltergeist'
gem 'rspec'
PHANTOM_JS='phantomjs-1.9.2-linux-x86_64'
PHANTOM_JS_DIR=unless ENV['PHANTOM_JS_DIR']
ENV['PHANTOM_JS_DIR'] = File.join(Bundler.root, Bundler.settings[:path], PHANTOM_JS)
@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
@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: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:8143855
Last active April 21, 2017 00:32
yum updateで古いマイナーリリースへ固定する

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

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

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

  1. --releaseverオプションを指定する。
@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: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