Skip to content

Instantly share code, notes, and snippets.

View unakatsuo's full-sized avatar

Masahiro Fujiwara unakatsuo

View GitHub Profile
@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: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 / 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: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 / gist:6229392
Created August 14, 2013 09:30
qemu drive handling distribution difference.
RHEL QEMU
## Ubuntu 12.04
qemu-kvm_1.0+noroms-0ubuntu14.10
```
$ ls debian/patches/
@unakatsuo
unakatsuo / gist:6211881
Created August 12, 2013 15:28
access to the Jenkins loaded plugin.
PluginWrapper p = Jenkins.getInstance().getPluginManager().getPlugin("mailer");
p.isActive();
p.isEnabled();
@unakatsuo
unakatsuo / gist:6017372
Last active December 19, 2015 20:59
Onliner for constantize from string.
module A
module B
module C
end
end
end
'A::B::C'.split('::').unshift(Object).inject{|l, o| l.const_get(o) }
@unakatsuo
unakatsuo / gist:5909894
Created July 2, 2013 14:44
force rvm to compile binary from source. (with favorite cc options)

command line example:

% CFLAGS="-O0 -g" rvm install 2.0.0  --disable-binary
@unakatsuo
unakatsuo / gist:5803831
Last active December 18, 2015 15:19
Resizing partition and ext4 filesystem without breaking existing MBR.
# parted /dev/sda
GNU Parted 2.3
Using /var/tmp/5m
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model:  (file)
Disk /var/tmp/5m: 10.5MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
@unakatsuo
unakatsuo / gist:4516413
Created January 12, 2013 06:24
net/http using Celluloid::IO.
require 'celluloid/io'
require 'net/http'
module Celluloid
module IO
# TCPSocket with combined blocking and evented support
class TCPSocket
def eof?