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.

 

Readable text

My favourite eclipse code format

My favourite eclipse code format

Tuesday, October 20, 2009

Did you leave your shoes to the right or the left of the umbrella?

The umbrella

As tradition dictates, upon entering his Zen master’s house, the disciple left his shoes and umbrella outside.

“I saw through the window that you were arriving,” said the master. “Did you leave your shoes to the right or the left of the umbrella?”

“I haven’t the least idea. But what does that matter? I was thinking of the secret of Zen!”

“If you don’t pay attention in life, you will never learn anything. Communicate with life, pay each moment the attention it deserves – that is the only secret of Zen.”

Source: Warrior of the Light

Saturday, October 17, 2009

Creating text with images

This tutorial details the steps to create a wording with parts of an image in the foreground of the text. Like this:


First open up the image which needs to be in the foreground of the text.

Next, select the text tool from the tool box. I used the following settings:


Now type the desired text. I typed "Happy Diwali". Note that this new text creates a new layer.

The image now looks like this:

Next, select "Path from text" in the toolbox (without changing the tool selection)


Now make a selection of the text by clicking Select -> From Path


Now the image looks like this:

Now Select Edit -> Clear.


Now the image looks like this:


Now, select the text layer and click on "Layer to image size"


Then, select Select -> invert. This will select everything other than the text selected previously.


Select the bucket fill tool. This is what I used:


The final result looks like this:



Enjoy :-)

Tip: To make a selection from scissors select tool, click inside the selection

After making the selection with the scissors selection tool, click inside the selection to turn it into a selected area.

The Tools menu has the same options as the toolbox window. But the tools are categorized by type.

Thursday, October 15, 2009

Creating callouts or speech bubbles in GIMP

First open the basic image to which you would like to add the callouts to. This was my base image:



Add a new layer to the image by selecting Layer -> New Layer:



Give the new layer a new name (optional)


The new layer can now be found in the layers window:



Now select the Ellipse Select Tool from the Toolbox window



Draw an ellipse on the image where the callout is required:



In my case, I wanted the border line of the call out to have the same color as the cat's face. So I had to set my foreground colour to the cat's face color. To do so, select the Color picker tool in the toolbox. In the layer's window, select the Background layer.



With the Color picker tool click on the cat's face to set that color as the foreground color.



Select the new layer that was created in the first few steps:


Now select the fill tool and make sure "FG color fill" is selected.


Now click inside the ellipse. The image looks like this now:



Now click select -> Shrink.



In the next dialog, enter the size of the callout's border. In my case I wanted a 3 pixel border.



The selection now reduces by the number of pixels entered in the previous step:



Now click edit -> clear.


Now the border of the call out is nicely formed.



Now get rid of the selection (Select -> None)



Now to extend the call out, use the Path tool. Select click on points indicated:



After clicking on the 3rd point, hold the control key, hover over the 1st point and when the mouse pointer changes a little bit, click. This will make the selection a closed one.

Now draw lines over the selection by selecting Stroke selection:



In my case the size of the call out line is 3 pixels (entered previously in the shrink selection step). The same size is entered here too:



Now the image looks like this:



Using the same steps, make another call out for the mouse:



Now the lines within the call out arrows have to be removed. To do so, zoom in:



Select the Paths tool and go about clicking on the line segment that needs to be erased. Now select "Stock path" and select "Stock path from paint tool" and select "Erase" in the drop down (before doing this select the eraser tool in the tool bar and make sure the brush size [in the eraser tool properties] is correct) and stroke. This will erase the un-necessary parts and look like this:



Use, the Text tool and enter the desired text into the call out. Have Fun/ :-)

This tutorial is based on this article with more details and certain improvements.

Nice AOP articles

Spring Terminology: Weaving

Weaving is the process of applying Aspects to Targets to create Proxies. The aspects are woven into the target at the specified joinpoints. This process can happen at different stages of the Target's life
1. Compile Time: Aspects woven into targets when target class is compiled. This requires a special compiler though. Aspectj's weaving compiler weaves aspect this way.
2. Classload time: Aspects woven into targets when target class is loaded into the JVM. This requires a special class loader that enhances the target class's byte code before it is introduced to the application. Aspectj 5's load time weaving (LTW) support is based on this approach.
3. Runtime: Aspects woven into targets when target class is invoked. Typically an AOP container will generate a proxy object that will deliver the aspect functionality before or after delegating to the target object. This is how Spring AOP aspects are woven.

Source: My understanding from reading "Spring In Action"

Spring Terminology: Proxy

When an advice is applied to a Target, it becomes a Proxy. To the clients of the Target, the Target (Pre-AOP) and the Proxy (Post-AOP) are the same. There are no differences in the public APIs exposed by both of the objects. The Delta between the proxy and the target is the implementation to address cross-cutting concerns that are hosted in the Advice.

Source: My understanding from reading "Spring In Action"

Spring Terminology: Target

A target is the object that is being advised. This could be a third party object and a self-written home-grown object. If there was no AOP then then object would handle both its primary logic and cross cutting concern. With AOP this object's responsibility is restored to its code logic and it does not know that it is being advised.

Source: My understanding from reading "Spring In Action"

Spring Terminology: Introductiion

Introduction gives new behavior and state to existing classes without having to change the existing classes. This is achieved by adding new methods and properties to existing classes.


Source: My understanding from reading "Spring In Action"

Wednesday, October 14, 2009

Spring terminology: Aspect revisited

See previous post titled “What is Cross Cutting Concern? Why AOP? What is Aspect?” before reading this.

 

An Aspect is an amalgam/merger of advice (what and when) and pointcuts (where) [see previous posts on advice and pointcuts].

 

 

Spring Terminology: PointCut

An Aspect (see previous post on what an Aspect is) need not handle all Join points of an application. A specific Aspect can be made responsible for a subset of Join points. PointCuts are used to define the subset of join points that a given Aspect is responsible for handling. In other words PointCuts defines the join points where the aspect logic is to be applied. This “where” can be defined on specific, explicit class and method names or through regular expressions that apply to classes and method names that match the pattern.  

Spring Terminology: Join Point

Points in application logic where the aspect’s (see previous posts on what an Aspect is) functionality is to be applied or plugged in. This point could be a method invocation, field write/modification or exception thrown. There are points where the aspect’s logic can be pluged in to add new behaviour.

Spring Terminology: Advice

Defines the responsibility of the Aspect (see previous posts on what an Aspect is) in terms of what (will be performed) and when (it will be performed – before/after/before and after/only on exception).

Brittle means Fragile

 

What is Cross Cutting Concern? Why AOP? What is Aspect?

There are certain aspects of the application that has to be addressed at every layer of the application and cannot be categorized to be a responsibility of any one single layer. Examples are logging, transaction management, security, Caching, Validation etc…

These aspects that span across the several layers of the application are cross cutting concerns. AOP helps decouple cross cutting concerns from the application logic that they impact.

If there was no AOP, one would have to implement common functionality in a base class and have all classes make use it. But this will make the object hierarchy brittle. Other common approach is to delegate common functionality is to utility class. But this will require calls to the utility method spread all across application logic code.



In AOP, the common functionality is implemented in a single class. But this class is invoked by declaratively defining how and where the functionality needs to be applied without having to modify the class to which the functionality is applied to.


These classes that hold common functionality are called Aspects.


Now, the application logic code or service modules contain code pertaining only to their primary responsibility or primary concern and secondary concerns move to aspects. The second advantage is that all common functionality is nicely held in a single place.


Why Dependency Injections

Dependency Injections helps decouple the various components of the application by

  1. Having the components reference each other through abstract interfaces and
  2. Delegate instantiation of concrete implementation classes to a dependency injection framework like Spring

Tuesday, October 13, 2009

Gimp Controls

Navigating over big images or high zoom levels:

 

 

Clicking on that helps to navigate over the image like this:

 

 

To view image details

 

Brings up this:

 


React the same way to winning and losing

If you can react the same way to winning and losing, that… quality is important because it stays with you the rest of your life.

 

- Chris Evert

Monday, October 12, 2009

jQuery(this) example

An example of using jQuery(this).

My browser favourites






work wholeheartedly

When you’re working, focus. I’ve found that concentrating on work is actually less exhausting than allowing yourself to be wishy-washy about it. When you decide that it’s time to work, buckle down, eliminate distractions, and do it wholeheartedly. There’s something amazingly refreshing about pure, sharp focus.

 

Zen Habits

Gimp Book

Nice Article on CSS Styling

Friday, October 09, 2009

Collapsing HTML table using jQuery

<html>

<head>

<script src="http://code.jquery.com/jquery-latest.js"></script>

<script type="text/javascript">

$(document).ready(

  function()

  {

    jQuery("[id*=testTable] tr:gt(1)").hide();

  }

);

 

function collapseDetails()

{

  jQuery("#testTable tr:gt(1)").toggle() ;

}

</script>

</head>

<body>

  <div id="wholeBody">

    <table id="testTable">

      <tbody>

        <tr>

          <td>

            col1

          </td>

          <td>

            col2

          </td>

        </tr>

       

        <tr>

          <td>

            col1

          </td>

          <td>

            col2

          </td>

        </tr>

       

        <tr>

          <td>

            col1

          </td>

          <td>

            col2

          </td>

        </tr>

       

      </tbody>

    </table>

    <div id="showAll" onclick="collapseDetails();">Show/Hide</div>

  </div>

</body>

</html>

Collapsing table using jQuery
























col1

col2

col1

col2

col1

col2

Show/Hide

Thursday, October 08, 2009

"We learn more by looking for the answer to a question and not finding it, than we do from learning the answer itself."

“We learn more by looking for the answer to a question and not finding it, than we do from learning the answer itself.”

- Lloyd Alexander through Julie911

Tuesday, October 06, 2009

No bitterness

“Bitterness imprisons life; love releases it. Bitterness paralyzes life; love empowers it. Bitterness sours life; love sweetens it. Bitterness sickens life; love heals it. Bitterness blinds life; love anoints its eyes.”

- 
Harry Emerson Fosdick through Julie911

Monday, October 05, 2009

"Time you enjoy wasting, was not wasted."

“Time you enjoy wasting, was not wasted.”

- 
John Lennon through Julie911

"My formula for living is quite simple. I get up in the morning and I go to bed at night. In between, I occupy myself as best I can."

“My formula for living is quite simple. I get up in the morning and I go to bed at night. In between, I occupy myself as best I can.”

- 
Cary Grant through Julie911

Friday, October 02, 2009

The cheapest, fastest, and most reliable components of a computer system

“The cheapest, fastest, and most reliable components of a computer system are those that aren’t there.” - Graham Bell through Leo

In the context of don’t bring in stuff that are not needed

Forgiveness is the only way to dissolve .... resentment

“When you hold resentment toward another, you are bound to that person or condition by an emotional link that is stronger than steel. Forgiveness is the only way to dissolve that link and get free.”

- 
Angela Belcher through Julie911

don't play sad songs

“Whatever you do, don’t play sad songs if you’re blue, ‘cause they’ll just bring you down.”

Cheyenne