Python open file with with statement

It is good practice to use the with keyword when dealing with file objects. This has the advantage that the file is properly closed after its suite finishes, even if an exception is raised on the way. It is also much shorter than writing equivalent try-finally blocks.

Python multiprocessing

Python multiprocessing.

Python multithreading

Python multithreading. NOTE that although multiple threads can run within the python interpreter, ONLY one thread is being executed by the interpreter at any given time, which is ensured by the GIL (global interpreter lock) in python virtual machine. Python multithreading is more appropriate for I/O-bound applications than for CPU-bound applications as I/O releases GIL.

Java okhttp trustall certificate

Java okhttp client trustall certificate (for test only).

Java REPL

Java REPL

Java static class

In Java, static fields and static methods are common but how about static class? Here is an example.

Config postfix with gmail to send email from linux command line

A working example on how to config postfix with gmail smtp server to send email directly from linux command line and tested on vagrant vm with ubuntu precise 32.

Java multithreading

Java multithreading programming demo.

Javascript calendar

A javascript calendar.

Pretty print json

How to pretty print json usually for better visibility.