Wednesday, December 24, 2008

Management Style

"If employees just did what they were told to do, you would continually find defects at the end of the line. We want employees to go beyond what they are told and be creative, building quality into the process." - Mitsuo Kinoshita (Toyota)


I have learned about this for the first time in U.S. Marines c.1995 during Total Quality Management training based on Japanese Kaizen. The young Marine leaders were trained to make independend decisions in case of the interruption of the chain-of-command (death of the superiors) in order to be able to function in chaos of battle, conflicting reports and lack of communication with the outside world.

I modern company it means that the manager is serving as a mentor and instructor that constantly makes the employee responsible for planning, sharing knowledge and executing of the tasks. The manager should faciliate the communications, continous quality improvement, cut the bureaucratic "fat" and inefficiencies (BS). Manager should empower the employees to act and grow, not just do their jobs.

While "running a thight ship" the manager(captain) should strive to achieve a command where each member of the team comes forward with ideas, takes pride and responsibility in the work, grows and learns, transfers knowledge to others and is able to take charge when called upon.

Happy New Year 2009!

Tuesday, December 23, 2008

Quality improvement (Toyota example)

To understand current situation I have been re-reading a book on Toyota's quality process. I found many thoughts that can apply to programming directly.

"Something is wrong if we do not look around each day, find things that are wrong, unclear, tedious or repetitive, and then rewrite the procedures." - paraphresing Taiichi Ohno (Toyota)


One of the recent changes on our way of software development is to de-emphesize the rush for new features in order to ensure the quality of the delivered product.

When we propose a new product (QA build) we STOP new development until all problems are resolved and the application is trully polished, unit tested and documented. We involve our clients in QA process.

Only when problems are resolved we can provide product for UAT (user acceptance testing) and production deployment.

Only when everyone is absolutely happy with the features they delivered we start PLANNING the new development.

While in planning phase, we listen to the user feedback and fix any problems we missed, code at this point is still the same as UAT.

This is: fix problems first policy.

Once a stable product backed up by a suite of regression tests (Selenium) and delivered to the users, we go into a phase of intense development of new features.

The philosophy here is to continously deliver new, solid features that fully satisfy the client. Quality vs. poor quantity.  Having less features hardly ever breaks the deal, having production problems always does.

Monday, December 22, 2008

Gilead: PersistentRemoteService

Gilead does merge operations when you made a service call using PersistentRemoteService, before with hibernate4gwt it didn't do it on all service calls. So we had this nice error

[WARN] StandardContext[]Exception while dispatching incoming RPC call
java.lang.NullPointerException: null
at net.sf.gilead.core.PersistentBeanManager.mergePojo(PersistentBeanManager.java:423)
at net.sf.gilead.core.PersistentBeanManager.merge(PersistentBeanManager.java:289)
at net.sf.gilead.gwt.GileadRPCHelper.parseInputParameters(GileadRPCHelper.java:89)
at net.sf.gilead.gwt.PersistentRemoteService.processCall(PersistentRemoteService.java:147)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:86)

So if you don't use spring to create your PersistentRemoteServices, then you have to include these 2 lines in the constructor of all your services.

XmlBeanFactory application = ApplicationContextFactory.getXmlBeanFactoryInstance();
setBeanManager((PersistentBeanManager) application.getBean("hibernateBeanManager"));

Friday, December 19, 2008

Spring beans: ApplicationContextFactory

This code snipped shows you how to get a bean from the applicationContext.xml

<bean id="statusDao" parent="baseTransactionProxy">
<property name="target">
<bean class="com.xyz">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</property>
</bean>


package com.xyz;

import org.springframework.beans.factory.xml.XmlBeanFactory;

public class Xyz
{
    public static void main(String[] args)
    {
XmlBeanFactory beans = ApplicationContextFactory.getXmlBeanFactoryInstance();
                   setBeanManager((PersistentBeanManager) application.getBean("hibernateBeanManager"));
        StatusDao statusDao = (StatusDao) beans.getBean("statusDao");

Status status = statusDao.fetch(new Long(1));
System.out.print(status.getEntity());
    }
}

Wednesday, December 17, 2008

Mac: resetting system and user password

Recently I had to research how to recover my system password on my Mac, I was not thrilled with my findings. With a quick Internet browsing, I discovered that one can reset a Mac system password with the operating system CD, which is provided with any Mac purchase as well as stores like Apple, BestBuy, etc. 

I had the urge to call the Apple support because I did not believe that Apple would have such a naive fix to a significant issue like a system password. More importantly there is no data loss after reseting a system password from the bootable CD. Also you have the ability to reset any user account password.

 While it is great that I was able to regain my access to my system password with out losing any data on my computer, it made me rethink about security on my machine. 

Here is how to reset a system and/or user password:
  • Insert the MacOS CD that matches with your Mac OS version.
  • Shut down your Mac
  • press C key + power button.
  • Click Continue for the welcome menu
  • Select Utilities from the upper menu bar
  • Select Reset Password from the Utilities menu.
  • Select HD, which is your hard drive
  • Enter your new password
  • Click on Reset Defaults
  • Click on save button
  • Select Quit Installation CD from the MacOS Install CD


Java: file writer

public static void main(String[] args)

    {

try

{

    FileHelper.write(new File("csd_temp.txt"), "Hello World!");

} catch (FileNotFoundException e)

{

    e.printStackTrace();

} catch (IOException e)

{

    e.printStackTrace();

}

    }


    public static void write(File file, String text) throws FileNotFoundException, IOException

    {

if (file == null)

    throw new IllegalArgumentException("File should not be null.");

if (!file.exists())

    file.createNewFile();

if (!file.exists())

    throw new FileNotFoundException("File does not exist: " + file);

if (!file.isFile())

    throw new IllegalArgumentException("Should not be a directory: " + file);

if (!file.canWrite())

    throw new IllegalArgumentException("File cannot be written: " + file);


Writer output = new BufferedWriter(new FileWriter(file));

try

{

    output.write(text);

} finally

{

    output.close();

}

    }


GILEAD replaces Hibernate4GWT

Background information:
http://noon.gilead.free.fr/gilead/index.php?page=f-a-q

1) Download ZIP:
http://sourceforge.net/project/showfiles.php?group_id=239931&package_id=291834&release_id=639455

Import jar files into Maven2 repo:




mvn install:install-file -DgroupId=net.sf.gilead -DartifactId=adapter-core -Dversion=1.2.0.29 -Dpackaging=jar -Dfile=*download location*/gilead-1.2.0.29/dist/adapter-core-1.2.0.29.jar

mvn install:install-file -DgroupId=net.sf.gilead -DartifactId=adapter4gwt -Dversion=1.2.0.29 -Dpackaging=jar -Dfile=*download location*/gilead-1.2.0.29/dist/adapter4gwt-1.2.0.29.jar

mvn install:install-file -DgroupId=net.sf.gilead -DartifactId=hibernate-util -Dversion=1.2.0.29 -Dpackaging=jar -Dfile=*download location*/gilead-1.2.0.29/dist/hibernate-util-1.2.0.29.jar

mvn install:install-file -DgroupId=net.sf.beanlib -DartifactId=beanlib -Dversion=3.3.0beta21 -Dpackaging=jar -Dfile=*download location*/gilead-1.2.0.29/adapter-core/lib/beanlib-3.3.0beta21b.jar

mvn install:install-file -DgroupId=net.sf.beanlib -DartifactId=beanlib-hibernate -Dversion=3.3.0beta21 -Dpackaging=jar -Dfile=*download location*/gilead-1.2.0.29/adapter-core/lib/beanlib-hibernate-3.3.0beta21b.jar




2) replace in XYZ.gwt.xml


<inherits name="net.sf.hibernate4gwt.Hibernate4Gwt15" />


with



<inherits name="net.sf.gilead.Adapter4Gwt15" />


3) replace LazyPojo with LightEntity


import net.sf.hibernate4gwt.pojo.java5.LazyPojo;
public class BaseDTO extends LazyPojo

with



import net.sf.gilead.pojo.java5.LightEntity;
public class BaseDTO extends LightEntity

4) replace


import net.sf.hibernate4gwt.core.HibernateBeanManager;
import net.sf.hibernate4gwt.gwt.HibernateRemoteService;
public class SomeClassImpl extends HibernateRemoteService

with

import net.sf.gilead.core.PersistentBeanManager;
import net.sf.gilead.gwt.PersistentRemoteService;
public class SomeClassImpl extends PersistentRemoteService

5) change how you get the beans:

ApplicationContextFactory application = ApplicationContextFactory.getInstance();
setBeanManager((PersistentBeanManager) application.getBean("hibernateBeanManager"));
addressDao = (AddressDao) application.getBean("addressDao");


It also seems like there were some issues with merging arrays that was
fixed in the 1.1.1 version of hibernate4gwt http://hibernate4gwt.sourceforge.net/news.html

We have had some issues with merging objects that contain Lists or
Sets of other objects and getting classcastexception errors. hopefully
going to the new version will fix these issues.

Monday, December 15, 2008

Java compareTo method for TreeSet

  • To use java comparable class, implement Comparable<> in your class
  • Write a compareTo method as below:

public int compareTo(TeamDTO teamDTO)

    {

TreeMap map = new TreeMap();

map.put(getKey(teamDTO), teamDTO.getId());

map.put(getKey(this), this.getId());

if (map.firstKey().toString().equals(getKey(this)))

    return -1;

return 1;

    }



Thursday, December 11, 2008

iPhone: Java blog

I found same interesting posts on the following site:

http://java4iphone.com/category/all-news/java/

PS: If the rumors are true there will be Apple-enabled Java on the iPhone!


[0142]Examples of other applications 136 that may be stored in memory 102 include other word processing applications, JAVA-enabled applications, encryption, digital rights management, voice recognition, and voice replication. 

Mac OS X: Black border around active element

For a day, or two, I had a thin border appearing around each active element on my Mac OS X, despite the fact that it was not effecting  anything negatively, it was extremely annoying for two reasons: 

1) it is visually disturbing
2) I was not sure if the system was corrupted, or worse - infiltrated by some spyware

After some research I have learned that I turned ON the feature for visually impaired by executing a shortcut Command-F5.

Tuesday, December 9, 2008

Quality Testing

Unit testing

This (jUnit) is the first step for creating a quality product. A simple fact of writing a test before code implementation, forces the developer to think about various "what if?" scenarios. Testing a given method, or module, for both positive and negative inputs is essential and it is also a good example of how to use that code. Running all the tests at regular intervals assures good integration and regressions testing.

Selenium UI testing

Selenium provide the ability to regression-test hundreds of features that would be tedious for the human to test and retest. It quickly identifies the points of failure.

Code freeze

Code freeze happens when the QA/UAT is built and following the build. No NEW development happens during the code freeze. ALL developers concentrate
on:
- fixing the issues that were identified in this build,
- documenting the items they just finished,
- updating the QA checklist with new features,
- creating Selenium tests for the items just finished,
- planning and documenting future development,

Saturday, December 6, 2008

iPhone: Actions & Outlets

Actions & Outlets may seem difficult, but it makes sense:

Action: a method that will be called once user does something to the widget
Outlet: a widget that will change as a result of some action



Connecting an Action: 
  • Drag from the desired Event (Touch Up Inside) to File's Owner 
  • select action method you wrote


iPhone: TextField to Label

To create action of the text field to populate a label...

- (IBAction) sgDoneEditing:(id) sender
{
UITextField *textField = (UITextField *)sender;
NSString *textFieldValue = textField.text;
NSString *label = [[NSString alloc]  initWithFormat:@"S.G.: %@", textFieldValue];
sgValue.text = label;
[label release];
}


Tuesday, December 2, 2008

GWT: Ant classpath in build.xml

The variables are set in my_sys_name.properties file:

...

<property file=".\\src\\main\\resources\\${user.name}.properties" />

<path id="class_path">

<pathelement path=".\\src" />

<pathelement path=".\\src\\main\\java" />

<pathelement path=".\\target\\classes\\" />

<pathelement location="${GWT_DEV_JAR}" />


<fileset dir="${GWT_SERVLET_PATH}">

<include name="*.jar" />

fileset>


<fileset dir="${GWT_USER_PATH}">

<include name="*.jar" />

fileset>


<fileset dir="${WAR_EXPLODED}\\WEB-INF\\lib">

<include name="*.jar" />

fileset>

path>

...

Change Mode of the file - UNIX chmod

Make a files executable:

chmod +x *.sh


Monday, December 1, 2008

Linux: MySQL case sensitivity

As a matter of principle when writing SQL for mix-OS systems:

USE LOWER CASE ONLY

Example proper case SQL statement:

CREATE TABLE `address` (                       

           `id` bigint(20) NOT NULL auto_increment,     

           `attn_care_of` varchar(255) default NULL,  

           PRIMARY KEY  (`id`)                          

         ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 


This is especially important when developing on Windows systems where case does not matter. It is possible to configure MySQL to be case sensitive/insensitive, but that is seldom done.

Thursday, November 27, 2008

iPhone: Nimbuzz in, AIM out

 


The truth is that Skype totally dropped the ball on iPhone and AIM client was so bad, it was most of the time unusable.

The new application, Nimbuzz, provides support for most of the chat networks in the nice package.

Big pros for me:

  • All networks in one design - no switching
  • Skype - finally a good client
  • AIM / MobileMe / iChat
  • big horizontal keyboard typing
Cons:
  • no photo transfer (yet)
  • the list of contacts is very long, it would be nice if they were sorted by status ("online" on the top)
  • (option) hide all "Away" contacts
  • AIM often shows message that it is "temporarily unavailable"
  • no full names of the contacts (frankly I don't remember all the user names of all the people I have)
  • ability to make fonts smaller in the chat to show more messages while typing
  • better fitting of the messages (balloons?)
  • no group support (yet), I need a small groups like "friends", "work" and "all others"

Overall, Nimbuzz is the best chat application so far and the fact that it combines multiple networks makes it a winner on iPhone that can have only one app open at the time.


Monday, November 24, 2008

Saturday, November 22, 2008

iPhone: add app icon SDK 3.1

To add an icon to your app:
  • create 57x57 pixel "icon.png" image file (any other name will do)
  • drag that image to Resources folder (check the copy option)
  • in Info.plist edit "Icon File" - CFBundleIconFile property, enter the name e.g. "icon.png"



The SDK 3.1.1 upgraded this functionality by hiding the unreadable names:



Friday, November 21, 2008

SVN - remove .svn, UNIX find, rm commands

When you copy files over from another project the .svn directories prevent you from checking in the files to the new SVN directory. To list and then remove .svnrun the following commands:


find . -name '.svn' | xargs rm -fr

Thursday, November 13, 2008

Regular expression: user input validation checks

Validate email properties:
String regexExp = "^[a-zA-Z0-9]+[.a-zA-Z0-9_-]+@[a-zA-Z0_.-]+\\.[a-zA-Z]+$";

String regexExp2 = "^[a-zA-Z]+@[a-zA-Z0_.-]+\\.[a-zA-Z]+$";

String errMessage = "Invalid email address.";


Validate alpha numeric properties:

String regexExp = "[a-zA-z0-9]*";


Validate numeric properties:

String regexExp = "^[-+]?\\d*\\.?\\d*$";


Validate alpha properties:

String regexExp = "^([a-zA-Z\\s-\']+)$";


Validate URL properties:

String regexExp = "(HTTPS?://)[A-Z0-9.-]+\\.[A-Z]{2,6}([\\w\\d:#@%/;$()~_?\\+\\-=\\\\\\.&]*)";

String

Tuesday, November 11, 2008

SQL: simple database insert statement

insert into org_attribute (name,value,organization,level) values 

('name_a', 'My Company.', '1', 2),

('name_b', 'Your Company', '2', 2);


Monday, November 10, 2008

HTML: mailto tag

Using HTML mailto tag, you can open local system mail client to automatically open a new mail window. When a user clicks on an email address in the webpage, this tag will open up a new email message. Use below example to use this tag:


Thursday, November 6, 2008

Button Alignment

To align a button in the center of an a vertical container using google web toolkit:

Button selectOther = new Button("My Button");

favListing.setCellHorizontalAlignment(selectOther, HasHorizontalAlignment.ALIGN_CENTER);

Wednesday, November 5, 2008

Java comparator

Java provides comparator interface which is used to order elements in collection objects such as TreeMape or TreeSet. Below is an example of a comparator method:


 public int compareTo(Administrator admin)

    {

Map entityValue = new HashMap();

entityValue.put("Application", 1);

entityValue.put("Organization", 2);

entityValue.put("League", 3);

entityValue.put("Team", 4);


int thisIndex = entityValue.get(this.entityName).intValue();

int otherIndex = entityValue.get(admin.getEntityName()).intValue();

int compare = thisIndex - otherIndex;


if (compare == 0)

    compare = this.entityID.intValue() - admin.getEntityID().intValue();

return compare;

    }


You can call the compareTo method for a TreeSet collection for example. 


Monday, November 3, 2008

SQL: query

SELECT
(CONCAT( MONTH(date_time), "/", DAYOFMONTH(date_time) ,"/", YEAR(date_time))) as date,
COUNT(*), column_x, column_y
FROM table_x group by YEAR(date_time), MONTH(date_time), DAYOFMONTH(date_time), column_x, column_y;

Wednesday, October 22, 2008

Java final keyword

Wikipedia has a great article on the subject so there is no need to re-state it:


The final keyword is especially important when you write a lot of asynchronous code (GWT), or write complex subclassing.

Thursday, October 16, 2008

GWT: Override StackPanel onBroswerEvent()

An inner class is a customized class that is used inside a java class. The main purpose of inner class is to use a generic method that may be problematic to use in the actual class. This is a useful concept when using when using onBrowserEvent(Event event) method for instance in google web toolkit because I could not initialize an event in the original java class. Below are the step t implement this:


- Create a private inner class StackPanelNav  that extends the container/super class StackPanel:


private class StackPanelNav extends StackPanel
    {
public StackPanelNav()
{
    super();
}

@Override
public void onBrowserEvent(Event event)
{
    super.onBrowserEvent(event);
    switch (this.getSelectedIndex())
    {
    case 0:
    {
        // Handle selected
    }
break;
}

Friday, October 10, 2008

GWT: Auto-saving a TextArea

    You can use this inner class:

 private class TextAreaAutoSave extends TextArea
 {
   public TextAreaAutoSave()
   {
    super();
   }

   @Override
   protected void onDetach()
   {
      if (saveButton != null)
     saveButton.click();
   }
 }

HTML: superScript


ChicagoMarathon Inc

Tuesday, October 7, 2008

HTML: adding bullets

To add an .html bullets, insert below code to get a circle bullets:
Circles:



  • First element
  • Second element
  • Third element


If you need square shaped bullets, insert below code:



  • First element
  • Second element
  • Third element


Source: http://www.w3schools.com/TAGS/tag_textarea.asp

Friday, October 3, 2008

Mac: changing default internet browser


To change your default internet browser in Mac, follow bellow steps:
1. Open your current internet browser.
2. Click on Safari menu -> Preferences -> General tab.
3. Select your preferred browser from the drop down as illustrated in the picture.

Thursday, September 25, 2008

Setting Environment Variables on Mac

It is essential to set up a list of environment variables that are specific to a specific development environment. Below are the step on how to accomplish this on MacOS:

1. Open a text file and save it as .bash_profile:
# User specific Terminal config
if [ -n "$PS1" ]; then PS1='\u@\h:\w \$ '; fi
shopt -s checkwinsize

echo ~/.bash_profile

export PATH=$PATH:/usr/local/bin

####### JAVA DEV #######
export JAVA_HOME=/Library/Java/Home/
export PATH=$PATH:$JAVA_HOME/bin


2. Save .bash_profile under main user directory in the HD.
3. Restart your terminal window.
4. Verify in the terminal that you have the correct path for the env var. you just set up:
echo $JAVA_HOME

Tuesday, September 23, 2008

GWT: convert database objects to DTO object

Google web toolkit operates on DTOs (Data Transfer Object) in the front end. Every time data is retrieved from the database, it has to be converted to DTO objects before it can be used in the front end. Below code illustrates how to convert from database objects to DTOs:

In the service implementation class, externd HibernateRemoteService class:
public class MyServiceImpl extends HibernateRemoteService implements MyService,
{
public MServiceImpl()
{
XmlBeanFactory xml = ApplicationContextFactory.getXmlBeanFactoryInstance();
setBeanManager((HibernateBeanManager) xml.getBean("hibernateBeanManager"));
myDao = (MyDao) xml.getBean("myDao");
}
private MyDao myDao;
public List fetchAll()
{
List myList = organizationDao.fetchAll();
List dtos = ConvertToDTO.clone MyObject ListToDTO(getBeanManager(), myList);
return dtos;
}
}


Create a method as follows:
public static List cloneMyObjectListToDTO(HibernateBeanManager beanManager, List myList)
{
List< MyObjectDTO > dtos = new ArrayList< MyObjectDTO >();
for (MyObject obj : myList)
{
MyObjectDTO organization = (MyObjectDTO) beanManager.clone(org1);
dtos.add(organization);
}
return dtos;
}


At this point you can make a call from the front end to the Asynchronous method to call the service implementation. This will allow you to get a DTO objects that are converted from the back end.

Monday, September 22, 2008

"Runner" software for iPhone GPS

Yesterday night,  I was evaluating a new iPhone software for runners.

The program works very well, here are the highlights:

  • start your music BEFORE you start running and it will keep on playing in the background
  • select the distance (3 mile, etc), or time you want to run 
  • keeps track of your current speed, 
  • keeps track of your  average speed, 
  • calories burned for your weight and distance (about 120 kcal per mile)
  • routes the path you have run on the map
  • keeps history of all of that

Friday, September 19, 2008

Turning on colored coding in Eclipse


It is exteremly helpful to have color coding turned on in your development environment. In Eclipse you can turn on this color coding option in order to have modifiers, variable names, etc display in a common color, this will help you quickly identify how the code is used. To do this follow below steps:

In Eclipse menu -> Preferences option -> type "Editor" in the search text box -> Mark occurrences -> check all check boxes shown in picture below.

Thursday, September 18, 2008

Technology and Determination

Richard E. Leakey, a famous archeologist, described humans in his book, the "Origins":

[as] highly intelligent creature who, through technology and determination, has come to dominate the world [...]

Everyone will understand the definition of determination, but what is the technology today? Surely not the flint points.

We created a lot of powerful technologies.. atomic bombs, fighter planes, satellites, bio and chemical weapons, but if you think of it, they are mostly useless, the MOST far reaching and POWERFUL weapon is INFORMATION and the World Wide Web. We [I and some of my readers] happen to be foremost experts in this technology.

Do we have the determination to make a good use of it?

Sunday, September 14, 2008

Saturday, September 13, 2008

Setting up a new GWT project - part 2

This article assumes that you followed the previous step in "Setting up a new GWT project - part 1".

We will try to extend the previous functionality which just displayed the content of "Main.html" file and create a simple GWT element.



Here are the steps that we will work with:
  • Add css and images directories for later styling
  • Main.gwt.xml
This file at this point only defines the application entry point Main.java
  • Main.html
This file does not change much, but it includes the compiled JavaScript 

    <script language='javascript' src='com.taktico.Main.nocache.js' type="text/javascript">


  • Main.java
This is a very basic GWT functionality:

package com.taktico.client;


import com.google.gwt.core.client.EntryPoint;

import com.google.gwt.user.client.Window;

import com.google.gwt.user.client.ui.Label;

import com.google.gwt.user.client.ui.RootPanel;


/**  @author Uki D. Lucas  */

public class Main implements EntryPoint

{

    public Main()

    {

RootPanel.get("page").add(new Label("GWT! 1"));


    }


    public void onModuleLoad()

    {

RootPanel.get("page").add(new Label("GWT! 2"));

Window.alert("done loading!");

    }

}


The Eclipse directory will look similar to this:


Here is the screenshot of Main.gwt.xml and Main.html




And here is the resulting application!




At this point you have the client side GWT working, all you have to do is to add some services...

Side note: 
MyEclipse 6.5  Maven dependencies drives me nuts, I frequently switch to MyEclipse 5.0 and all seems to work fine.