Tuesday, March 4, 2014

How to convert Integer into String with leading zeros in Java

This is pretty easy task, but I keep on forgetting it:
String.format("%05d", num);

Tuesday, February 18, 2014

Batch Resize Images in Mac OS

To resize all the images to maximum height of 640px
sips -Z 640 *.jpg
To resize all the images to maximum width of 400px
sips --resampleWidth 400 *.jpg

To resize SVG files in Mac OS, you can use the rsvg library install it with:
brew install -v librsvg
and then run it with the following shell line:
for i in *; do rsvg-convert $i -w 100 -h 100 -f svg -o `echo new/$i`; done
This takes all the svg files in the folder, resizes it and copies the result into new/ folder

Thursday, February 13, 2014

jBPM bpmn designer validation errors

Ok, you must agree with me on this one. It is not nice to develop in environment where you get an errors on unknown location. Well, errors are fine, it is part of software development, but when you are not able to see any details of where the error comes from, it gets to waste enormous amount of time to dig out why such error happens.

I got such errors when I try to use jBPM eclipse environment to try implementing BPM process using an external bpmn file. Since bpm is created in one of those graphical eye-candy oriented BPM modelling software (with little or no support for bpmn validation), I could imagine there are some  pieces (details) missing within bpmn.

No Interface found - According to BPMN standard, every Service Task needs to be defined with a proper service operations. If such is not defined for any of the service tasks within your bpm file, you will get this error.

No Item definitions found - tbd.

If I come up to some more of these errors, I will add them here...

Resize of svg icons from command line

This post would probably only useful to me, but, it is possible to change the size of svg files using XSLT (why would one need to change size of vector graphics??? Well, there are cases where there are no means to scale the images)

I had a bunch of files which I needed to resize into a proper size (in my case, 16px x 16px icons), and was looking for a easy solution. Since I knew svg is xml-based vector graphics, I was hoping to find example similar to

I used the xsl file from the post on https://www.ruby-forum.com/topic/166757#732031, with adding the 16x16px as a target scale.
Command line to run:
xsltproc --stringparam scale 2.5 bigger.xsl in.svg >out.svg
<?xml version="1.0"?>
<!-- bigger.xsl $Id$
     Author: Terry Brown
     Created: Thu Sep 25 2008
<xsl:stylesheet version="1.0"
  <xsl:output method="xml"/>
  <xsl:template match="svg:svg">
    <xsl:copy>  <!-- copying the svg element -->
      <xsl:copy-of select="svg:metadata|svg:defs|sodipodi:namedview"/>
      <xsl:element name="svg:g">
 <xsl:attribute name="transform">
   <xsl:value-of select="concat(concat('scale(',$scale),')')"/>

Thanks Terry Brown!  

Wednesday, February 12, 2014

Create a new Custom Form Field in Vaadin

I am writing this post because of multiple solutions shown on web, which due to multiple drastic implementational changes during Vaadin development (most notably Vaadin 6 to Vaadin 7).

How to create a new custom form field, so that it can easily be integrated into FormLayout.

Simplest way so far is to extend CustomField class.

Here is the example
import com.vaadin.ui.AbstractField;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.CustomField;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Button.ClickEvent;

public class ExampleCustomField extends CustomField<String> {
    private static final long serialVersionUID = 8376102707918932019L; 
    private static final String = "Default Text";
    private TextField field;
    private Button delButton=new Button("Reset");
    private HorizontalLayout layout=new HorizontalLayout();

    public ExampleCustomField() {

        delButton.addClickListener(new Button.ClickListener() {
            private static final long serialVersionUID = -5711434206619225940L;

            public void buttonClick(ClickEvent event) {
                    .show("Reset Button pressed");

    public String getValue(){
        return field.getValue();
    public Object getType() {
        return field.getType();

    protected Component initContent() {
        return layout;

Thursday, July 11, 2013

Exporting Skype Chat/Skype Contacts to csv file using the shell script and sqlite3 (usually already installed on mac)

I heard there are not so many nice ways to get the chat history from skype, so I came across a page of one guy who shows a way to open the sql chat history database and delete all conversations. I thought to make something more from that idea (as delete chat history is now one of the options in skype)

Create a file exportFromSkype.sh
place either this text:
sqlite3 -batch "$HOME/Library/Application Support/Skype/$1/main.db" <<EOF
.mode csv
.output $2.csv
select * from Messages where dialog_partner = '$2';
.output stdout
now make the script executable by running

chmod +x exportFromSkype.sh
now, when you want to export some chat history from certain person, you can do it by:

sh exportFromSkype.sh your_skype_name your_friends_skype_name

and it will create a csv file with name persons_skype_name.csv in the same folder where the script is placed.

You can also modify the script, and use for example as a sql query other tables, like:

sqlite3 -batch "$HOME/Library/Application Support/Skype/$1/main.db" <<EOF
.mode csv
.output contacts.csv

select * from Contacts;
.output stdout
 This will give you whole list of Contacts in csv file. when you run it as:
sh exportFromSkype.sh your_skype_name

A bit more step-by-step instruction I wrote in this post

Edit: In case you want to get the exact time-date export, I suggest changing the "select ..." line with the following one:
select author,dialog_partner,datetime(timestamp, 'unixepoch', 'localtime'),body_xml from Messages where dialog_partner = '$2';

Tuesday, June 4, 2013

Printing out all fields of an object

Often when debugging the printed Object has just the hash number (like Object@h43a356).
The following static method uses reflections to print out all fields:

builder.ToStringBuilder.reflectionToString(object, ToStringStyle.MULTI_LINE_STYLE);