Mock transactionTemplate

Mockito.when(mockTransactionTemplate.execute(Mockito.any()))
    .thenAnswer(invocationOnMock -> {
        Object[] args = invocationOnMock.getArguments();
        TransactionCallback arg = (TransactionCallback)args[0];
        return arg.doInTransaction(new SimpleTransactionStatus());
    });

PatternDelete

Delete the pattern line and save back (Mac OSX)\nMac use sed command’s -i option need String parameter , in order to tell sed save old file to this file suffix.

find . -type f -name '*[m|h]' | xargs -I {} sed -i '' '/.*凌星.*/d' {}

TCL Expect

#!/usr/bin/expect -f

proc terminal:password:get {promptString} {

     # Turn off echoing, but leave newlines on.  That looks better.
     # Note that the terminal is left in cooked mode, so people can still use backspace
     exec stty -echo echonl <@stdin

     # Print the prompt
     puts -nonewline stdout $promptString
     flush stdout

     # Read that password!  :^)
     gets stdin password

     # Reset the terminal
     exec stty echo -echonl <@stdin

     return $password
}

proc chooseMachine { } {
    puts "1) 11.192.101.216 (pre/ccvob);\n2) 11.192.101.192;\n3) 11.192.101.236;\n4) 11.192.101.221;";
    gets stdin choice;
    switch $choice {
        1 {
            return "11.192.101.216";
        }
        2 {
            return "11.192.101.192";
        }
        3 {
            return "11.192.101.236";
        }
        4 {
            return "11.192.101.221";
        }
        default {
            return "11.192.101.216";
        }
    }
}

proc main { } {
    set timeout -1;
    set IP [ chooseMachine ];
    set PASSWORD [ terminal:password:get "请输入密码:" ];
    puts "Start build source success";
    spawn ssh van.yzt@11.239.182.250;
    expect "*password:";
    send "$PASSWORD\r";
    expect "*$*";
    set TOKEN [ terminal:password:get "请输入6位令牌:" ];
    spawn ssh van.yzt@login1.am100.alibaba-inc.com;
    expect "*password*";
    send "$PASSWORD$TOKEN\r";
    expect "*$*";
    send "ssh van.yzt@$IP\r";
    expect "password:";
    send "$PASSWORD\r";
    expect "*$*";
    send "sudo su admin\r";
    expect "*password*";
    send "$PASSWORD\r";
    expect "*$*";
    interact;
    exit 0;
}

[ main ];

按照入参排序

select * from users where extern_uid in ('24311', '169942', '157193', '103420', '183078') order by instr(',24311,169942,157193,103420,183078,', concat(',', extern_uid, ','));

原始SQL,用instr;

public static String getOrderByInstr(String value, String field) {
    return String.format("INSTR(',%s,', CONCAT(',', %s, ','))", value, field);
}

在java中封装成一个方法。

Forbid body drag

HTML

JS

document.body.ondrag = function () { return false; }

see some **document.body**'s **drag*** attributes.

CSS

.unselectable {
   -moz-user-select: -moz-none;
   -khtml-user-select: none;
   -webkit-user-select: none;

   /*
     Introduced in IE 10.
     See http://ie.microsoft.com/testdrive/HTML5/msUserSelect/
   */
   -ms-user-select: none;
   user-select: none;
}