Anything that interests me finds place here. Software dominates my interests and hence a good part of this blog as well.
Monday, December 28, 2009
Finish each day and be done with it.
- Ralph Waldo Emerson through Julie911
When we are ... just not brave enough ...
— Ardis Whitman through Julie911
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
- The employer’s contribution. You don’t have to contribute to your entire medical insurance premium.
- 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
A christmas carol
Monday, December 21, 2009
Basic Hibernate Command line application
To build the application, run
mvn clean install
To execute, run
mvn exec:java -Dexec.mainClass=tutorial.EventManager -Dexec.args="store"
Friday, December 18, 2009
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();
}
}
}
Tuesday, December 08, 2009
If you are greedy and lazy
If you are greedy and lazy you expect more result from less effort.
Monday, December 07, 2009
Now becomes my past...so let me handle it mindfully
What is now will become the past in the future. If you don’t want to feel sorry in the future….act mindfully now.
Thursday, December 03, 2009
He who has a why to live for, can bear almost any how.
“He who has a why to live for, can bear almost any how.”
- Friedrich Nietzsche through Julie911
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:
- View (represented by PortletMode.VIEW) – usually portlets represent their current state
- Edit (PortletMode.EDIT) – Options to edit data are presented here
- 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
- Init
- Process Action
- Render
- 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
- 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
- Process Action & Render - Requests raised by portlets can from
- 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.
- Render URL: request only fires render() method on all the portlets.
- 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,
- Read from the bottom of the trace
- Read the Message of the last stack trace (usually there are many with “caused by”)
- 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
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
Tuesday, November 24, 2009
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
Portlets in Liferay
Saturday, November 21, 2009
DRM - Digital Rights Management
Friday, November 20, 2009
Audio connectors/plug/jacks
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.
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
There is more to life than increasing its speed.
“There is more to life than increasing its speed.”
- Gandhi through Kari-shma
Wednesday, November 11, 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
People and Virtues
Don’t break virtues to appease people.
Don’t break people to enforce virtues.
- Me
Tuesday, November 03, 2009
Sunday, November 01, 2009
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
<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:
- The “course” table represented both the entity (degree) and the relationship (course to degree).
- 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.
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
Friday, October 23, 2009
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.