Monday, 11 June 2018

青蛙旅行 - 一次性下载相册



one-liner:

function frog_travel_albums() {
    cd ~/Downloads/; adb pull /storage/emulated/0/Android/data/jp.co.hit_point.tabikaeru/files/Picture; cd Picture; find . -iname "album_*.sav" -exec bash -c 'fs="$(( "$(stat --printf="%s" $1)" - 4 - 32))"; if  [ ! -f "$1".png ] || [ "$fs" -ne "$(stat --printf="%s" $1.png)" ]; then dd if="$1" of="$1".png bs=1 skip=4 count="$fs"; else echo "File already exists"; fi' _ {} \;; rm *.sav; rm *.sav.back; (nautilus . >/dev/null 2>&1 &)
}
export -f frog_travel_albums

Thursday, 7 June 2018

java jgrep




xb@dnxb:/tmp$ java -verbose |& grep rt.jar | head -1 #to find out java runtime path
[Opened /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar]
xb@dnxb:/tmp$ unzip /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar -d /tmp/rt #unzip the rt.jar
   creating: /tmp/rt/META-INF/
 extracting: /tmp/rt/META-INF/MANIFEST.MF  
 extracting: /tmp/rt/com/oracle/net/Sdp$1.class  
 extracting: /tmp/rt/com/oracle/net/Sdp$SdpSocket.class
...
 extracting: /tmp/rt/java/io/Serializable.class  
 extracting: /tmp/rt/java/lang/String.class  
 extracting: /tmp/rt/java/lang/Object.class  
xb@dnxb:/tmp$ 
xb@dnxb:/tmp$ find /tmp/rt > /tmp/rt.map #create list path as map
xb@dnxb:/tmp$ cp /tmp/rt.map ~/CRITICAL/ #save as permanent map


bash function:

jgrep ()
{
    OPTS=`getopt -o iva --long case-insensitive,verbose,all -n 'parse-options' -- "$@"`;
    if [ $? != 0 ]; then
        echo "Failed parsing options." 1>&2;
        return;
    fi;
    eval set -- "$OPTS";
    i=;
    in=;
    prefix='/';
    postfix='\.class';
    javap_cmd=:;
    while true; do
        case "$1" in
            -i | --case-insensitive)
                i='i';
                in='in';
                shift
            ;;
            -v | --verbose)
                javap_cmd=javap;
                shift
            ;;
            -a | --all)
                prefix=;
                postfix=;
                shift
            ;;
            --)
                shift;
                break
            ;;
            *)
                break
            ;;
        esac;
    done;
    rt_p=~/CRITICAL/rt.map;
    grep -a --color=auto --color=never -a"$i" "$prefix$1$postfix" "$rt_p" | cut -c 9- | sed 's/\//./g' | while read -r line; do
        if [[ "$line" =~ '.class'$ ]]; then
            line="$(echo "$line" | rev | cut -c7- | rev )";
        fi;
        echo "$line" | grep -a --color=auto --color=always -a"$i" "$1";
        "$javap_cmd" "$line";
        echo;
    done
}