Skip to content

Instantly share code, notes, and snippets.

View riywo's full-sized avatar
🏈
Go 49ers!

Ryosuke Iwanaga riywo

🏈
Go 49ers!
View GitHub Profile
@riywo
riywo / gist:4735767
Created February 8, 2013 01:13
How to parse /proc/PID/cmdline or /proc/PID/environ ?
$ cat /proc/self/cmdline | strings -1
cat
/proc/self/cmdline
@riywo
riywo / gist:4679006
Created January 31, 2013 01:14
use parent in the same script in Perl
use strict;
use warnings;
use B;
B->new();
#-------------------------------
package A;
@riywo
riywo / gist:4678650
Created January 31, 2013 00:12
Open a file with read and write mode or create the file if it does not exist in Perl
$ ls
$ perl -e 'open my $fh, "+<", "hoge" or die $!'
No such file or directory at -e line 1.
$ ls
$ perl -MFcntl -e 'sysopen my $fh, "hoge", O_RDWR|O_CREAT or die $!'
$ ls
hoge
@riywo
riywo / gist:4617052
Last active December 11, 2015 14:49
Exclude "/dev" and strings not explaining absolute file paths from a list with POSIX extended regexp
$ for i in no / /dev /boot /d /de /deva; do echo $i | grep -E '^/([^(dev)].+||d|de|dev.+)$' || echo "skip $i"; done
skip no
/
skip /dev
/boot
/d
/de
/deva
@riywo
riywo / gist:4616862
Last active December 11, 2015 14:49
for i in a aaa bbb abc abcd abcafa ab; do echo $i | grep -E '^a([^(bc)].+||b|bc.+)$' || echo "skip $i"; done
a
aaa
skip bbb
skip abc
abcd
abcafa
ab
#!/usr/bin/expect
spawn dpkg-reconfigure -f readline dash
expect "Use dash as the default system shell (/bin/sh)?"
send "n\n"
interact
@riywo
riywo / Capfile
Created January 5, 2013 07:56
invoked as a login shell with capistrano
default_run_options[:shell] = 'bash -l'
set :sudo, 'sudo -H'
@riywo
riywo / gist:4365586
Last active October 29, 2016 01:07
add known_hosts for localhost with chef
app_home = "/home/#{node['app']['username']}"
execute "add localhost to known_hosts" do
user node['app']['username']
group node['app']['username']
cwd app_home
command "ssh-keyscan localhost >> #{app_home}/.ssh/known_hosts"
not_if "grep -q \"`ssh-keyscan localhost`\" #{app_home}/.ssh/known_hosts"
end
@riywo
riywo / bashrc
Created December 12, 2012 23:49
setting hostname as screen window title
export PS1='\[\033k'"$HOSTNAME"'\033\\\]'"$PS1"
SERVER_ID=1 erb my.cnf.erb > /etc/my.cnf