Monday, July 30, 2007

A dash of ruby

So, I've been playing with ruby on and off now for about 2-3 months.  After going through the pick axe book and a rails book I have pretty much set it down, mostly so I could focus on some Java issues at work. 

After our last release the Java work has settled down and now my interest in Ruby has once again returned, not Rails so much (However, I do think that the Java Community has a lot to learn from Rails though).  So here is the problem I had...

The company that I work for is completely in love with EJBs (2.1).  We use them with Spring so it's not as bad as it might sound.  Anyway to stub out an EJB it takes about an hour.  That is without any methods that actually do something.

So just in the event that you 're working on an application server that doesn't support JEE 5 or higher (I think that is the write acronym - they keep changing) here are the things you need (this is the spring version so there are a few extra interfaces in there to make it more fun):

Server Side Components

  1. The implementation that does something.  This should extend the interface in the client
  2. The EJB that implements the interface in the client and and Spring's AbstractStatelessSessionBean

Client Side Components

  1. The interface that defines what is supposed to happen
  2. The LocalHome interface this guy extends EJBLocalHome and simply has a create() method
  3. The Local interface this guy extends our interface and EJBLocalHome.  Oddly enough he has no methods (spring takes care of it for us).
  4. The Remote  interface he extends EJBObject and has the same method signatures as the interface (unless you don't want them exposed through remote objects)
  5. The RemoteHome interface that extends the EJBHome he has one method method called create()

 

So to hand code all of these things correctly takes me around an hour more or less depending on distractions.  So here is a fancy little ruby script that will prompt you for package names implementation names and a few other things and generate those guys for you.  Of course you will still need to configure the spring files and ejb-jar.xml file as well as whatever custom config files your appserver needs but it was a fun task to do with Ruby.

 

-Aaron

Friday, July 20, 2007

Life is like that I guess

So, my dad is dying...  Ok, so he is technically my step dad but he raised me nonetheless.  Many of my best (or worse attributes) come from him.

Anyway, last year he lost a kidney to cancer.  The one he has left is only working at 50% capacity (so that is 25% over all).   It turns out on top of all that he has a small spot of lung cancer as well...

So, yeah.  He's feeling fine now but we don't know how long that will last.  He is taking treatments for the bladder/kidney cancer several times a week now.  And the doctors are trying to figure out what to do about the lung cancer now.

On the flip side he has a Grand Daughter who is about to get married, his house is paid off, he has his first Grand Son who will bear his name that will be born in a few months...

Life is like that I guess... Really bad things happen at the same time really bad things happen... It's never all bad or all good. 

It reminds me of the Zen story of where this guy is hanging from a vine while a tiger is looking down trying to get him, a poisonous snake is working it's way up to get him, and 2 mice begin to chew the vine.  With death coming from all around some honey starts dripping into the hole and he realizes how great the honey tastes. 

 

Yeah, Life is like that I guess.

 

-Aaron

Tuesday, July 17, 2007

Buddha is as Buddha does

So, I started reading a new book a few weeks ago.  It's called "Buddha is as Buddha Does" by Lama Surya Das.

 

I haven't read any of Lama Surya Das's other books but this one is really great.  However, it is not a fast reader the concepts are really quite deep.  It's one of those books that has to be digested slowly.  I find myself only able to read a couple of pages at a time.  The concepts just sit in my mind and slowly soak in.  Here is a particularly great paragraph (from chapter 1 - Generosity):

"Whenever we consider our inner thoughts about anything, it's crucial to bear in mind that we can change them.  Being visited by negative or selfish thoughts doesn't make us bad people.  It just means we're conditioned human beings.  Nor do we have to be forever at the mercy of these thoughts merely because they occurred to us.  We can cultivate positive thoughts to replace them, thus skillfully and intentionally reconditioning and eventually deconditioning our energy and ourselves.  When the Buddha said, 'We are what we think,' He was asking us to take responsibility for our inner life.  That's the crux of why meditation and awareness cultivation are such vital practices in Buddhism.  They enhance our ability to manage more skillfully our own thoughts and feelings, including our thoughts about generosity -- a truth that, again illustrates how all the paramitas are interrelated and mutually supportive.

It is a great comfort for me to remember throughout the day that the thoughts that arise in my mind are not necessarily a reflection of who and what I am.  Irrational anger can be caught and defused before it explodes.

The teachings of the Buddha give me great hope...

-A

Monday, July 16, 2007

Cool Little JavaScript goodie

Oddly enough one of the best web sites I've been to in a while is my local gas company.  They have this fancy little clock that tells you what time it is, I finally took the time to figure out how they did it.  Here is the short version...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Clock </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
/* =================================================== */
// Display Date / Time
var ie = /MSIE/.test(navigator.userAgent);
/* =================================================== */
var addEvent;
if (document.addEventListener) {
    addEvent = function(element, type, handler) {
        element.addEventListener(type, handler, null);
    };
} else if (document.attachEvent) {
    addEvent = function(element, type, handler) {
        element.attachEvent("on" + type, handler);
    };
} else {
    addEvent = new Function; // not supported
}
/* =================================================== */
// Display Date / Time
function clock(){
    if (!document.getElementById){ return }
    this.start = function(){
        var self = this;
        this.date = new Date();
        // ===== Set Timezone & Daylight Savings ===========
        var day = this.date.getDay();
        var month = this.date.getMonth() + 1;
        var week = Math.floor((this.date.getDate() - 1) / 7) + 1;
        var dst = Number(month +""+ week +""+ day);
        // daylight savings range
        var start = 327  // March(3): Second(2) Sunday(7) = 327;
        var end = 1117    // November(11): First(1) Sunday(7) = 1117;

        this.offset = (dst > start && dst < end)? -5 : -6;
        this.zone = "CT";
        this.utc = this.date.getTime() + (this.date.getTimezoneOffset() * 60000);
        this.d = new Date(this.utc + (3600000*this.offset));
        // ===== Format Date ===============================
        this.day = this.addZeros(this.d.getDate());
        this.month = this.getMonthName(this.d.getMonth());
        this.yr = this.d.getYear();
        this.year = (this.yr<1000)? (this.yr+=1900) : this.yr;
        self.addSeconds();
        window.setInterval(function() {self.addSeconds();},1000);
    };
    this.addSeconds = function() {
        this.d.setSeconds(this.d.getSeconds() + 1);
        var hours = this.setMeridian(this.d.getHours());
        var minutes = this.addZeros(this.d.getMinutes());
        var seconds = this.addZeros(this.d.getSeconds());
        document.getElementById("dateTime").innerHTML = this.month+" "+this.day+" "+this.year+" "+hours+":"+minutes+":"+seconds+" "+meridian+" "+this.zone;
    };
    this.getMonthName= function(nMonth){
        var months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
        return months[nMonth]
    };
    this.setMeridian = function(hours){
        meridian = (hours < 12)? "AM" : "PM";
        return (hours > 12)? hours-12 : (hours==0)? 12 : hours;
    };
    this.addZeros = function(digits){
         return (Number(digits) < 10) ? "0"+digits : digits;
    };
}
addEvent(window,'load',startClock);
function startClock(){
    var theClock = new clock();
    theClock.start();
}
/* =================================================== */
//-->
</SCRIPT>
<STYLE TYPE="text/css" TITLE="">
t body { margin:0px; padding:0px; border:0px; text-align:center; background:#FFF; }
body { margin:0px; padding:0px; border:0px; text-align:center; background:#FFF; }
body * { font-family: Tahoma, Arial, Helvetica, sans-serif; }
#header ul.navitems  { position:absolute; top:8px; left: 165px; z-index:10; margin:0px; padding:0px; list-style-type:none; }
#header ul.navitems li { float:right; font:normal 10px Arial, Helvetica, sans-serif; color:#898688; padding-left:10px; }
#header ul.navitems li.stock { background:transparent url(../images/arrow.gif) no-repeat 0px 0px; padding-right:10px;  }
#header ul.navitems li#dateTime { border-left:1px solid #CCC; margin-left:10px; display:block; width:140px; padding:0px 10px 0px 10px; white-space:nowrap; }
#header ul.navitems li a { position:relative; top:2px }
</STYLE>
</HEAD>

<BODY >
<div id="header">
    <ul class="navitems">
        <li id="dateTime">&nbsp;</li>
    </ul>
</div>
</BODY>
</HTML>

Saturday, July 14, 2007

One More...

Releasing the Cows as told by Thich Naht Hahn

So one day the Buddha was sitting with a number of monks in the woods. They had just finished their mindful lunch and were about to start a Dharma discussion when a farmer came by. He was lost and said: “Dear Venerables did you see my cows passing by here?”, and the Buddha answered “No we have not seen any cows”.

“I have 3 cows, and this morning I don’t know why, all of them have run away. And this year the insects have eaten up all of our crops I think I’m going to die.” The farmer expressed his sufferings and worries.

The Buddha said “Dear friend, we have not seen your cows passing by here, you might try to look in the other direction.” The farmer thanked the Buddha and went away.

The Buddha turned to his monks smiling he looked at them and said “Dear Friends, do you know that you are happy people? Do you know that you are lucky people? You don’t have any cows to lose!”

So the practice here is to identify the cows that you have. The cows that you think you can not be separated from. The cows that you think are essential to your happiness but these cows actually cause you suffering.

Odds and Ends pt 6

And finally....

How far you go in life
Depends on your being
Tender with the young
Compassionate with the aged
Sympathetic with the striving
Tolerant of the weak and the strong

Because someday in life you will have been all of these

-George Washington Carver

Odds And Ends pt 5

A prayer heard from Jack Kornfield

Dear God,
So far today I've done alright. 
I haven't gossiped, lost my temper,
haven't been greedy, nasty, selfish or
over-indulgent.

I'm really glad about that.

But in a few minutes God I'm going to
get out of bed.

And from then on I'm probably going to
need a lot more help.

Thank you.

Odds and Ends pt 4

Traditional Zen Blessing on food

Innumerable labor's brought us this food
we should know how it comes to us

Receiving this offering
we should consider wether our virtue and practice deserve it

Desiring the natural order of mind
we should be free from greed hate and delusion

Odds And Ends pt 3

Let me not pray to be sheltered from dangers
but to be fearless in facing them.

Let me not beg for the stilling of my pain
but for the heart to conquer it.

Let me not look for allies in life's battlefield
but to my own strength.

Let me not crave in anxious fear to be saved
but hope for patience to win my freedom.

- Ancient Buddhist Prayer

Odds and Ends pt 2

As read by Gil Fronsdal

This has to do with a man who was an Abbott of a Zen monastery.
The abbot was a most unusual man, he seemed always to have
a smile in his eyes and a look as if he knew you better than you knew yourself.  He once told this story about himself...

When I was 13 my family would send me up to the mountains around the monastery to collect edible plants to be used for our evening meal.  This foraging trip was the only work that I enjoyed doing otherwise I tried every trick I could to avoid work on my family's farm.  I was still going to school but school had no interest;  for me and my ever present anger was a welcome barrier to learning anything the teacher was teaching.

Occasionally during my foraging trips I would pass by the monastery while the monks were out and about sweeping the leaves from the many paths.  The first time I saw the monks working I was mesmerized in watching them going about their work.

For many months afterwards I would often stop for awhile to watch them sweep.  They went about their work silently and with an efficiency that seemed effortless.  One day a monk walked up to me and asked what I was doing in the mountains.  Immediately I became defensive and scared I resented anyone who tried to get to know me, so instead of answering the question I countered
by asking him what he was doing.  The monk smiled and answered he had been told to sweep and that he was just killing time until he could return to his room for a nap.

As I walked home later in the day I thought about his answer and was glad that he did not seem any different than myself;  when I was required to do anything my heart was never in it and my attitude was that I was passing time until I could be excused taking a nap was certainly preferable.

The next day I passed by the monastery on one of my foraging trips and another monk stopped his sweeping and asked what I was doing.  again I resented the question, it felt like an intrusion, however this time I did not feel as scared, again I deflected the question by asking what he was doing.  He answered that he was doing extra work in hopes of being assigned to the kitchen which was always warm in the winter and always seemed to have one or two extra sweet rice cakes in the cupboard for cooks to nibble on without saying anything I nodded and left to continue my foraging.  The monks answer resonated with me since I too liked to be warm and eating sweet cakes was one of my favorite activities second only to sleeping.

The next time I passed the monastery a third monk asked me the same question.  I was surprised that  I wasn't offensive or resentful of being asked.  However again I deflected the question back to him he explained that he was sweeping as a spiritual discipline to help him overcome his anger.  Later as I walked the mountain trail with my bag of plants I felt a kinship with this monk like me he had
anger but I was perplexed that he would want to overcome it.  For me my anger protected me.  A week later I was again outside the monetary watching the monks sweep.  yet another monk came up to me when he asked me what I was doing I mumbled something about collecting plants I doubt he could hear me my
voice was so faint.  But I did muster up some strength to ask him what he was doing.  he replied that he was beautifying the monastery so that others may be inspired in their work of spiritual transformation before I left him I glanced down the well swept paths and realized that part of the reason I was compelled to
watch the monks sweep was that they seemed to be transforming the paths into something that made me feel peaceful.

The next time I stood outside the monastery watching the monks I was drawn to walk over to a fifth monk and before he could ask me what I was doing I asked him.   He looked at me with kind eyes and after what seemed like a long but quite soft silence he explained that he was sweeping to be of service to all who used the monastery in practicing this way he hoped to find the ultimate peace.  as I left the monastery that day I thought his answer strange because I didn't understand what he meant by service and peace  I certainly couldn't see how these had any value for me. 

The next time I visited the monastery for the last time I had an unfamiliar feeling as I walked up into the mountains.   Just before I reached the monastery I guessed  that i was looking forward to seeing the monks again I felt a warm glow of gladness in anticipation by what I would find.  When I arrived at the monastery I walked right up to the old monk who seemed absorbed by the sweeping.  I inquired what he was doing.   as he answered each of his words washed over me like cleansing water:  me? he said I am not doing anything, my ego was swept away long ago.  There is no I that does anything now the awakened life moves through my body my mind my heart and my mouth no one sweeps there are no paths to sweep and there is no dirt to brush away.  I was stunned by his answer and before I could respond he handed me the broom and walked away. 

I have been here ever since.

Odds and Ends pt 1

I'm cleaning up my hard drive today and found a few interesting things that have been accumulating here is the first one:

I go among trees and sit still
all my stirring becomes quite around me like circles on water
my tasks lie in their places where I left them asleep like cattle

Then what is afraid of me comes and lives awhile in my sight
what it fears in me leaves me and the fear of me leaves it
it sings and I bear it's song

Then what I am afraid of comes I live for a while in it's sight
what I fear in it leaves it and the fear in it leaves me
it sings and I hear it's song

By Wendal Berry

Saturday, July 07, 2007

Web Site vs. Web Application

I went to lunch the other day with one of the VP's where I work.  She had questions about our architecture, specifically why do we have so many licenses for WebSphere Portal; and if there was a relationship between the way we use EJB's.

I suppose that was an opportunity to vent a bit on the fact that our use of EJB's is completely excessive and a horrible idea.  It introduces such a huge level of complexity.

But I didn't.  My biggest concern is the complexity of EJBs and how they are very difficult to support.  However, with the advent of Spring the complexity is significantly reduced.  Troubleshooting can still be very difficult but... it is manageable.

So, I guess with Spring I am learning to at least view EJBs as a valid option in the J2EE architecture (Past experience has proven otherwise).

Another interesting conversation that came out of that lunch was the difference between a website and a web application.  I found a couple of articles supporting our VP's stance.  Funny, I've been working on web applications for close to 10 years and never really thought about the differences...  Maybe that explains why I stink at designing web sites but love architecting and writing applications.

-Aaron

Sunday, July 01, 2007

New stuff has been learned... Old things have become new.

So, all the problem I was working through yesterday have been figured out.  Kind of disappointing in some ways.  Sort of like reading a really good short story.  Great entertainment but so short, hardly worth the effort.

I mentioned, or alluded yesterday that I had been playing around with IDE support trying to get my dtd converted into beans.  One of the places I discovered while pursuing the NetBeans route was the Schema2Beans plug-in.  Although I never got it to work inside of NetBeans I was able to pull out the libraries of the plug-in and invoke them from the command line (and from Eclipse). 

So my big nasty DTD did have some "issues" you could say, that didn't really help anything but with a little help from an XML validator and some creative hacking I got it all working.  It works quite beautifully actually.  The XML generation isn't quite as cool as my decorator but it will work.

The funny thing is as I was writing the test case I recognized the code I had written was almost identical to the way IBM's generated beans work.  So there is a [small] chance in H3ll that the old applications can migrate to this version when IBM finally deprecates their dtd converter.

Not the weekend I should have had but it was a fun little problem that didn't turn out to be that difficult thanks to those fine fellows over at NetBeans.

-Aaron