Friday, December 31, 2010

Android's Process != Application ???

Still trying to understand the statements ... "Internally, each user interface screen is represented by an Activity class. Each activity has its own life cycle. An application is one or more activities plus a Linux process to contain them.
In Android, an application can be “alive” even if its process has been killed. Put another way, the activity life cycle is not tied to the process life cycle. Processes are just disposable containers for activities." (Hello Android 3rd edition p.35)

Tuesday, December 21, 2010

How to take care of your leather seats ?

Use hair dryer to remove wrinkles from leather seat.
1. Wipe down the leather seat with mild soap and water or a specifically formulated leather cleaner. Use the cloth to rinse and dry the leather seat so that no soap or cleaner residue remains on the surface of the leather.

2. Inspect the leather seats and find all the places that have wrinkles.

3. Turn on the hair blow dryer to its hottest, strongest setting.

4. Position the end of the dryer eight to 10 inches away from the wrinkled leather surface. Move the end back and forth so that the hot air from the dryer is not hitting a single portion of the leather for too long. This prevents the dryer from burning the leather.

5. Wait for the wrinkles to disappear. The heat from the hot air in the dryer will gradually shrink the leather, tightening its surface and effectively removing the wrinkles. Hair blow dryers operate at a lower temperature than the professional heat guns that are typically used to remove leather wrinkles. As a result, it might be several minutes before the wrinkles are completely gone.

6. Apply a light coat of premium leather conditioner and work it into the surface of the leather. This helps to protect the leather from the environment, and it might prevent or minimize future wrinkles. Buff lightly with a cloth. A high-quality leather conditioner might cost slightly more than some other brands, but it has less wax and can extend the life of your leather. Popular leather conditioners include Mothers Leather Conditioner and Meguiar's Gold Class Rich Leather Cleaner and Conditioner. Such products may be purchased at your local automotive store or online.

How to generate a thread dump ?

Generating a Thread Dump
Windows
The Java application that you want to produce a thread dump for must be running / started in a command console. When you want to produce a thread dump press Ctrl-Break
Note: it's easier to produce a thread dump on Linux as the JVM doesn't need to be started in a console window.
Linux
If the JVM is running in a console then simply press Ctrl-\.
If the JVM is running in the background then send it the QUIT signal:kill -QUIT process_id

Note: the thread dump will show on the console where the to-be-kill process is running on, not the console where you issue the kill command.

Thursday, December 9, 2010

Using yum to install packages locally

# yum localinstall /media/disk/Fedora/Packages/gftp-*
(If DVD is mounted on /media/disk)

Linux tips

> ls -l | grep -v total | awk '{ S+=$5} END { print "Total = ",S, ", Average = ", S/NR, ", Entries = ", NR, ", Columnss = ", NF}'
Total = 70238 , Average = 4389.88 , Entries = 16 , Columnss = 9
================================================================
> x=2008
> y=1957
> echo "$[$x - $y]"
51
> echo "$(($x - $y))"
51

================================================================
> gunzip < /usr/share/man/man8/vgrename.8.gz | nroff -man less

================================================================
> for i in `find /usr/home -name '*.jar'`
> do
> jar tvf $i | grep Something 2>/dev/null
> if [ $? -eq 0 ]; then
> echo $i
> fi
> done

================================================================
> groovy -e "System.env.each { println it }"
> groovy -e "System.props.each { println it }"

How to find the locking order for equals() ?

Always lock them in the same order, one way you could decide the order is on the results of System.identityHashCode(Object)

References:
http://stackoverflow.com/questions/1636399/correctly-synchronizing-equals-in-java
http://download.oracle.com/javase/tutorial/essential/concurrency/atomic.html


Never abruptly exit a finally block

Every finally block should complete normally, barring an unchecked exception.
Never exit a finally block with a return, break, continue, or throw, and never allow a checked exception to propagate our of a finally block.
When both try block and the finally block complete abruptly, the reason for the abrupt completion in the try block is discarded. Discarding the reason for abrupt completion is almost never what you want ... (Java Puzzlers p.78)


References:
http://accu.org/index.php/journals/236 (handle checked exception in finally block)
http://www.javamex.com/tutorials/exceptions/exceptions_finally.shtml
http://www.javamex.com/tutorials/exceptions/exceptions_hierarchy.shtml

Wednesday, December 8, 2010

Install VLC on CentOS

If you are not able to install VLC through command "yum install vlc" then most likely you have to enable the RPMForge repository by following the instructions provided by the link here

p.s. RPMforge is a collaboration of Dag and other packagers. They provide over 5000 packages for CentOS, including wine, vlc, mplayer, xmms-mp3, and other popular media tools. It is not part of Red Hat or CentOS but is designed to work with those distributions.

Java volatile vs. synchronized

If volatile already synchronizes data across threads, what is synchronized for? Well there are two differences. Firstly synchronized obtains and releases locks on monitors which can force only one thread at a time to execute a code block, if both threads use the same monitor (effectively the same object lock). That's the fairly well known aspect to synchronized. But synchronized also synchronizes memory. In fact synchronized synchronizes the whole of thread memory with "main" memory.

volatile only synchronizes the value of one variable between thread memory and "main" memory, synchronized synchronizes the value of all variables between thread memory and "main" memory, and locks and releases a monitor to boot. Clearly synchronized is likely to have more overhead than volatile.

volatile:
- Get a global lock on the variable
- Update the one variable from main memory
- Write any change of the one variable back to main memory
- Release the lock

synchronized:
- Get a global lock on the monitor
- Update all shared variables that have been accessed from main memory
- Process some statements
- Write all shared variables that have been changed back to main memory
- Release the lock


reference: http://www.javaperformancetuning.com/news/qotm051.shtml

Saturday, December 4, 2010

How to record/replay X events

Download xnee 2.05
> cnee --record --mouse --keyboard --out-file mouse-keyboard-events.xnl
> cnee --replay --file mouse-keyboard-events.xnl

Run shell script through keybinding

Press Ctrl+Alt+Insert to start an Xterm running the 'top' command, and press Ctrl+Alt+Delete to kill it:
gconftool-2 -t str --set /desktop/gnome/keybindings/custom1/name "Start top command"
gconftool-2 -t str --set /desktop/gnome/keybindings/custom1/binding "Insert"
gconftool-2 -t str --set /desktop/gnome/keybindings/custom1/action "xterm -e /usr/bin/top"

gconftool-2 -t str --set /desktop/gnome/keybindings/custom2/name "Stop top command"
gconftool-2 -t str --set /desktop/gnome/keybindings/custom2/binding "Delete"
gconftool-2 -t str --set /desktop/gnome/keybindings/custom2/action "xterm -e kill -9 $(ps aux grep top grep -v grep)"