Skip to content

Instantly share code, notes, and snippets.

View caramelchocolate's full-sized avatar

caramelchocolate

View GitHub Profile
@caramelchocolate
caramelchocolate / main.sh
Created August 4, 2019 12:23
display "displayName" and "address" in VMware fusion
#!/bin/sh
find ~/Documents/Virtual\ Machines.localized/ -name '*.vmx' -print0 | xargs -0 -I@ -L1 sh -c 'f="@";cat ${f}|grep displayName|address'
@caramelchocolate
caramelchocolate / main.sh
Created August 4, 2019 06:02
display /etc/resolv.conf in jails
#!/bin/sh
find ./jail/base*/ -name 'resolv.conf' | xargs -L1 -I@ sh -c 'f="@";echo ">>>${f}";cat ${f}; echo "<<<${f}";echo;'
@caramelchocolate
caramelchocolate / main.sh
Last active July 23, 2019 04:05
collect /usr/local/etc/postfix/main.cf in jail
#!/bin/sh
jls | awk 'NR>1 {print $4}' | awk -F'/' '{print $NF}' | xargs -I@ sh -c 'j=@; c=$(jexec ${j} test -e /usr/local/etc/postfix/main.cf && jexec ${j} cat /usr/local/etc/postfix/main.cf); echo "${c}" > "${j}.txt"'
@caramelchocolate
caramelchocolate / main.sh
Last active July 23, 2019 04:04
collect /etc/hosts in jail
#!/bin/sh
jls | awk 'NR>1 {print $4}' | awk -F'/' '{print $NF}' | xargs -I@ sh -c 'j=@; c=$(jexec ${j} cat /etc/hosts); echo "${c}" > "${j}.txt"'
@caramelchocolate
caramelchocolate / main.sh
Last active July 23, 2019 04:03
list php version in jails
#!/bin/sh
jls | awk 'NR>1 {print $4}' | awk -F'/' '{print $NF}' | xargs -I@ sh -c 'j=@; v=$(jexec ${j} php -v | head -1); echo "${j}: ${v}"'
@caramelchocolate
caramelchocolate / main.sh
Created July 20, 2019 06:40
特定のnginx.confを読み込み、start|restart|stopをする場合に使用するラッパー。
#!/bin/sh
# nginx.conf の pid /path/nginx.pid; の調整は必要。
args=${1:-""}
case "${args}" in
stop)
echo 'stop';
;;
restart)
@caramelchocolate
caramelchocolate / .cshrc
Created July 20, 2019 06:30
cshでのプロンプトでIPとディレクトリを表示。2行プロンプトにする。
set ip=`ifconfig -l | awk '{print $1}' | xargs -L1 -I@ ifconfig @ inet | grep inet | awk '{print $2}' | head -n 1`
set prompt="%{\e[00;32;40m%}${ip}:%/%{\e[0m%} \n[freebsd]❯"
@caramelchocolate
caramelchocolate / main.php
Created July 5, 2019 11:10
1行ずつ読み込み
<?php
$file = new SplFileObject(__FILE__);
while (!$file->eof()) {
echo $file->current();
$file->next();
}
?>
@caramelchocolate
caramelchocolate / main.php
Last active July 5, 2019 11:07
PHP Closure
<?php
class a {
protected $hoge = 'foo';
}
$a = new a();
$closure = Closure::bind(function () {
$this->hoge = 'foofoo';
}, $a, $a);
$closure();
@caramelchocolate
caramelchocolate / main.sh
Created June 25, 2019 07:10
pkg bootstrap and install latest version of python
#!/bin/sh
pkg_base_path="/usr/local/bin/"
get_python_path () {
ls -1 "${pkg_base_path}" | grep -E '^python[0-9]{1}\.[0-9]{1}$'
}
pkg -N > /dev/null
st_code=$?