Skip to content

Instantly share code, notes, and snippets.

View anon-hui's full-sized avatar

Anon Sricharoenchai anon-hui

View GitHub Profile
@anon-hui
anon-hui / index_cmp.sh
Last active August 29, 2018 09:32
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)]]]
# $ { head -1000c /home/sysadmin/tmp/f139.3 ; cat /home/sysadmin/tmp/f139.2 ; } | perl -le 'read(STDIN, $a, 1000); print index(join("",<STDIN>),$a)+1'
#{ head -1000c "$2" ; cat "$1" ; } | perl -le 'read(STDIN, $a, 1000); print index(join("",<STDIN>),$a)+1'
#set -- "$1" "$2" "`{ head -1000c "$2" ; cat "$1" ; } | perl -le 'read(STDIN, $a, 1000); print index(join("",<STDIN>),$a)+1'`"
#set -- "$1" "$2" "`perl -le 'open(F, "<", $ARGV[0]); read(F, $a, 1000); close(F); print index(join("",<STDIN>),$a)+1' "$2" < "$1"`"
#set -- "$1" "$2" `perl -le 'open(F, "<", $ARGV[0]); read(F, $a, 1000); close(F); read(STDIN,$b,2000000); for($o=0;;){ read(STDIN,$c,2000000); $i=index($b.substr($c,0,1000-1),$a); if($i>=0){print $o+$i+1;last;} if($c eq""){last;} $o+=length$b; $b=$c; }' "$2" < "$1"`
#. /dev/null
#while (( $# > 2 )) ; do
# (( "$3" > 0 )) && {
# #tail -c+"$3" "$1" | cmp "$2"
@anon-hui
anon-hui / wait_until.sh
Created July 2, 2018 08:26
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