Multiple DefaultCommand in a form using different scopes in PrimeFaces

DefaultCommand in PrimeFaces is for specifying which clickable command in a form to trigger when ENTER key is pressed on an input in the form. It is especially useful when there are multiple commands in the form. Suppose that we have two Dialog in a form, and each has some inputs and a command button. Then two DefaultCommand can be defined so that when ENTER key is pressed on the inputs of either Dialog, the corresponding command button is triggered. If no DefaultCommand were defined, the first button with the type submit would always be triggered in most browsers.

Memory leak in X process in Fedora 19 KDE

Fedora 19 KDE looks really beautiful on my laptop with the 1080p screen, but I have been really pissed off by the memory leak coming with the beautifulness. Specifically, the X process can consume up to 50% of my total memory within 3 hours when I regularly use Chrome, Eclipse, MySQL Workbench, etc. It is equivalent to 3GB of memory, and could be even larger. But before that happens, I usually already have restarted the system because everything has been so slow.

Is a javax.persistence.EntityManager thread safe to be an instance variable?

In a JPA based DAO class, we usually declare an EntityManager as an instance variable annotated with @PersistenceContext, and use it in the methods of the class. This usage seems to work fine and I just accepted it without further thinking. But recently it turned into a question when I was working on some JPA code that, how could an entity manager be thread safe as an instance variable, while an entity manager does not seem to be meant for sharing among multiple threads?

Reading Java Message Service by Mark Richards et al., O'Reilly (2009)

Messaging systems allow you to loosely couple heterogeneous systems together with added reliability. Java Messaging Service (JMS) providers use a system of transactions, to commit or roll back changes atomically. Unlike systems based on a Remote Procedure Call (RPC) pattern, messaging systems primarily use an asynchronous message passing pattern with no tight relationship between requests and responses. Most messaging systems also support a request-response mode but this is not a primary feature of messaging systems.

An exercise on binomial coefficient identities

Recently, I received an email asking how I got the closed form of a summation in one of my publications. I checked my archive and did not find the calculation back then. Here I do it again, so I will have it.

Multiple avro output files with Hadoop streaming api

Mappers and reducers using Hadoop streaming api generally have no direct control on how many output files to generate in Hadoop Distributed File System (HDFS). Although it is possible to open Hadoop subprocesses to write to HDFS during mapping and reducing, it may be easier and safer to write an output format in Java that outputs multiple files. Here is an example output format that outputs multiple avro files.

Resolving ix4-300d being stuck at 0% of RAID reconstruction with 4 drives

Lenovo ix4-300d is a cost-effective 4-bay network attached storage (NAS) for home use. It does not support hot swapping, but offers otherwise most commonly used NAS features. I have 4 3TB Western Digital Red drives running a RAID-5 array with it now, but when I first put the drives in, I did come across some gotchas.

Python 2 pyliblzma based decompressing wrapper for lzma/xz streams

The lzma.LZMAFile class from pyliblzma for Python 2 can only construct from file paths, but not from file-like objects which support read() or write() operation. If you have an object representing an lzma/xz stream in Python 2 and you want to decompress from it in a streamed fashion, here is an example implementation using the lzma.LZMADecompressor class also from pyliblzma.

Breaking a thread coordinating cyclic barrier

A CyclicBarrier is a synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point. Suppose that in a test, there is a Runnable which needs to be executed by multilpe threads at the same time for multiple rounds. Then the beginning and ending for each round can be coordinated by a CyclicBarrier that a manager thread can signal the beginning of a round to all the worker threads, and wait until all the worker threads finish to end the round. The beginning and ending can then happen for more rounds.

Walking around compilation failure on enums implementing interfaces

If an enum implements an interface, and methods from the interface are called on an instance of the enum, the enum instance needs to be referenced as the interface, or the interface is somehow referenced in the context where the methods are called; Otherwise, there is possible compilation failure in a Maven build complaining about "cannot find symbol" on the interface methods being called.