Interface translation in symfony - tool for teams

July 16th, 2008 by Shyamal

I mentioned in my previous post how we decouple the translation dictionary completely from the source so that a change in any text does not affect the templates. That has helped us a lot in several large projects.

Another issue which we frequently encountered when multiple people worked on the same project is conflicting and merging of the dictionary files. Since these files have sequential numbers in each <trans-unit> block, if multiple people want to add translations, these suquential numbers almost overlap and have to be rewritten manually while checking in.

So we decided to generate these symfony interface translation dictionary files using a script. So here’s what we do:

  •  put the translations in a properties file: Create one properties file for each language. So for English we create “translations.en.properties”. This has translations like:

USERNAME_LABEL=Username
PASSWORD_LABEL=Password

This ensures that even when multiple people add translations to these files (using a source control like CVS or SVN) there are no issues.

  • Also put the following file createXML.php in the same i18b folder.   
  • Now you can simply call this script from the command prompt to generate the xml dictionary.

php createXML.php > messages.en.xml

That was pretty simple to do. There are some enhancements this requires, like it should by itself generate all translation files based on the properties files available. But thats for when i get more time to work on it.

Passwords in clear text

July 4th, 2008 by Shyamal

I just received a newsletter from a social network site (brijj.com) and was surprised how they had embedded my username and password in clear text. It speaks volumes on how seriously they take security. I think when storing passwords all sites should go by few rules:

  • Do not store passwords in cleartext. Never ever.
  • Use any encryption technology, preferable a 1-way hash so that nobody can decipher the password.
  • If you break the above rules, which several sites do, at least do not send out passwords in emails without being asked for. That’s the worst you can do.

Everyone should realize that people tend to use same passwords for several sites and accounts so sending out passwords in clear text not only compromises the user’s account at your site but possibly at other places as well.

Restoring monitor resolution on 17″ TFT

February 16th, 2008 by Ved

A lot of times I found my Acer 1702W 17″ TFT Monitor loosing its native resolution of 1400 X 900, which is ideal for the monitor to display the content properly. Even after doing a lot of search on various search engines I couldn’t find a method that guaranteed me results. Though I have an Intel Accelerated Graphics driver, I feel this solution should work for any card ATI, NVidia etc.

Follow the following steps in order to get back your monitor’s native resolution: -

1. From display settings, set screen resolution to higher resolution, I changed it to 1600 X 1024.
2. From your display driver installation CD, run setup application.
3. After the drivers are installed restart your computer.

This would bring back the native resolution for the monitor.

Date manipulation using GNU date

February 9th, 2008 by Amit

GNU date command lets you do just about everything related to date and time but date manipulation is something not well documented.

# get date 2 weeks from now
date –date “now 2 week”

# 2 months earlier
date –date “now -2 month”

you can give any date in place of ‘now’ or use a variable.

# what day is it after 10 days?
date –date “now 10 day” +%A

Interesting information from Google trends

October 27th, 2007 by Amit

I was waiting for our designer to show me some htmls so in the meantime I thought of ‘browsing’ Google Trends
I looked at the home page for couple of minutes thinking how can this be helpful, after looking at the listed examples first thing that caught my attention was “Tip: You can compare searches by separating with commas.” and I clicked on “music, fashion, sex“. Ok, so I saw a big graph and the searches per region. India was at number six but what was interesting to see was the orange bar. Indians are googling way more for word ’sex’ than anyone else in the world. It instantly made me think if searches on google are indication of people’s interest then I can find other interesting information for eg.
- Which country is most likely to be shopping online? Gift, shopping US, UK, Australia
- What sells more jewellery, clothes, flowers? - clothes.
- What about India? - Flowers. And guess what punjab is on the top.
- Which country might be having most Java programmers. India and Bangalore on top.
- Which is more common java, .net, php, ruby, python. Java wins by clear margin and again India and Bangalore
- Which place in India might have most struts programmers. Noida and Pune.
- Mysql more famous or postgreSQL Mysql
- Where are most people searching for jobs? India, UK
- Most Kerala people are looking for matrimonial sites.
- Some obvious ones India, Pakistan searches most on cricket and US, Canada on baseball

I couldn’t make sense to following searches.
- Why is India searching for India?
- Also ‘outsourcing’?
- What could this mean? startups

GlassFish Auto Deployment and Hot Deployment

October 23rd, 2007 by Amit

There are several ways to deploy a GlassFish application. To speed up development/debuging we need a way to instantly deploy web applications. One of the ways is to use hot deployment feature, another lesser known feature is ‘directory deployment’. You simply point GlassFish to your development directory and let it pick up and deploy application from there. No packaging and re-deoploying hassles. The catch is whenever you want to re-deploy your application you just need to ‘touch’ a file called ‘.reload’ which should be present in your web folder.
Following is the command and directory structure you can use.
–|myproj
–|–|src
–|–|web
–|–|–|WEB-INF
–|–|–|–lib
–|–|–|–classes
–|–|–|–web.xml
–|–|.reload

GLASS_FISH_HOME/bin/asadmin deploydir full_path_to_you_web_folder

If you are using Eclipse or NetBeans make sure that they put the class files in web-inf/class folder after compiling.

Evaluating / Comparing NetBeans and Eclipse EE for Java EE development

October 19th, 2007 by Amit

Although we are ‘big’ Eclipse fans and have been using it for many years for everything (PHP/symfony, Java, XUL, HTML) and have even contributed plugins but we decided to evaluate NetBeans to see if it gives any extra features that might help/speed up development for our forth coming Java EE project.
Technologies we are going to use in our application are:

Preferred IDE requirements:

  • CVS integration
  • Integration with GlassFish - so that we don’t have to leave the IDE to deploy etc
  • Should support debugging of web application
  • Support for profiling
  • XML/JSP editor
  • Context sensitive help and auto completion for tags

We are comparing
NetBeans 6 Beta 1 and Eclipse 3.3 Java EE

Creating a new web project is pretty straight forward. Both IDEs create more or less same directory structure only difference being the location where Java source files are stored. Eclipse keeps them under src where as NetBeans keeps them under src/java.
Next thing I wanted to do was import (share) my project to CVS. Found it more user friendly in Eclipse although NetBeans was equally straight forward.

JSP/XML Editor
NetBeans editor is lot more advance and friendly.
Editing Web.xml in Eclipse
Editing web.xml in NetBeans

Other differences
- In Netbeans you don’t have to click on ‘fast views’ just mouse over brings the window.

- Can’t easily change destination of compiled class files in NetBeans. We wanted to try directory deployment feature of GlassFish so that we don’t have to create .war every time, this required us to compile and put the class files in WEB-INF/class folder. This setting is pretty straight forward in Eclipse whereas you have to change projects.properties file in NetBeans. (Or it was not easy to find how to change it via UI)

- One of the biggest inconveniences was not having auto import while writing Java Code. Eclipse will auto import a class if you use it (Ctrl+space) but in NetBeans you have to manually add imports. There is fix imports also but thats an extra step.

- Eclipse UI in general is more user friendly. As an example ‘output console’ had a title bar and then some tabs. Each of these tabs are (or at least look) like individual windows with separate x (close) buttons. Its very natural to double click on the title to maximize it, hence you would try to double click on title ‘GlassFish v2′ but it will not do anything. You will have to double click on the bar above it ‘Output’. This is understandable but not ‘really’ as expected. On the other hand eclipse is pretty straight forward.
NetBeans console windowEclipse console window

- Eclipse kept on crashing (giving out of memory error) on my colleague’s laptop which has 1GB RAM, this happens when he tries to run GlassFish from Eclipse. Trying to run GF outside of Eclipse doesn’t crash it. This is actually a show stopper, or he needs to upgrade RAM

- I couldn’t figure out how to auto compile and auto deploy application on NetBeans. Every time you change a class file you need to ‘build’ and ‘run’ or ‘deploy’ on the other hand Eclipse will compile and deploy automatically on save. On the other hand auto deploying can also become a problem when application size grows. But this made it very smooth on Eclipse to build/test.

We also evaluated how to create a project so that it can be opened in both the IDEs so that we can either switch or let programmers choose whatever they want. There was no ‘huge’ difference of features or one IDE helping a LOT. On the other hand as we are comfortable with Eclipse shifting on NetBeans can be counter productive as we have to learn/get used to the new IDE. We know that we will need NetBeans for debugging and profiling but development will be faster with Eclipse using directory deploy and .reload feature of GlassFish.

Visualizr - Yahoo! Open Hack Day Bangalore, India

October 9th, 2007 by Amit

Over the weekend we went to the open yahoo! hack day at Bangalore ….and what……

Hack Day - visualizr

Here are the ideas we thought of

  1. A service which will take your favorite blogs, your linked in profile or/and your favorite articles as input and create a mash-up of articles you might be interested in from Amazon or images from flickr or events from upcoming. Will also try to make a guess as to what kind of person you are.
  2. Visualizr, what we initially called as pic-story and the one we finally built.
  3. Travel Helper - Give us your travel dates and cities you are visiting and we will tell you what are the events happening during that time on those places and we will also show you interesting pictures from flickr taken in those cities so that you can decide what you want to do if you have free time.
  4. Tell us what you want to buy and we will give you all the relevant information. for e.g. items from different shopping sites, review sites, news, flickr etc
  5. Pictorial how to? Give us step by step procedure of creating or doing anything and we will return the same how with pictures to understand better.

Creating visualizr was fun and we really like the idea as it could actually be applied in lots of things like

  • Make your own cards
  • Build an ad campaign
  • With more comprehensive image access a new way of communication
  • Evolve as a How to tool? Ask 10 questions and see how Images can answer for you
  • May give a whole new way of learning difficult concepts
  • Or just brighten up your day

So what are you waiting for, go check it out visualizr

STPI incubation facility in Bangalore

September 19th, 2007 by Shyamal

We recently came to know about the incubation facility that STPI provides to new startups looking for a cost effective and worry free infrastructure. This is really suitable for new units who have not invested in their existing infrastructure and plan to get their own office (leased/owned) in a year’s time. Apart from the infrastructure they also help with HR, legal and accounting functions at extra cost.

It did not turn out suitable for us since we have already invested in our own infrastructure. But had we been aware of this facility when we started, we would have definitely opted for it.

You can contact Remali.R at STPI Bangalore for further information.

Recovering database from MySQL 4.x

August 31st, 2007 by Ved

Recently I was involved with a task to recover a database on MySQL 4.x that crashed. Below are the steps that I did to recover the database. The commands in this post are available on MySQL 4.x, if you are on MySQL version higher than this then check MySQL 5.x

1. The MYI file of the database was corrupted and I could find out that by trying to select rows from one of the tables. The error message returned for the select query - ERROR 1016 (HY000): Can’t open file: ‘TABLE.MYI’ (errno: 144).

2. Next step was to run myisamchk for which I should shut down the database first by issuing command “mysqladmin -u root shutdown” at the command prompt

3. First I tried using the –quick option on the database to rebuild the index only
/pathtomysqlexecutablefiles/myisamchk –quick /pathtodatabase/*.MYI [ to repair all the tables use wildcard (*) ], the command executed successfully, and displayed the repair information.

4. I again started mysql server using command “mysqld &”

5. Logged in to mysql prompt and selected the repaired database. To know the status of the tables after repair I executed “show table status” on the mysql prompt.

6. The results displayed error “Incorrect information in file: ‘./database/TABLE.frm” which means the frm file of the database got corrupted. Searching for the same on the web I found if we run an extended check using myisamchk may solve this problem for which I had to go to step 2.

7. There are few checks one should do if step 3 cannot help you recover the database, and after every check repeat steps 4 - 6 in the same order. You would know your table is recovered when “show table status” shows no errors, and to confirm this further you should be able to select rows from the table.

a) /pathtomysqlexecutablefiles/myisamchk –force –fast -c -i -r /pathtodatabase/*.MYI
b) /pathtomysqlexecutablefiles/myisamchk –force –fast -c -i -o /pathtodatabase/*.MYI
c) /pathtomysqlexecutablefiles/myisamchk –force –fast –update-state -i -r -e /pathtodatabase/*.MYI

if it gives error - myisamchk: error: Not enough memory for blob at 1940 (need 1890777748) (1.7GB thats wierd)
but if you think your table may be holding that much of data and your server has huge memory you may use
d) /pathtomysqlexecutablefiles/myisamchk –fast –update-state -i -o -e -O key_buffer_size=2048M -O read_buffer_size=2048M -O write_buffer_size=2048M /pathtodatabase/*.MYI
Thats giving 2 GB of memory to myisamchk for processing!
If you want to know more about visit : myisamchk Memory Usage

If the error about memory persists, it means there has been serious damage to the database. Same was the case with my database, these are the steps for recovering in such scenario:
a) Recreate a database on local MySQL server.
b) Recreate all the tables with similar schema as it is on the web server
c) Stop local MySQL server
d) Copy frm and MYD to the local computer at the same place where your newly created database exists with its (frm, MYI and, MYD) files.
e) Execute myisamchk –quick /path/to/datadir/*.MYI (One can also use REPAIR TABLE command from mysql prompt)
f) Restart MySQL Server and try selecting rows from the tables.