Converting Stacktrace to String

To store stack trace as a string, you can use Throwable.printStackTrace(...) For example: public static String getStackTrace( Throwable throwable ){ Writer result = new StringWriter(); PrintWriter printWriter = new PrintWriter(result); throwable.printStackTrace(printWriter); return result.toString(); } In the above example, getStackTrace takes a Throwable as a parameter and uses printStackTrace to print it to a PrintWriter output stream. This output is collected by the StringWriter and converted to a string using StringWriter.toString().

April 8, 2017 · 1 min · Rezha Julio

Synchronized Statement in Java

synchronized statements can be used to avoid memory inconsistency errors and thread interference in multi-threaded programs. When a thread executes code within a synchronized statement, the object passed as a parameter is locked. When writing a synchronized block, the object providing the lock must be specified after the synchronized keyword: public class Rezha { private int sum; public void addToSum(int value) { synchronized(this) { sum += value; } } } In this example the object providing the lock is this, which is the instance of Rezha that the method is being called in....

April 7, 2017 · 1 min · Rezha Julio

Function in Python are First-Class Object

Python’s functions are first-class objects. You can assign them to variables, store them in data structures, pass them as arguments to other functions, and even return them as values from other functions. Grokking these concepts intuitively will make understanding advanced features in Python like lambdas and decorators (I will cover two this in the next post) much easier. It also puts you on a path towards functional programming techniques. In this post I’ll guide you through a number of examples to help you develop this intuitive understanding....

April 6, 2017 · 8 min · Rezha Julio

Django 1.11 Release Note a Reading

Django 1.11 is released for the world to use. It comes with a lot of changes, which can take some time to read. In this video, GoDjango read all of the release notes so you can just put on some headphones and hit play.

April 5, 2017 · 1 min · Rezha Julio

Skip Yaourt Prompts on Arch Linux

Yaourt is probably the best tool to automatically download and install packages from the Arch User Repository, also known as AUR. It’s really powerful; however, by default, it prompts you a LOT for confirmations of different things, such as checking if you want to install something, if you want to edit the PKGBUILD, etc. As a result, Yaourt is pretty annoying if you’re used to the hands-free nature of most other package managers....

April 4, 2017 · 1 min · Rezha Julio