Skip to content

Instantly share code, notes, and snippets.

View anon-hui's full-sized avatar

Anon Sricharoenchai anon-hui

View GitHub Profile
perl -e 'use Time::HiRes qw(time sleep); use POSIX qw(strftime); vec($r="",0,1)=1;$|=1;print"-"x79,"\n";<STDIN>;for($s=$p=$t=time,$i=1;;$t=time){sub p{$a=sprintf"%7.2f",$_[1];strftime($_[0],gmtime$a).substr($a,-3)." $a"}print p("%F.%T",$t)," ",p("%T",$t-$s)," ",p("%M:%S",$t-$p)," $i\r"; select($ro=$r,undef,undef,0.001)>0 and<STDIN>,$p=$t,++$i}'
@anon-hui
anon-hui / eval_1.sh
Last active July 10, 2025 06:18
find the position in 1st file where its binary match the head of 2nd file, and begin cmp at that position; Usage: $ . index_cmp.sh file1 file2 [offset_of_file2_head(default_0) [length_of_file2_head_to_search(default_1000) [offset_in_file1_to_start_search(default_0)]]]
#set -- "$@"
#. /dev/null
if : || [[ "$1" != "set "* ]] ; then
#echo '$ '
#echo "$1" ; eval "$1"
echo '$ ' >&2
#echo "$1" >&2 ; eval "$1"
#echo "$1" >&2 ; eval "shift ; . /dev/null ; $1"
# * sourcing make it not return $@, but no this effect when shift
@anon-hui
anon-hui / wait_until.sh
Last active July 10, 2025 08:24
Wait until specified time has been reached. Time format is exactly the same as the format accepted by "date -d time". (bash shell) (see example in comment) Usage: $ . wait_until.sh time
##set -- "$(( `date -d "$1" +%s`-`date +%s` ))"
#set -- "$(( `date -d "$1" +%s`-`date +%s` ))" "$2"
#[[ "$2" == "" ]] || set -- "$(( $1+$2*60 ))"
##echo "$1"
#set -- "$(( $1>=0 ? $1 : 0 ))"
#. /dev/null
##echo "$1"
#sleep -- "$1"
# * the above not work after suspend or hibernate
@anon-hui
anon-hui / zip.sh
Last active July 2, 2018 08:32
compress file using best command between, gzip, gzip -9, bzip2, bzip2 -9, lzma, lzma -9. (bash shell) Usage "$ . zip.sh filename". th_TH:บีบอัดไฟล์โดยเลือกคำสั่งที่ดีที่สุดระหว่าง, gzip, gzip -9, bzip2, bzip2 -9, lzma, lzma -9.
. /dev/null
set -- "$1" "`wc -c -- "$1" | tee /dev/stderr | awk '{print$1}'`" '' :
echo "${@:2}" ;
set -- "$1" "$2" "`gzip -c -- "$1" | wc -c`" "${@:4}"
echo "${@:2}" ; (( "$3" < "$2" )) && set -- "$1" "$3" '' gzip
set -- "$1" "$2" "`gzip -c -9 -- "$1" | wc -c`" "${@:4}"
echo "${@:2}" ; (( "$3" < "$2" )) && set -- "$1" "$3" '' gzip -9
2