Skip to content

Instantly share code, notes, and snippets.

View unakatsuo's full-sized avatar

Masahiro Fujiwara unakatsuo

View GitHub Profile
@unakatsuo
unakatsuo / gist:1221187
Created September 16, 2011 04:16
Onliner: keep sparse section after decompressing.
# When you extract the compressed file which might be sparse originally, the generated file will be non-sparse.
# Here is the oneliner that allows to keep sparse without creating temporary file.
zcat sparse.raw.gz | cp --sparse=always /dev/stdin sparse.raw
@unakatsuo
unakatsuo / gist:1496579
Created December 19, 2011 10:44
rbenv init section in .bashrc/.bash_profile.
[[ -d "$HOME/.rbenv/bin" ]] && {
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
function rbsudo(){
sudo env - "PATH=$(rbenv root)/shims:$PATH" $*
}
}
@unakatsuo
unakatsuo / gist:2029751
Created March 13, 2012 16:27
Cookie reject list from my Chrome preference.
"[*.]2o7.net": {
"cookies": 2
},
"[*.]accesstrade.net": {
"cookies": 2
},
"[*.]ad-cloud.jp": {
"cookies": 2
},
"[*.]adcirrus.com": {
@unakatsuo
unakatsuo / gist:3727609
Created September 15, 2012 12:36
kpartxとその問題

kpartx -dする際 "Device or resource busy"で失敗する。

原因は、デバイスファイルが/dev/mapper/から消えるまえまでに"ioctl (fd, LOOP_CLR_FD, 0)" (=losetup -d)が行われてしまうこと。 タイミングの問題であるので再現性が低い場合がある。

この問題を回避するためには、"multipath: add udev sync support." (8d63b33d0996e141a2451df552b062b908db15bc)が入っているバージョンを使う必要がある。このchangeにより、"-s"オプションが追加され、udevイベントを待ってからloop deviceの操作が行われるようになる。

これを書いている時点のmultipath-toolsの最新リリースは0.4.9 (2010-10-22)で、このcommitはなんとか入っている。

以下、distro毎の違い

@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?
@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: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: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: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: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/