Monthly Archives: January 2014

The only diploma that you’ll ever need

I was headed home late on Friday night when blue flashing lights suddenly appeared in my rear-view mirror.  As I pulled over to the side of the road, directly in front of a Chipotle restaurant, my thoughts alternated between despair and hunger. For you see, there were at least two traffic infractions that I knew that I had just committed.

  1. Speeding
  2. Not coming to a complete stop on a right-turn on red

But I did not fear. as my training as a magna-cum-laude graduate of the David A. Gallerizzo Traffic Ticket Avoidance Academy reflexively kicked-in.

“Remember your training, and you will survive”
-David A. Gallerizzo

As my sensei taught me, you must follow the path:

  1. Remain calm, focus your chi, and do not remove your hands from the steering wheel until after the officer approaches.
  2. Look as sad, exhausted, and pathetic as possible. This comes naturally to the master.
  3. Always respond in a respectful and honest manner.
  4. Resist all temptation to use social media during the encounter.

My conversation with the officer went thusly:

Me: Hello, Officer. How may I be of assistance to you on this fine, yet chilly evening?

Officer: (chucked). Well Sir, I think the question is how can I help you?

Me: I apologize officer, did I not come to a complete stop before making a right-turn on that last traffic light?

Officer: Do you know that the speed limit on Lee Highway is well-under 60 Mph? Do you know how fast you were going?

(At this point, I’m thinking…”oh, shit!” You see, the speed limit on that stretch of road is around 35 Mph)

Me (remembering my training): Honestly officer, I do not. You see, I just got off a frustrating 12-hour shift at work. My diet today has consisted of two slices of cold pizza and 7 cups of coffee. I’m just trying to make it over to that Chipotle across the street to grab some food, drive home, and then pass out from exhaustion.

Officer: Can I see your drivers license and registration please?

Me: (gulp). Of course, sir.

Officer: Do you have any weapons in the car?

(Now at this point, I had actually considered replying – “just my disarming wit, sir” Those who have known me for a long time know that I’m not making this up. It’s just the way that my brain operates)

Me: No sir!

(At this point, the officer retires to his cruiser to (presumably) pull up my driving record…I’m hoping that their records don’t include traffic camera infractions and that I won’t be seeing the judge who throws drivers in jail for each Mph that they were driving in excess of 30 Mph over the speed limit. My training returns. Be calm. Be confident. Be cool.)

The officer approaches…

Officer: You said you just got off work?

Me: Yes, sir! 

Officer: Ok, slow down. And have a nice night.

Me: Thank you officer!

(I start my car and make a slow, respectful turn into the Chipotle. Before digging into my 18,000 calorie salad, I thank my sensei in silent prayer)

 

Ext JS 4: Custom Word Counter Validation Type

One of my recent Ext JS 4 projects involved defining text areas with limits on the number of words that can be entered by the user.

I solved this problem by implementing a custom validation type (vtype) as illustrated below:

Ext.apply(Ext.form.field.VTypes, {
    wordlimit : function(v, field) {
        
        v = v.replace(/(^\s*)|(\s*$)/gi,"");
        v = v.replace(/[ ]{2,}/gi," ");
        v = v.replace(/\n /,"\n");
	    var words = v.split(' ').length;
        
        var numremaining = field.maxWords - words;
        
        var fieldLabel = field.getFieldLabel();
        
        fieldLabel = fieldLabel.substring(0, fieldLabel.indexOf('(') - 1);
        field.setFieldLabel(fieldLabel + " (" + numremaining + " words remaining" + " )");
        
        
        if (words <= field.maxWords) {
            return true;
        } else {
            return false;
        }
        
    },
    wordlimitText : "You exceeded the maximum number of words"
});

You can apply the vtype to a textarea as illustrated below:

 var config = {
   xtype: 'textareafield',
   fieldLabel: 'Describe yourself (50 word maximum)',
   labelAlign: 'top',
   allowBlank: false,
   name: 'description',
   anchor: '100%',
   resizable: true,
   resizeHandles: 's',
   vtype: 'wordlimit',
   maxWords: 50
 };
 
 panel.add(config);

You can play with the example by clicking here

Enjoy!