sed: delete matching lines








sed -i.bak '/pattern/d' input.txt



Shell scripting: remove .DS_Store and ._* files recursively on Linux or Mac








find . -name ".DS_Store" -print0 | xargs -0 rm -rf
find . -name "._*" -print0 | xargs -0 rm -rf
find . -name ".DS_Store" -delete
find . -name "._*" -delete
find . \( -name '.DS_Store' -or -name '._*' \) -delete



Shell scripting: Removing repeating empty lines








cat -s 1.txt > 1.txt; mv 1.txt.tmp 1.txt



Shell scripting: enclose all lines with quotes








  • Using awk:
    awk '{print "\""$0"\""}' input.txt
    
    or if ignore empty lines:
    awk 'NF {print "\""$0"\""}' input.txt
    
  • Or using sed:
    sed -i.bak 's/^/"/; s/$/"/' input.txt
    
    or if ignore empty lines:
    sed -i.bak 's/^..*$/"&"/' input.txt
    



Shell Scripting: delete blank lines from a text file using sed








Delete empty lines using sed:
sed -i.bak '/^\s*$/d' 1.txt



Java: Stream Handler for Logger








        Logger logger = Logger.getLogger("daris-download");
        logger.setLevel(Level.ALL);
        logger.setUseParentHandlers(false);
        /*
         * file handler
         */
        FileHandler fileHandler = new FileHandler(
                "%h/.daris/daris-download.%g.log", 5000000, 2);
        fileHandler.setLevel(Level.ALL);
        fileHandler.setFormatter(new Formatter() {

            @Override
            public String format(LogRecord record) {
                StringBuilder sb = new StringBuilder();
                sb.append(new Date(record.getMillis())).append(" ");
                sb.append("[thread: ").append(record.getThreadID())
                        .append("] ");
                sb.append(record.getLevel().getName()).append(" ");
                sb.append(record.getMessage());
                sb.append("\n");
                return sb.toString();
            }
        });
        logger.addHandler(fileHandler);
        /*
         * console handler
         */
        StreamHandler consoleHandler = new StreamHandler(System.out,
                new Formatter() {
                    @Override
                    public String format(LogRecord record) {
                        return record.getMessage() + "\n";
                    }
                }) {
            @Override
            public synchronized void publish(LogRecord record) {
                super.publish(record);
                super.flush();
            }
        };
        consoleHandler.setLevel(Level.INFO);
        logger.addHandler(consoleHandler);



几个中文影视直播APK











Shell script: Java arguments contains spaces








java -jar myapp.jar ${1+"$@"}

See also




Java: low level logging messages not showing








FINE level logging message is not shown even if the handler.setLevel(Level.FINE).

Reason

java.util.logging has a root logger that defaults to Level.INFO, and a ConsoleHandler attached to it that also defaults to Level.INFO. Level.FINE is lower than Level.INFO, so fine messages are not displayed by default.

Solution

    Logger logger = Logger.getLogger("my-logger");
    logger.setLevel(Level.ALL);
    logger.setUseParentHandlers(false);
    /*
     * file handler
     */
    FileHandler fileHandler = new FileHandler(
                "%h/.my-app.%g.log", 5000000, 2);
    fileHandler.setLevel(Level.ALL);
    logger.addHandler(fileHandler);
    /*
     * console handler
     */
    ConsoleHandler consoleHandler = new ConsoleHandler();
    consoleHandler.setLevel(Level.INFO);
    logger.addHandler(consoleHandler);



Java: Consume InputStream by Null OutputStream








OutputStream nullOutputStream = new OutputStream() { 
    @Override
    public void write(int b) {
    }
};

See also




Java: Remove illegal character 0x0 from string








Unicode 0x0 is illegal in XML.
str.replaceAll("[\\000]+", "")



海外看中超亚冠直播的几个网站








2017年3月更新

  • 乐视由于欠费,失去2017亚冠中超直播权。2017亚冠中超网上直播有PPTV。央视也开始直播亚冠中超。
飞流直播 目前最好的看2017亚冠,中超直播站。【推荐】
http://goatd.net/ 速度比较快,画质一般,无中文解说。中超亚冠都有直播。【不再推荐,因为此网站被google提示有安全问题,其实是弹窗广告安装流氓软件】
央视体育频道(CCTV 5, CCTV 5+)
可在电脑上安装Bluestacks模拟器和电视家观看
中文解说,画质较好,经常有停滞和音画不同步。央视2017直播亚冠中超。



Java synchronized block in static method








class Test {


    public static Test() {
        synchronized(Test.class) {
            ... ...
        }
    }

}



JavaFX WebView shows blank page when the web site ssl certificate is not trusted ( or self-signed)








JavaFX WebView shows blank page when the web site ssl certificate is not trusted (or self-signed). There is not errors/exceptions that you can see unless you set up a listener before you load the web site in WebView: The following code will show the error:
    WebView web = new WebView();
    web.getEngine().load("https://www.your-org.org");
    web.getEngine().getLoadWorker().stateProperty()
            .addListener((ov, oldState, newState) -> {
                System.err.println(web.getEngine().getLoadWorker()
                         .exceptionProperty());
            });
The error is like below:
java.lang.Throwable: SSL handshake failed
To resolve the error, if you trust the web site, you can ignore the error by adding following code before you start the WebView:
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { 
    new X509TrustManager() {     
        public java.security.cert.X509Certificate[] getAcceptedIssuers() { 
            return null;
        } 
        public void checkClientTrusted( 
            java.security.cert.X509Certificate[] certs, String authType) {
            } 
        public void checkServerTrusted( 
            java.security.cert.X509Certificate[] certs, String authType) {
        }
    } 
}; 

// Install the all-trusting trust manager
try {
    SSLContext sc = SSLContext.getInstance("SSL"); 
    sc.init(null, trustAllCerts, new java.security.SecureRandom()); 
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (GeneralSecurityException e) {
}

WebView web = new WebView();
web.getEngine().load("https://www.your-org.org");
NOTE: After executing the above code, your application will trust all https web sites. To have a more secure solution, you may maintain a local key store to add the trusted certificates, see this for more detail.

See also




openssl command to check web site ssl certificate








openssl s_client -showcerts -connect www.google.com:443



Coolpad 8297W remove News Stream








  1. Root the phone
  2. Install System App Remover from Google Play Store.
  3. Uninstall News Stream in System Application Remover



Telstra ZTE MF60 WIFI modem: change APN settings








  • You have to insert a Telstra SIM card (otherwise you will not be able to set the new profile as default.)
  • Power on the modem, can connect to the WIFI from your computer.
  • Open http://192.168.0.1 in your browser.(Default username: admin password: admin)
  • 3G Settings -> APN Settings
  • Click 'Add' button to add a new profile,  edit the APN, then click 'Set default' button.

See also




Telstra ZTE MF60 WIFI modem: reset WIFI password








Hold the WPS button and the POWER button at the same time for about 5-10 secs it will re-start the modem back to the default factory settings.

The original password is printed under the battery in the modem.

See also