Wednesday, August 14, 2013

Distributed Semaphore (Lock) with memcached

Hi, today I want to show a simple technique how to build a synchronization primitive when you have compare-and-swap operation (in fact you can apply those technique to Mongo or Zokeeper and get the semaphore backed by Mongo or ZooKeeper, actually I really like ZK-based locks and semaphores since there is a built-in notification for value changes).
!!! Note, that the code I provide is just for demonstration purposes it's not production-ready. Please do not use these distributed semaphores as is.

Wednesday, August 7, 2013

Recursively resize images

A couple of days ago I was trying to share my photos to my relatives. The thing is that there was 25Gb of photos and there was a bunch of nested folders in my photo collection. I didn't want to share the photos in such a high resolution and that was a problem #1. Admittedly I did have a image converter that could be used as image resizer but it only worked with one folder, completely ignoring the nested, so there was a problem #2.

I decided to create a simple image resizer that could recursively traverse through nested folders and resize the images. As usual, sources and binary (github). Note that You need JRE to run the recursive image resizer.

I should say I find that utility pretty useful (at least for me :)
  1. The first good thing is that you invoke it with SOURCE_DIR and DESTINATION_DIR parameters and it creates 100% identical copy of SOURCE_DIR, resizes the images and places them in the same place (ralative to source dir). 
  2. The second good thing is that it utilizes mutiple CPU's of your machine, so, hopefully it the recursive conversion of your images should complete faster. 

The usage of  recursive image resizer is simple, just run to get help:
java -Xmx1024m -jar image-resize-app.jar

I'll give you a simple example:
java -Xmx1024m -jar image-resize-app.jar -r 1920,1440 /home/username/photos /home/username/photos_resized

Friday, August 2, 2013

Learn Hibernate By Example

Hey, I should say I'm a very big fan of learning by example. The thing is, once you have a solid background you don't need words to be said: the code tells everything. So I've added a couple of projects which are dedicated to Hibernate and related stuff. And as always github: hibernate-samples and hibernate-ehcache. All the examples are implemented as JUnit tests.