Friday, February 26, 2010

Floating point numbers in String.format()

String.format(

"SQL completed in %.2f seconds.",

((float)(endTime - startTime)/1000)

)

Output:

SQL completed in 0.02 seconds.

Display the parameter as a floating point decimal (%f) with 2 decimal places (%.2f).

 

Thursday, February 25, 2010

Judge before and after doing a scene but not during

Judge before and after doing a scene but not during (when the scene is being made)

 

-          An actor on NPR

The more precise you are about your decisions the better are the chances of winning

The more precise you are about your decisions the better are the chances of winning

 

-          Almost close to the wordings of a winter Olympic athlete

Tuesday, February 23, 2010

"Not being able to do everything is no excuse for not doing everything you can."

“Not being able to do everything is no excuse for not doing everything you can.”

- Ashleigh Brilliant through Julie911

"Young lovers seek perfection. Old lovers learn the art of sewing shreds together and of seeing beauty in a multiplicity of patches."

“Young lovers seek perfection. Old lovers learn the art of sewing shreds together and of seeing beauty in a multiplicity of patches.”

- How To Make An American Quilt through Juli911

Saturday, February 20, 2010

Karakoram Highway

"In 1968, the Chinese, anxious to create an easy route to a new market for their manufactured goods, to limit Soviet influence in central Asia and to cement a strategic alliance against India, offered to supervise and fund the completion of the thirteen-hundred-kilometer route from Kashgar, in southwestern China, to Islamabad."

- Three Cups of Tea by greg Mortenson & David Oliver Relin


The pleasure to be found in submission to prayer

"...kneeling among one hundred strangers, watching them wash away not only impurities, but also, obviously, the aches and cares of their daily lives, he glimpsed the pleasure to be found in submission to a ritualized fellowship of prayer."

- chapter 6 titled "Rawalpindi's Rooftops At dusk" in "Three Cups of Tea" by Greg Mortenson & David Oliver Relin

Thursday, February 18, 2010

Why read only operations should also be in a transaction?

1.       The transaction can be marked as read-only and any accidental/un-intentional writes can be discovered and fixed

2.       The read operations can be wrapped with a “propagation required” (if a transaction already exists while performing the operation, use it. Else create a new transaction) there by the read operation can participate in write transactions.

Tuesday, February 16, 2010

Find unique, non-empty lines in a file

cat test.txt | sed '/^ *$/d' | sort | uniq # uniq requires its input to to be sorted

Monday, February 15, 2010

Visit to Zion National Park

Was on family road trip to Zion National Park over the long week end. Here are few of the snaps:




Wednesday, February 10, 2010

Detachment

“…in order to acquire anything in the physical universe, you have to relinquish your attachment to it… You don’t give up the intention, and you don’t give up the desire. You give up your attachment to the result… The moment you relinquish your attachment to the result, combining one-pointed intention with detachment at the same time, you will have that which you desire… because detachment is based on the unquestioning belief in the power of your true Self… Attachment… is based on fear and insecurity and the need for security is based on not knowing the true Self. The source of wealth, of abundance or of anything in the physical work is the Self; it is the consciousness that knows how to fulfill every need. Everything else is a symbol: cars, houses,… Symbols are transitory; they come and go. Chasing symbols is like settling for the map instead of the territory. It creates anxiety; it ends up making you feel hollow and empty inside, because you exchange yourself for the symbol of your Self…Only from detached involvement can one have joy and laughter. Then the symbols of wealth are created spontaneously and effortlessly… To be grounded in this experience (of spontaneous wealth creation) you have to be grounded in the wisdom of uncertainty. In this uncertainty you will find the freedom to create any-thing you want.” Seeking security does not work. No amount of security is enough. “ In ancient wisdom traditions, the solution to this whole dilemma lies in the wisdom of insecurity, or the wisdom of uncertainty. This means that the search for security and certainty is actually as attachment to the know. And what’s the know? The known is our past. The known is nothing other than the prison of past conditioning. There’s no evolution in that – absolutely none at all. And when there is no evolution, there is stagnation, entropy, disorder and decay. ..Relinquish your attachment to the known, step into the unknown, and you will step into the field of all possibilities…This means that in every moment of your life, you will have excitement, adventure, mystery. You will experience the fun of life – the magic, the celebration, the exhilaration and the exultation of your own spirit…When you are attached, your intention gets locked into a rigid mindset and you lose the fluidity, the creativity, and the spontaneity inherent in the field (of all possibilities) (that can orchestrate an infinity of space-time events to bring about the outcome that is intended).  The Law of detachment accelerates the whole process of evolution. When you understand this law, you don’t feel compelled to force solutions. When you force solutions to problems, you create new problems. But when you put your attention on the uncertainty, and you witness the uncertainty while you expectantly wait for the solution to emerge out of the chaos and the confusion then what emerges is something very fabulous and exciting. This …alertness – your preparedness in the present, in the field of uncertainty – meets with your goal and your intension and allows you to seize the opportunity. ” The opportunity contained within every problem that you have in your life. “Good luck is nothing but preparedness and opportunity coming together.”

Relinquish your attachment to the outcome

“Relinquish your attachment to the outcome. This means giving up your rigid attachment to a specific result and living in the wisdom of uncertainty. It means enjoying every moment in the journey of your life, even if you don’t know the outcome”.

 

1.       “I will make a list of all my desires. I will carry this list with me whenever I go. I will look at this list before I go into my silence and meditation. I will look at it before I go to sleep at night. I will look at it when I wake up in the morning.

2.       I will realize this list of my desires and surrender it to the womb of creation, trusting that when things don’t seem to go my way, there is a reason, and that the cosmic plan has designs for me much grander than even those that I have conceived.

3.       I will remind myself to practice present-moment awareness in all my actions. I will refuse to allow obstacles to consume and dissipate the quality of my attention in the present moment. I will accept the present as it is, and manifest the future through my deepest, most cherished intentions and desires.”

 

-          The Seven Spiritual Laws of Success by Deepak Chopra

Do more with less

“ … most of our energy goes into upholding our importance …  If we are capable of losing some of that importance, two extraordinary things would happen to us. One, we would free our energy from trying to maintain the illusory idea of our grandeur; and two, we would provide ourselves with enough energy to….catch a glimpse of the actual grandeur of the universe. [ from The Art of Dreaming ]”

 

3 aspects to achive do more with less

1.       Accept that this moment (people, situations, circumstances and events) is as it should be, because the entire universe is as it is. “When you struggle against this moment, you struggle against the entire universe.” So you should “accepts things as they are, not as you wish they were in this moment”. “When you feel frustrated or upset by a person or a situation, remember that you are not reacting to the person or the situation, buy to your feelings about the person or situation. These are your feelings and your feeling are not someone else’s fault. And if you can accept things as they are, you are ready to take responsibility for your situation...”

2.       “Responsibility means not blaming anyone or anything for your situation including yourself. Having accepted this circumstances, this event, this problem, responsibility then means the ability to have a creative response to the situation as it in now. All problems contain the seeds of opportunity, and this awareness allows you to take the moment and transform it to a better situation or thing” “Reality is an interpretation. And if you choose to interpret reality in this way, you will have many teachers around you…” Your situation is “precisely the one you need in your life at this moment. This is the hidden meaning behind all events and this hidden meaning is serving your own evolution”.

3.       Remain defenseless – relinquish “the need to convince … others of your point of view.” In doing so, you will “gain access to enormous amounts of energy that have been previously wasted. When you become defensive, blame others, and do not accept and surrender to the moment, your life meets resistance… You don’t want to stand rigid like a tall oak that cracks and collapses in the storm. Instead, you want to be flexible, like a reed that bends with the storm and survives. ”

Spontaneous right action

“In every moment of our existence, we are in that field of all possibilities where we have access to an infinity of choices. Some of these choices are made consciously, while others are made unconsciously.” ”…most of us – even though we are infinite choice-makers – have becomes bundles of conditioned reflexes that are constantly being triggered by people and circumstances into predictable outcomes of behavior.” “If you step back for a moment and witness the choices you are making as you make those choices, then in just this act of witnessing, you take the whole process from the unconscious realm into the conscious realm. This procedure of conscious choice-making and witnessing is very empowering.”

 

2 questions to ask before making a choice

1.       “What are the consequences of this choice that I’m making?”

2.       “Will this choice that I’m making now being happiness to me and to those around me?”

 

“There is only one choice, out of the infinity of choices available in every second, that will create happiness for you as well as for those around you. And when you make that one choice, it will result in a form of behavior that is called spontaneous right action.”

 

-          The Seven Laws of Spiritual Success by Deepak Chopra

That which doen't multiply through giving is neither worth giving nor worth receiving

That which doen't multiply through giving is neither worth giving nor worth receiving

-          The Seven Spiritual Laws of Success by Deepak Chopra

"Law of giving"

Also called “the Law of Giving and Receiving, because the universe operates through dynamic exchange”

 

-          The Seven Laws of Spiritual Success by Deepak Chopra

Non-judgment

“Judgment is the constant evaluation of right or wrong, good or bad. When you constantly evaluating, classifying, labeling, analyzing, you create a lot of turbulence in your internal dialogue. This turbulence constricts the flow of energy between you and the field of pure potentiality. You literally squeeze the “gap” between thoughts.”

“The gap is your connection to the field of pure potentiality. It is that state of pure awareness, that silent space between thoughts, that inner stillness that connects you to true power. And when you squeeze the gap, you squeeze your connection to the field of pure potentiality and infinite creativity.”

“Non-judgment creates silence in your mind.” Start your day with “Today I shall judge nothing that occurs” [ a prayer from A Course in Miracles ] “and throughout the day, remind yourself of that statement each time you catch yourself judging.” If it is difficult for a day say something like “For the next hour I shall judge nothing that occurs”

 

-          The Seven Spiritual Laws of Success by Deepak Chopra with my words (not in quotes)

Stillness

“One way to access” pure consciousness “is through daily practice of silence, meditation and non-judgment. Spending time in nature will also give you access to the qualities inherent in the field: infinite creativity, freedom and bliss.”

 

“Practicing silence means making a commitment to take a certain amount of time to simply be.” “If you never give yourself the opportunity to experience silence, this creates turbulence in your internal dialogue.

 

“Set aside a little time every once in a while to experience silence.”…”And every once in a while experience silence for an extended period of time, such as a full day…”. “Initially your internal dialog becomes even more turbulent. You feel an intense need to say something.” But as you “stay with the experience,” the “internal dialog begins t quieten. And soon the silence becomes profound.” “Then as the internal dialogue quietens, you begin to experience the stillness of the field of pure potentiality.”

 

Power of self

When our thinking is based on our objects in our experience, “we are constantly seeking the approval of others. Our thinking and behavior are always in anticipation of a response. It is therefore fear-based.” There is also a “need control things. The need for approval, the need to control things, and the need for external power are needs that are based on fear. This kind of power is not the power of pure potentiality or power of the self, or real power.” …”Power based on object referral …lasts only as long as the object of reference is there. If you have a certain (job) title or if you have a lot of money the power you enjoy goes with “ the title or money. “Ego based power will last only last as long as those things last. As soon as the title, the job, the money go away, so does the power”.

 

The true self, “which is your spirit, your soul, is completely free from those things. It is immune to criticism, it is unfearful of any challenge, and it feels beneath no one. And yet, it is also humble and feels superior to no one, because it recognizes that everyone else is the same self, the same spirit in different disguise.” .. “It draws people to you and it also draws things that you want to you.”…”It is the support of divinity; it is the support that comes from being in the state of grace. Your power is such that you enjoy a bond with people and people enjoy a bond with you”..”A bonding that comes from true love”.

 

-          “The Seven Spiritual Laws of Success” by Deepak Chopra with my words (not quoted)

Monday, February 08, 2010

There is my queen and what a privilege it has been to love her.

“True love. You know … when you’re old and you’re wrinkly and you’re sitting there gumming your food and your husband looks at you and even though he doesn’t see you very well anymore, he can see in your eyes the whole world: the future, the past, everything that was good and even things that were bad, and he can still say, ‘There is my queen and what a privilege it has been to love her.’”

- Prince Charming through Julie911

Don't be careless, but don't be too careful either.

“It’s easy to be confident when you have control of the puck. It’s very difficult to keep that confidence when you have to take whatever strange bounces life throws your way. Don’t be careless, but don’t be too careful either. You cannot be afraid to lose.”

- Jeffrey Nordling through
Julie911

School vs. Life

“The difference between school and life? In school, you’re taught a lesson and then given a test. In life, you’re given a test that teaches you a lesson.”

- Tom Bodett through Julie911

Time is tricky

“Time is tricky. You have whole months, even years, when nothing changes a speck, when you don’t go anywhere or do anything or think one new thought. And then you can get hit with a day or an hour, or half a second, when so much happens its almost like you are born all over again into some brand-new person you for damn sure never expected to meet.”

- Life is Funny through Julie911

You know we just don't recognize the most significant moments of our lives while they're happening. Back then I thought, well, there'll be other days. I didn't realize that that was the only day.

“You know we just don’t recognize the most significant moments of our lives while they’re happening. Back then I thought, well, there’ll be other days. I didn’t realize that that was the only day.”

- Field of Dreams through Julie911

Sunday, February 07, 2010

The right collaboration

Classes collaborate with each other to deliver their responsibility. In doing so, classes must make the least assumptions about the other classes. Too few assumptions, the collaboration will not be useful. Too many assumptions, the collaboration becomes a pack of cards (changes on one class will break the other class). More collaboration assumptions made is more coupling.

Interfaces help a given class to explicitly specify the assumptions that the clients can safely make when collaborating with that class. This set of assumptions must be balanced to be useful enough but not too detailed.

For example consider a StudentController class (a application UI class) that collaborates with JDBCStudentDAO class.

Class StudentController
{
JDBCStudentDAO dao = new JDBCStudentDAO();
public Student saveStudentUIAction(Student student)
{
return dao.jdbcSave(student);
}
}

In this case, StudentController makes assumptions about the implementation details of JDBCStudentDAO and public methods exposed by the implementation. This has the following disadvantages:
1. Any change in JDBCStundetDAO that violates any assumption made by StudentController will break StudentController.
2. Consider a HibernateStudentDAO which does *not* have the same public methods as JDBCStudentDAO (say HibernateStudentDAO only has a hibernateSave(Student) method and not a jdbcSave(Student)). Then replacing JDBCStudentDAO with HibernateStudentDAO will
a. Take more time to change StundentController
b. Cause more regression (every implementation assumption made by StudentController on JDBCStudentController that is violated by HibernateStundentController will lead to regression)

The solution: let StudentController reference a StudentDAO (an interface that explicitly states the assumptions that clients like StudentController can make). So we have

class StudentController
{
StudentDAO dao = new JDBCStudentDAO();
public Student saveStudentUIAction(Student student)
{
return dao.save(student); // Implemented by JDBCStudentDAO & HibernateStudentDAO
}
}

This solution solves ton of issues but not all of them. StudentController is still statically bound to JDBCStudentDAO.

To unit test StudentController let us suppose we write the following StudentControllerTest

class StudentControllerTest
{
public testSaveStudentUIAction()
{
Student student = new Student("Johnson");
Student savedStudent = studentController.saveStudentUIAction(student);
assertNotNull(savedStudent.getKey());
}
}

Let us assume that saveStudentUIAction can return null & throw a DuplicateStudentException. To simulate this scenario, JDBCStudentDAO must be exercised. But that is a test appropriate to JDBCStudentDAOTest, *not* StudentControllerTest. In short, StudentControllerTest must exercise and test only StudentController and not the classes that StudentController is dependent on. To achieve this, StudentController should be made to interface with a stub implementation of StudentDAO in the test cases and an actual implementation (like JDBCStudentDAO or HibernateStudentDAO) in the application. So StudentController should must not instantiate JDBCStudentController. But a implementation of StudentDAO must be handed over to it. This handing over of StudentDAO implementation can be achieved through Spring IOC (Inversion of control) or dependency injection.

So we now have

class StudentController
{
StudentDAO dao;
public Student saveStudentUIAction(Student student)
{
return dao.save(student); // Implemented by JDBCStudentDAO & HibernateStudentDAO
}
// This setter is invoked by spring IOC with stub implementation (that
// does what the test case wants to exercise) in test cases and
// actual implementation in the application
public void setDao(StudentDAO studentDAO)
{
dao = studentDAO;
}
public void getDao()
{
return dao;
}
}