Skip to content

String Phobia in Software Development

String phobia in software development is different from the medical condition of Linonophobia!
It is when teams or individuals do not use strings and want to replace every constant with enums.
Probably using enums is acceptable if they will not really change; for example “days of the week” but if they keep changing and the component has dependencies that are affected by this change then I see no point in using enums. This is very annoying in enterprise environments where a component has a number of dependencies and a change will affect multiple silos.
The clients on the other hand can convert these string to enums if they want to.
SOA Cook Book says:
Keep the types in the canonical schemas somewhat flexible and general, as they will potentially need to absorb a variety of service entity definitions. For example, it’s probably fine to use an enumeration in a service schema, but use a string to represent that same type in a canonical schema. It is surprising how little we can actually agree on. Maybe your USState enumeration has 50 items, but maybe the enum in the schema of the service you need to integrate with includes Guam and Puerto Rico.
Aside

Learn Persian New Year (Norooz) Rituals!

2

Norooz (Nowruz), in word, means “New Day”. It is the exact astronomical beginning of the spring in the northern hemisphere (note3). It usually falls on 20 or 21th of March.

This ancient festival is celebrated and observed by many people in Asia and Middle East, even in North-western China and Balkan.

Iranians take that as the beginning of the year. This exact second is called “Saal Tahvil” meaning “Year Delivered”. Norooz (Nowruz) with its unique Iranian characteristics has been celebrated for at least 3,000 years and is deeply rooted in the rituals and traditions of the Zoroastrians (The religion of ancient Persia).

Iranians consider Nowruz as their biggest celebration of the year which includes a few days of public holiday and sometimes up to 2 weeks for schools.

Major New Year rituals include:

  • Cleaning the house (Khaane Tekaani – meaning home cleaning) before the New Year and buying new clothes!
  • Setting a special table (Haft Seen – meaning seven ‘S’) before the New Year. This table has 7 specific items on it starting with ‘S’ in Farsi (Persian language).
  • Fire Festival (“Chahar-shanbe Suri” – meaning feast of Wednesday) the night before the last Wednesday of the old year is celebrated by going into the streets to make bonfires, and jump over them.
  • The New Year moment (Saal Tahvil – meaning year delivered) is celebrated by music and kisses.
  • Parties and family gatherings after New Year
  • 13th day (Sizdah Bedar – meaning 13th day out) 13 days after the New Year is the outdoor and picnic day.

Now I explain these in short.

Haft Seen (7 Seen) Table:

3

A special table laid with seven specific items on it. All the 7 (Haft in Farsi) items start with the letter “S” in Farsi. These seven things usually are:

  • sabzeh – wheat, barley or lentil sprouts growing in a dish – symbolizing rebirth
  • samanu – a sweet pudding made from wheat– symbolizing affluence
  • senjed – the dried fruit of the oleaster tree – symbolizing love
  • sir – garlic – symbolizing medicine
  • sib – apples – symbolizing beauty and health
  • somaq – sumac berries – symbolizing the colour of sunrise
  • serkeh – vinegar – symbolizing age and patience

Other items on the table may include:

  • sekkeh – Coins – representative of wealth
  • lit candles – symbolizing enlightenment and happiness
  • Mirror – symbolizing cleanness and honesty
  • Decorated eggs, one for each member of the family – symbolizing fertility
  • A bowl of water with goldfish – symbolizing life
  • Traditional Iranian pastries and sweets
  • Dried nuts, berries and raisins
  • A holy book (Avesta, Quran, and/or a poetry book, Shahnameh or the book of Hafez)

Decorated with colourful ribbons, the 7 Seen table is kept for 13 days and then disposed outdoors.

4

The New Year Moment:

People usually listen to radio or television at the moment of year change (saal tahvil) which is identified by a countdown or a cannon blast after which people hug and kiss each other and wish each other a happy new year.

Then they give presents to each other (traditionally cash, coins or gold coins), usually older ones to the younger ones. The first few days are spent visiting older members of the family, relatives and friends. Children receive presents and sweets. Traditionally on the night before or after the New Year, most Iranians will have a special dish of fish and rice (Sabzi Polo Mahi).

6 7

13th Day:

The 13th day of the New Year is called “Sizdah Bedar” meaning 13th day out and spent mostly outdoors. People go to the parks and the nature for a festive picnic. Also in this day, people throw the Sabze (the seeds grown in Haft Seen table) away.

Old Iranian culture regard number 13 as a bad omen and believe that by going out they avoid misfortunes.

Fire Festival:

5

Another tradition before the New Year is “Chahar-Shanbe Suri”. It takes place at the night before the last Wednesday of the old year. People set up bon fires, young and old leap over the fires and sing special songs.

This festival is the celebration of the light (the good) winning over the darkness (the bad).

Notes:

  1. More information can be found at: http://en.wikipedia.org/wiki/Nowruz
  2. Countdown to the New Year moment: http://www.7seen.com/
  3. For Persian calendar see KhayyamHejri Calendar and Jalali Calendar
  4. Photos in this page link to their original location

Hibernate Filters

This is one way of writing a Hibernate filter. We have to define a filter first using @FilterDef as a global annotation, meaning that it can be applied anywhere in the code.

Then we apply the filter to where ever we want using @Filter and then we need to enable the filter in the session.

The reason for the filter is that when I do A.getstateTransitions() I want the list of B’s returned to be filtered.

@FilterDef(name=”myfilter”, defaultCondition=”TRANSITION_DATE > trunc (sysdate)”)

class A{

@OneToMany(…)
@Filter(name=”myfilter”)
private List<B> stateTransitions;

}

class B{

@NotNull
@Column (name=”TRANSITION_DATE”, columnDefinition=”DATE”)
private Calendar transitionDate;

}

Using:

org.hibernate.Session session = (Session) entityManager.getDelegate();
session.enableFilter(“myfilter”);
query.getResultList() // returns list of A’s where B.stateTransitions are after now.

Filters can have parameters but I didn’t need one here.

Build Light

A build light is rather a new (?) thing teams do to indicate their software build/test status. It has become very common in Agile teams. I did one for our project although not entirely Agile but it indicates the status of our builds being made in our in-house build server.

Read more about it in wikipedia: http://en.wikipedia.org/wiki/Build_light_indicator

I purchased the light from http://www.delcomproducts.com which sells them very expensive! A USB RGY LED light (http://www.delcomproducts.com/productdetails.asp?productnum=904007)  costed me (our project) around 120 AUD to reach Sydney from US! Quite an expensive light!

If you are into electronics you should be able to make one easily I suppose. I am not really a hardware person and also have no time for it.

Anyway the light arrived quickly with no documents attached but everything can be found online. In Windows there is a command line application “USBCMDAP.exe” that can quickly turn it on:

USBCMDAP.exe 0 0 101 12 1 0 #green on
USBCMDAP.exe 0 0 101 12 2 0 #red on
USBCMDAP.exe 0 0 101 12 0 3 # all off

my build light

Now all you need to do is to read the status of your build/test/project/whatever and turn this on/off accordingly.

There are drivers for different OSes and hardware information in their website if you want to get more serious.

If you found a similar light but cheaper (together with software) then let me know!

Starting with Fabric

Fabric is a Python module for system administrations. It can be considered a tiny Puppet. I needed to gather some info about remote servers, etc without installing an application and I was looking for a Python one that I found this. See more information on fabfile.org.

It is very nice for Python lovers as you can write your scripts in Python…

It is almost well documented but the problem I had with its HelloWorld was that it failed at the first run in Solaris which was annoying (see below why)

Anyway, These are the points I found the hard way. They either were not in the documentation or were deep hidden:

  • By default run() method calls “bash -l -c” to execute commands. In Solaris there is no -l so you need to change this default by setting: env.shell = ‘/bin/bash -c’
  • Default script file name should be fabfile.py and run it with the fab command.
  • List of host names can be set in env.hosts=[…] as a list or passed in to a method using @hosts([…]) annotation
  • Not sure if we can use a jumpbox (tunnel through) in version 1.4. It seems available on 1.5 that I haven’t installed yet. My requirement is for A to ssh to C where the connection is through B as A can only connect to B and B can ssh to C and A cannot directly ssh to C (A->B->C)
  • fabric module depends on ssh and crypto modules to name a few.
  • You hide execution and outputs by:

fabric.state.output[‘running’] = False
fabric.state.output[‘stdout’] = False

In 1.5 you can use hide() method. There is a bug on hide() in 1.4.

My RaspberryPi

My RaspberryPi

This is my latest toy. Although it is one of the cheapest but one of the most interesting ones!

I bought is from au.element14.com in Australia and ordered a case off ebay that I broke while putting it together! It was one of the transparent ones and very fragile. You do not really need a case for it.

I will not go into details of how to set this up as you can find a lot of info on the web.

Just a few notes:

  • For me copying the image to SD took about 10 minutes.
  • Power is through the USB port of my router
  • The desktop Linux is quite responsive but do not expect much from it
  • I enabled ssh and connect to it only remotely. Lynx browser is of some help sometimes !

I am planning to use it as a proxy/firewall in front of my router so currently installing a proxy server into it. I will try to use GPIO ports in the future.

JPA Composite Primary Key

Here is an example of a composite primary key object for Hibernate/ JPA. It makes things more complicated by creating a relation from one of the pk fields to another entity. If we didn’t have this extra relation then the inner class would have another simple @Column instead.


@Entity
@Table(name="MY_TABLE" )
public class Test implements Serializable, Validatable
{
	public Test(){}

	@Id
	PK id;

        //other fields
	
	@Embeddable
	public static class PK implements Serializable{
		public PK (){}
		
		@Column (name="PK_1")
		private Long pk1;
		
		@ManyToOne(fetch=FetchType.EAGER,optional=false)
	    @JoinColumn(name="PK_2")
		private AnotherEntity ent;

		public boolean equals(Object obj) {
	        if (obj == this) return true;
	        if (obj == null) return false;
	        if (!(obj instanceof PK )) return false;
	        PK pk = (PK) obj;
	        if (pk.ent == null && pk.pk1 == null) return false;
	        return new EqualsBuilder().append(pk1, pk.pk1).append( ent, pk.ent).isEquals();
	    }

	    public int hashCode() {
	    	return new HashCodeBuilder().append(pk1).append(ent).toHashCode(); 
	    }	

		//getter/setter
	}

	//getter/setter

}