Monday, December 28, 2009

Finish each day and be done with it.

“Finish each day and be done with it. You have done what you could; some blunders and absurdities have crept in; forget them as soon as you can. Tomorrow is a new day; you shall begin it serenely and with too high a spirit to be encumbered with your old nonsense.”

- Ralph Waldo Emerson through Julie911

When we are ... just not brave enough ...

"There are times when it is hard to believe in the future, when we are temporarily just not brave enough. When this happens, concentrate on the present. Cultivate le petit bonheur (the little happiness) until courage returns. Look forward to the beauty of the next moment, the next hour, the promise of a good meal, sleep, a book, a movie, the likelihood that tonight the stars will shine and tomorrow the sun will shine. Sink roots into the present until the strength grows to think about tomorrow."
— Ardis Whitman through Julie911

I see who I wanna be in my daughter’s eyes

“In my daughter’s eyes I am a hero. I am strong and wise and I know no fear, but the truth is plain to see: she was sent to rescue me. I see who I wanna be in my daughter’s eyes.”

- Martina McBride through Julie911

Wednesday, December 23, 2009

Basic Hibernate APIs

      // configure will look for mapping & settings in an application     

      // resource file named hibernate.cfg.xml

      SessionFactory sessionFactory =

            new Configuration().configure().buildSessionFactory();

      Session session = sessionFactory.getCurrentSession();

      try

      {

            session.beginTransaction();

           

            Event testEvent = new Event();

            testEvent.setTitle("testTitle");

           

            session.save(testEvent);

            // Commit if all goes well

            session.getTransaction().commit();

      }

      catch (Exception e )

      {

            // rollback if something fails

            session.getTransaction().rollback();

      }

 

Advantages of group insurance provided by employer in U.S

  1. The employer’s contribution. You don’t have to contribute to your entire medical insurance premium.
  2. No pre-existing conditions. If one approaches the insurance company directly, any pre-existing conditions are not covered. But this does not apply for group medical insurance provided by employer.

- As I understand from a friend of mine.

Tuesday, December 22, 2009

Seriousness ...can't be over done

I consider seriousness to be a admirable change of character, but it can't be over done.
A christmas carol

Monday, December 21, 2009

Basic Hibernate Command line application

Here is a basic hibernate command line application that is based on the getting started chapter of Hibernate Reference Documentation. It works with PostgreSQL and can be used to play around with small code changes and seeing the impact on the database. To point to another database, change hibernate.cfg.xml.


To build the application, run

mvn clean install

To execute, run

mvn exec:java -Dexec.mainClass=tutorial.EventManager -Dexec.args="store"

Wednesday, December 16, 2009

Whether your kid is a concert pianist or a math genius, it just doesn't matter, because at the end of the day all that matters is...

“Some day you’re gonna have a baby and you’re gonna feel overwhelmed by this little life that you’re responsible for and you’re gonna think and worry that everything you do is wrong, and that’s normal. You’re gonna obsess about what to feed it, and where to send it to school, and whether it should take violin or piano. But, I’m gonna let you in on a little old secret, it doesn’t matter. Whether your kid is a concert pianist or a math genius, it just doesn’t matter, because at the end of the day all that matters is if your kid is happy.”

- 
Grey’s Anatomy through Julie911

Believe that there's light at the end of the tunnel. Believe that you might be that light for someone else.

“Believe that there’s light at the end of the tunnel. Believe that you might be that light for someone else.”

- 
Kobi Yamada through Julie911

Tuesday, December 15, 2009

Merging specific changes from trunk to branch

To merge a set of specific revisions from the trunk to branch [this is usually required when a code change on trunk after a release needs to be back ported on to the release (each release having its tag)].

 

# cd abc/tags/1_7_3 # go to the branch

# svn merge svn://xyz/abc/trunk@8108 svn://xyz/abc/trunk@8109 . # merge into current working copy (branch)

Monday, December 14, 2009

Free Mind - mind mapping tool looks good

A couple of my colleagues discussed this:

 

http://freemind.sourceforge.net

Friday, December 11, 2009

Pursuit of greatness

Pursue something from nothing,

Pursue something good from something,

Pursue greatness from something good.

anybody driving slower than you is an idiot, and anyone going faster than you is a maniac

“Have you ever noticed that anybody driving slower than you is an idiot, and anyone going faster than you is a maniac?”

- 
George Carlin through Julie911

Thursday, December 10, 2009

To be present in the appreciation of life's abundance

Gratitude: To be present in the appreciation of life’s abundance and to share that light with others.

by Donna Downey through Julie911

Wednesday, December 09, 2009

Debugging exceptions with no known cause

There are times when you call a third party method in your code which throws an exception. Your line that invokes the third party code is not seen in the exception stack trace. In these cases, it is useful to wrap the call to the third party code in try catch block, catch Exception and log the resulting exception. The stack trace from the exception you log will have your code that is making the third party call, calls made by the third party code and likely a more detailed message of what went wrong.

 

e.g.:

 

class MyClass

{

    public void myMethod()

    {

        try

        {

            new ThirdPartyClass().thirdPartyMethod();

        }

        catch (Exception e)

        {

            e.printStackTrace();

        }

    }

}

Usually an application will create a single Configuration, build a single instance of SessionFactory and then instantiate Sessions in threads servicing client requests.

 

Monday, December 07, 2009

Thursday, December 03, 2009

Wednesday, December 02, 2009

Portlet Modes

The mode indicates the function that the portlet is currently performing. A portlet’s current mode is passed to it by the portlet container. Based on the mode, the portlet can choose to generate different contents. In processAction() method, the portlet can change the mode programmatically.

 

Portlets can be in 3 modes:

  1. View (represented by PortletMode.VIEW) – usually portlets represent their current state
  2. Edit (PortletMode.EDIT) – Options to edit data are presented here
  3. Help (PortletMode.HELP) – Generic or context sensitive information about the portlet provided here.

 

The portlet modes that a user has access to can be restricted by his authentication credentials (e.g. guest can only read and access help).

 

Custom portlet modes are also supported. These custom modes can be portal managed (portal will manage custom modes for the portlet) or portlet managed (portlet manages its mode in its own code. Portal not aware of portlet’s modes).

 

In portlet.xml, the modes that the portlet supports are indicated as follows:

 

<portlet>

  …

  <supports>

    <mime-type>text/html</mime-type>

    <portlet-mode>view</portlet-mode>

    <portlet-mode>edit</portlet-mode>

    <portler-mode>help</portlet-mode>

  </supports>

</portlet>

 

Initialization parameters to a portlet can be specified as follows in portlet.xml:

 

<portlet>

  <init-param>

    <name>view-action</name>

    <value>test</value>

  </init-param>

  <init-param>

    <name>edit-action</name>

    <value>test2</value>

  </init-param>

  …

</portlet>

 

These initialization parameters can be accessed in the portlet using the PortletConfig.

      

Portlet lifecycle

The portal, during the course of managing a portlet, passes the portlet through the following stages

  1. Init
  2. Process Action
  3. Render
  4. Destroy

There is one method in the Portlet interface for these stages. Right before a stage change occurs (e.g. when the portal is about to destroy a portlet), the portal notifies the portlet by invoking the appropriate method (the destroy() method for e.g.) on the Portlet Interface.

 

These are the possible state transitions

Init -> Process Action <-> Render -> Destroy

 

  1. Init – Porlet is loaded and instantiated either on portlet container start or upon receipt of request for the portlet. Following this, the init() method on the portlet will be invoked. Portlets usually initialize expensive resources (connections for e.g.) at this time
  2. Process Action & Render - Requests raised by portlets can from
    1. Action URL: request fires processAction() method on portlet on which the URL resides and render() method on all the portlets. The portlet, in its processAction() method, updates its model. The render() method generates a view that indicates the current state of the model.
    2. Render URL: request only fires render() method on all the portlets.
  3. Destroy – Portal’s notice that the portlet is to be removed. Typically, a portlet will release all resources and persist any yet-to-be-persisted state/model.

 

Tuesday, December 01, 2009

When ... you could not hold on a minute longer, never give up then, for that is just the place and time that the tide will turn.

“When you get into a tight place and everything goes against you, till it seems as though you could not hold on a minute longer, never give up then, for that is just the place and time that the tide will turn.”

- 
Harriet Beecher Stowe through Julie911

Looking at java stack traces

While looking at stack traces,

  1. Read from the bottom of the trace
  2. Read the Message of the last stack trace (usually there are many with “caused by”)
  3. Look for a line in the stack trace that indicate a call to your package in the stack trace. This way, you will know how your code is getting called and what your code is doing.

Monday, November 30, 2009

let us all be thankful.

“Let us rise up and be thankful, for if we didn’t learn a lot today, at least we learned a little, and if we didn’t learn a little, at least we didn’t get sick, and if we got sick, at least we didn’t die; so, let us all be thankful.”

- Buddha Through Julie911

Tragedy is a test of courage.

 “Tragedy is a test of courage. If you can meet it bravely, it will leave you bigger than it found you.”

- A Star is Born (1937) from Perfectly Imperfect/Julie911

 

 

The joy of life comes from our encounters with new experiences

 “So many people live within unhappy circumstances and yet will not take the initiative to change their situation because they are conditioned to a life of security, conformity, and conservatism, all of which may appear to give one peace of mind, but in reality nothing is more dangerous to the adventurous spirit within a man than a secure future. The very basic core of a man’s living spirit is his passion for adventure. The joy of life comes from our encounters with new experiences, and hence there is no greater joy than to have an endlessly changing horizon, for each day to have a new and different sun.”

- Chris McCandless, Into The Wild from Perfectly Imperfect/Julie911

 

 

Wednesday, November 25, 2009

You should never try to be better than someone else

You should never try to be better than someone else. Always learn from others. Never sease trying to be the best that you could be. That is under your control. If you are too engrossed into things that you have no control, it will adversely affect the things over which you have control.

Definition of success: Peace of mind attending only through self satisfaction in knowing you made the best of the effort of which you are capable of. Others cannot judge it. Your reputation is what you are perceived to be. Your character is what you really are.

Believe that the ways will work out the way we want it to provided we do what we should.


Sometimes I think the Fates must grin as we denounce them and insist the only reason we can't win, is the Fates themselves that miss.
Yet there lives on the ancient claim:
We win or lose within ourselves. The shining trophies on our shelves can never win tomorrow's game.
You and I know deeper down, there's always a chance to win the crown,
But when we fail to give our best,
we simply haven't met the test, of giving all
and saving none until the game is really won.
Of showing what is meant by grit.
Of playing through when other Quit,
Of playing though, not letting up.
It's beating down that wins the cup. Of dreaming there's a goal ahead.
Of hoping when our dream are dead.
Of praying when our hopes are fled.
Yet losing, not afraid to fall,
if bravely we have given all. For who can ask more of a man
then giving all within his span.
Giving all, it seems to me, is not so far from vistory.
And so the fates are seldom wrong, no matter how they twist and wind,
It's you and I who make our fates.
We open up or close the gates on the road ahead or the road behind.



Never mention Winning. You can lose when you outscore somebody in a game. And you can win when you're outscored.
Hold your head up after a game. When a game is over, and you see somebody that didn't know the outcome, I hope they cound't tell by your actions whether you outscored an opponent or the opponent outscored you.

If you make the effort to do the best you can regularly, the results will be about what they should be. Not necessary to be what you want them to be, but they will be about what they should.

The result of the game should be the byproduct of your best effort and not the end result.

"The journey is better than the end" - Cervantes


- My notes from a talk by John Wooden (source)

The reason people find it so hard to be happy is ...

“The reason people find it so hard to be happy is that they always see the past better than it was, the present worse than it is, and the future less resolved than it will be.”

- 
Marcel Pagnol Through Julie911

Monday, November 23, 2009

...This, too, shall pass.

“Expect trouble as an inevitable part of life and repeat to yourself the most comforting words of all: This, too, shall pass.”

- Ann Landers Through Julie911

Sunday, November 22, 2009

Strategies for development with Liferay

Following options can be adopted for developing Liferay based solutions
1. Plug-in SDK Environment (least [but sufficient in most cases,] flexibility and least migration effort): Liferay supports different types of plugins such as themes, layout templates, portlets, webs (which are web applications) and hooks. Liferay provides a Plug-in SDK to facilitate development of these plugins. One can extend by implementing the appropriate plug-in.
2. Extension Environment (Very good flexibility and can need extensive migration effort): This approach involves writing custom code that overrides Liferay code. Following approaches to overriding liferay code exist:
a. Modifying JSP files (of the porttal or the built in portlets)
b. Modifying configuration files (portal-ext.properties [layouts, themes, hibernate, cache, users, groups ets...], system-ext.properties [for java system properties used by liferay], ext-spring.xml [custom source code being spring dependency injected], web.xml [for servlet configuration], struts-config.xml [for struts related extension]
c. Custom classes (configures through portal.properties)
This approach does *not* include changing Liferay source code.
3. Modifying Liferay Source code: Pay Liferay, get their source code changed and contributed back to community.

Portlets in Liferay

There are 3 approaches to building portlets that can be deployed in liferay
1. JSR 168/286 Compliant Portlet - This is a standards compliant portlet and can hence be deployed not only in Liferay but in any portal server. The downside is it cannot use Liferay specific APIs.
2. Liferay plugin portlet - These portlets are liferay plugins. They may have a dependency on Liferay APIs (Portal kernel and Portal Service). Having dependencies on Liferay APIs restricts their portability to Liferay only.
3. Web application exposed as a portlet - One type of a Liferay plugin is a web applications (webs). So a simple web application can be exposed as a portlet in Liferay using the webs plugin.

Saturday, November 21, 2009

DRM - Digital Rights Management

My limited understanding of DRM: When music is downloaded from itunes, it includes the user id as a (DRM) label into the content file. This way when the content file is published on a file sharing web site, the culprit is easily know.

Friday, November 20, 2009

Audio connectors/plug/jacks

Stereo plugs are TRS (Tip, Ring, Sleeve) connectors. The TRS indicate contact points where audio signals are passed on. There are just TS and TRRS connectors too.

Jack plug, in UK, refers to a female connector and an Jack socket to a make connector.

In US when a connector is fixed, its called a jack.

2.5mm (diameter) Male Stereo socket - not commonly used

3.5mm (diameter) Male Stereo socket - the most commonly used:
There is also a 6.3 mm which is also used but not as frequently as 3.5 mm.

An RCA (Radio Corporation of America - which found it ) Male socket




Thursday, November 19, 2009

Which process has a lock on a file (continued....)

The command line utility to check the processes that have a lock on a given file:

 

e.g.

 

$ handle server.log

 

Handle v3.42

Copyright (C) 1997-2008 Mark Russinovich

Sysinternals - www.sysinternals.com

 

<Non-existant Process> pid: 277144  43C: E:\xyz\abc\logs\server.log

<Non-existant Process> pid: 278500  71C: E:\xyz\abc\logs\server.log

<Non-existant Process> pid: 279112  71C: E:\xyz\abc\logs\server.log

$CDPATH - very useful for bash shell navigation

Often, we “cd” to commonly used directories in a bash shell. Having to type the whole path is often a pain. I was using aliases to navigate to commonly used directories (e.g. alias scripts=’cd /cygdrive/c/scripts’). But this would require you to identify each frequently used directory, define an alias for each one of them and remember the alias.

 

A good friend of mine, pointed out an alternate to achieve the same. $CDPATH. This is a set of paths that the “cd” command would look into (besides “.”) for the directory to switch to. So if “cd scripts” is executed, it will check if the current directory has a “scripts” directory, if not, it will look for a “scripts” directory in each directory indicated in the “CDPATH” variable. If “CDPATH” has “/cygdrive/c/: /cygdrive/c/home/xyz”, then cd will look for “./scripts”, “/cygdrive/c/scripts”, “/cygdrive/c/home/xyz/scripts” and cd to the first directory that exists.

 

Source.

 

Wednesday, November 18, 2009

Which process has a lock on a file

Many times one attempts to delete a file and windows reports that the file is in use by another program and hence cannot be deleted. Tracing out which program is using the file was a hassle.

 

With Windows Process Explorer, you can figure out which process is holding the lock on a given file.

 

Once installed and started, click on “Show Lower Pane (Ctrl + L)” on the tool bar. This will open up a listing below the list of the processes. Now click on a process and all files used by that process is listed in the lower pane.

Saturday, November 14, 2009

Friday, November 13, 2009

Merging specific commited changes from one branch to another

To merge changes made in revision 7877 from trunk to the current working directory (which could be another branch):

 

svn merge -r -r7876:7877 svn://xyz/abc/efg/trunk

Lunch at O'falafel today

Went to O’falafel today and the sandwich for pretty good.

Thursday, November 12, 2009

Tuesday, November 10, 2009

When you love someone...

“When you love someone, you’ve got to trust them. There’s no other way. You’ve got to give them the key to everything that’s yours. Otherwise, what’s the point?”

- 
Robert De Niro, Casino through Julie911

"A cheerful frame of mind, reinforced by relaxation. is the medicine that puts all ghosts of fear on the run."

“A cheerful frame of mind, reinforced by relaxation… is the medicine that puts all ghosts of fear on the run.”

- 
George Matthew Adams through Julie911

Friday, November 06, 2009

Tuesday, November 03, 2009

Stress is poison.

“Stress is poison.”

- Agavé Powers through Julie911

Thursday, October 29, 2009

Sales People are a breed by themselves

As I am typing this I am overhearing a conversation between a sales guy and a fellow programmer. Before this conversation started, the programmer was in a discussion with another programmer and this is how the sale guy started:

Sales Guy: Sorry for interrupting your discussion. I just need to know when would be a good time to clarify a few questions I have.

Programmer: ahhhh (for 1 second)

Sales Guy: It would not take more than a minute to go through.

Programmer: emmm (for 1 second)

Sales Guy: Should we go through them now?

Progammer: hmmmm….yeah

Its been 10 minutes since he has started and it does not seem to be ending soon. J

Introducing a new hibernate persistant entity

1. Write down how your model object (.java file), hibernate mapping (.hbm file) and ER diagram (DB schema) is going to look like before and after the change. Contemplate on the end result and confirm that it is the best solution in each aspect (model, mapping and schema)
2. Implement any new model object. Review (see "Self reviewing code changes").
3. Coin the hbm mapping for the new model object. Review.
4. Modify existing model object to reference the new model object. Review.
5. Modify existing mapping to reference the newly mapped object. Review.
6. Write a new test case that will
a. exercise each method and each control flow (within the methods)
b. exercise each attribute of mapping
7. Make the test case pass (this will automatically rebuild the schema or you might have to drop and recreate the schema manually)
8. Write SQL scripts to
a. Change the schema on production.
b. Migrate existing data.
9. Use the new APIs from client APIs.

Self reviewing code changes

For new code:
Read the new code and explain the code to an imaginative reviewer. Make changes as necessary.

For code changes:
Pull up a diff of code changes, read and explain each change to an imaginative reviewer. Make changes as necessary.
If XML files are to be reviewed, explain what each attribute does to the imaginative reviewer. As you explain, if there is anything unusual, it will come up.

Wednesday, October 28, 2009

Hibernate many-to-one example

Basic many-to-one
<class
  name="Student"
  table="STUDENT"> Many students have the same course
  ...
  <many-to-one>
    name="course"
student has a property by name "course"
    column="COURSE_ID" COURSE_ID is a foreign key in STUDENT table.
    "column" is Optional. If not specified, target entity name ("course") + "_" + target entity if property name is default.
    class="Course" Optional. If not specified, hibernate will figure out from type of property.
    not-null="true"/> Each student MUST have a course
</class>

public class Student
{
  private Course course; // with getters and setters
  ...
}

"unique" in many-to-one

<class
  name="Student"
  table="STUDENT">
  ...
  <many-to-one>
    name="course"

    column="COURSE_ID"
    class="Course"

    not-null="true"
    unique="true"/> 
Each student MUST have a UNIQUE course. Does not make  sense in this example as that would mean each student must have a unique course i.e.  only one student can study a course. :-)
</class>


Normal beyond convenience

Had a discussion with Joel and Eric on a table structure today.

 

The issue:

 

There is a table like this:

 

“course” table

 

Course_id

Degree

Fee

Type

1

COMMERCE

1000

UG

2

COMPUTERS

2000

UG

3

LAW

1500

UG

4

COMPUTERS

2000

PG

 

The issues this was:

  1. The “course” table represented both the entity (degree) and the relationship (course to degree).
  2. Look up course_id 2 and 4. They both represent COMPUTERS degree and are repeated here. The Degree for course_id 4 could have very well been “computers” instead “COMPUTERS” although both refer to the same degree.

 

So I wanted to split this table as follows:

 

“course” table

 

Course_id

Degree_id

Fee

1

101

1000

2

102

2000

3

103

1500

 

“degree_lookup” table

 

Degree_id

Name

101

COMMERCE

102

COMPUTERS

103

LAE

 

Note: In my business case, it was highly likely that only 2 or more courses would be added in the next 10 to 15 years.

 

But Eric indicated that the above solution would be good if there were a lot of courses already or a lot of courses were going to be added. But this was not the case for us. So the above solution would be normalization beyond convenience (writing all the domain API objects, SQL, hibernate mapping etc…). So to take care of disadvantage 2 above, there could be a check constraint inserted on the table. That way only COMPUTERS will be accepted. In this case it would make sence. But if there were 20 or 30 courses, then it would not make sense to put in 20 or 30 elements in the check constraint and in that situation, my solution would work very well.

 

 

Nice Gimp tutorials

Monday, October 26, 2009

Set a goal you can achieve within the next 24 hours.

“The greatest thing you have is the 24 hours directly in front of you. The past is gone, the future is distant. Today you can succeed. Set a goal you can achieve within the next 24 hours.”

- 
JoAnn Pillifant through Julie911

Wednesday, October 21, 2009

Live Simply, and Save the Drama for Your Mother

Source: Zen Habits.

 

Live Simply, and Save the Drama for Your Mother

The word “drama” has taken on an interesting meaning in recent years, beyond the performance form of fictionit’s traditionally signified: “making a big deal over something unnecessarily”.

It’s about making a big production of something, when you could simply get on with things.

Interestingly, the word “drama” comes from the Greek word for “action”, which in itself derives from a word that means “to do”. And doing turns out to be the answer for unnecessary “drama” (which, by the way, you would be wise to save for your mama or other such parental figure, according to popular television).

What’s the problem with drama? For one, as the urban definition implies, it’s unnecessary. There’s no need for histrionics when you can talk about and deal with things calmly. There’s no need to get overly emotional when you can breathe, release the tensions, and focus on being happy, now, in the moment.

It complicates things, makes a big deal of little things, and ignores the little things that should be a big deal: little things like simple pleasures, and gratitude, and the simple wonderful existence of life.

Drama makes life harder. If you lose your job, you can go into a depression (perhaps understandably) and lose your home and have a hard time finding a job again — often because of the depression. But if instead you stay calm, perhaps take the view that this is a fresh start and a way to pursue the dream you’ve never had the time to pursue, look at it as a way to learn new skills and reinvent yourself … things won’t be so hard.

If you have gotten fat, instead of making a big deal about it, go outside for a walk, and make it a simple daily habit (perhaps gradually turning it into a jog). And then just start eating fresher foods — fruits and veggies and beans and nuts — rather than unhealthy foods. Start cooking for yourself instead of eating fast food. The drama will only serve to get you depressed and fatter. Simply getting on with it will solve the problem, rather easily if you don’t make a big deal of it.

How to Stop the Drama
So when you feel yourself getting worked up about something — a coworker not pulling his weight, a spouse who isn’t living up to your expectations, a daughter who isn’t doing as well at school as you’d like — stop the drama.

Breathe. Let it go. Breathe in, taking in the peace of the world. Breathe out, and let the tensions and frustrations flow out of you. Repeat until the drama is gone.

And then simply be, in the moment, right now. When we get worked up about something, it’s usually about something that has already happened (in the past) or something that might happen, that’s coming up (in the future). Forget about all that right now (you can reflect on it later, when you’re calmer and dispassionate). Right now, focus on what you’re doing. This might be sitting in front of a computer, reading. Or walking. Or drinking a glass of water. Washing dishes. Driving. That’s what you’re doing, in the moment. That’s all you should think about. As you feel your mind returning to the past or the future, return it gently to what you’re doing right now. It takes practice.

Simply get on with it. Do what you need to do to calmly address the situation. Deal with it, in as simple a manner as possible. Forget all the complications — just do.

Overwhelmed with too much to do? Breathe, focus on what you are doing right now, and just focus on getting that done.

Tired of your horrible job? Breathe, focus on now, and do what needs to be done to deal with it.

Annoyed by someone? Let it go. Focus on what you’re doing, right now. And just get on with it.

If you start getting worked up again, start back at the first step.

Also, your mother probably doesn’t need your drama either, just fyi.