2015/09/15

Perl and UTF-8

perl -CS -e 'print'

---

use utf8;

---

binmode STDOUT, ':encoding(UTF-8)';
binmode STDOUT, ':utf8';

---

use encoding 'utf-8';

2015/08/17

Sudo on OS X

http://blog.rongarret.info/2015/08/psa-beware-of-sudo-on-os-x.html

2015/07/03

Bash: init from arg

Initialize from argument:
TEST=$(test -n "$1" && echo $1) || { echo "Usage: $0 <path_to_file>"; exit; }

test -z $1 && echo "Usage: $0 <path_to_file>" && exit
TEST=$1

2015/06/25

Divide with floating point

awk 'BEGIN {printf "%.2f \n", (11.226 - 8.342)/11.226*100}'
awk 'BEGIN {print (11.226-8.342)/11.226*100}'

Rounding up works by default:
awk 'BEGIN {printf "%.3f \n", (11.226 - 8.342)/11.226*100}'

2015/06/12

Filter STDERR only

$ cat warn.pl
#!/usr/bin/env perl
print STDERR "warnings all over the place\n";
print STDOUT "standard output to file descriptor 1\n";

$ exec 3>&1; ./warn.pl 2>&1 >&3 3>&- | awk '{print $5}' 3>&-; exec 3>&-
standard output to file descriptor 1
place

2015/05/26

.bashrc

~/.bashrc
~/.bash_profile

export PS1="\[\033[36m\]\u\[\033[m\]@\h:\[\033[32m\]\w\[\033[m\]\$ "
export PS1="\[\033[36m\]\A \[\033[32m\]\w/ \[\033[33m\]\$ \[\033[m\]"
export PS1="\[\033[32m\]\w/ \[\033[33m\]\$ \[\033[m\]"
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GFh'
alias l='ls -l'
alias md='mkdir -p'
alias ..='cd ..'

alias grep='grep --color=auto -n'

2015/05/13

Oracle

select now():
select to_char(sysdate, 'mm-dd-yyyy hh24:mi:ss') "now" from dual;

select last row:
select * from table where id = (select max(id) from table);