Wednesday, December 16, 2009

JdkDynamicAopProxy ClassCastException

I am suddenly getting an error after some spring config was changed:

java.lang.ClassCastException: $Proxy47 cannot be cast to com.mycompany.MyConcreteClass

The code looks like this:
MyConcreteClass myClass = (MyConcreteClass) model.get("myClass");

I should add that MyConcreteClass was autoWired with spring elsewhere, and this setup used to work until something was changed in spring config.

This is happening because we are casting to the concrete implementation, what needs to be done is that the object needs to be cast to the interface:
MyInterface myClass = (MyInterface) model.get("myClass");

Also, the relevant spring configuration that causes this issue is:

<tx:annotation-driven manager="springTransactionManager" ></tx:annotation-driven>

In order for the proxy to not proxy the interfaces but concrete classes, you need to add the following attribute to the above directive:

Friday, August 28, 2009

Javascript: insert table rows / table body

If you write lots of javascript, there will someday come a time when you need to do one of the following DOM manipulations:
  • Insert a new table body, discarding the old one
  • Insert some number of table rows after some given row
This can be easily accomplished using a javascript library like jQuery, but there is a major downside to this: very bad performance! (for big chunks of html)

The reason for this is that a library like jQuery must preform all sorts of checks for all sorts of corner cases, such as checking if the html you are inserting contains script blocks and running them if your browser does not support script eval (IE6 - 7). It must clean each string before turning it into DOM objects.

For this reason, it is better to use plain javascript to write all the table manipulation functions, and make assumptions about the html you will be inserting (so you dont have to clean it). Here is a collection of such functions that i have used in production code. They are on average 2 or 3 times faster than using jQuery for the same insert.

Inserting table rows after a row

Example Usage:

You can insert 1 or more rows this way.

Replacing a table body with a new table body
Note: html does not include the actual tbody tag, just the rows and columns.

Another function that I often use is a helper function for replacing the table body to be used with jQuery's ajax functions:

Caveats of using these functions:
  • On browsers that dont support scriptEval, scripts that are inserted into the table body will not be executed upon insertion. You will need to deal with them yourself. I usually include them in a hidden input with a predefined ID, and then eval the value of that input after insertion.
  • Leading and trailing whitespace counts as a DOM node in IE, and will have weird effects if the html used in these methods contains it. If you are in charge of creating the html you insert, make sure it doesnt have unneeded whitespace between and around nodes.
  • I dont know if liveQuery plugin will know about these dom modifications.

Wednesday, August 12, 2009

Readynas: insufficient system resources exist complete requested service

Whenever i try to access my readynas nv+ shares from any computer, i get the following error message:
insufficient system resources exist complete requested service
All of my computers have plenty of free memory, hard disk space, etc. The problem is clearly the NAS. Googling leads me to believe that the NAS is returning a malformed response to windows and so windows gives this incorrect error message.

Moreover, i can still log into frontview, and ssh in.

Recently i was playing around with the NAS, i installed the addon that gave me root and installed some programs in the root directory /root. One of those programs misbehaved and filled up my root partition with some data. I sshed in and checked diskspace:
df - k
This showed me that the root partition was indeed at 100%. This is the problem, to solve it i needed to delete the big files that were taking up all the space. I used the method i previously wrote about to find the big files and remove them. After i was finished, root was at 46% full. i rebooted the NAS and the problem went away.

Friday, July 31, 2009

Intellij Tomcat Configuration Already Run

I have a debug tomcat configuration that i always use. Recently i started having a problem where after killing tomcat, and trying to run it again, i would get the error title "Configuration Already Run" which said "Run configuration 'tomcat local' has been already run. Do you want to redeploy it?". Clicking both yes and no buttons didnt do anything. Tomcat was not re-run.

(i am using tomcat 6, and intellij 8.1.3)

This seems like an intellij bug. Confirm that tomcat is really dead by running this at the command line:
taskkill /F /IM tomcat6.exe

If that doesnt fix it, proceed with the workaround:
Open the debug tool panel in intellij, and locate the close button, its a red X above the help button, which is a question mark, its on the left side of the screen. Press the close button to close the debug tool panel. Start the debug tomcat, it should run now.

Wednesday, July 08, 2009

Friday, June 26, 2009

checkbox margins in IE incorrect

By default, checkboxes have some margin and perhaps padding so they take up a bit more space than is needed. I needed to make some checkboxes take up the least amount of space possible, and the following css:

input {

didnt work in IE6 and IE7, while working perfectly in firefox (as usual).


Add the following IE only css:

<!--[if IE]>
<style type="text/css">
input {
margin: -5px;

This fixes the problem on IE6, and IE7, i dont know if IE8 has this problem or not.

Monday, June 22, 2009

Scroll bars not working and MSThemeCompatible

I recently had a problem where scroll bars were not working properly when windows XP was themed in the default theme (not classic). The scroll bar would not move if one used the arrows, or clicked in the area between the bar and the arrows. It could still be used by dragging it up and down.

The weirdest part of this issue was that the scroll bar worked normally in the windows 'classic' theme, but would seize to function correctly if you switched themes over to the ugly blue default theme.

I should also add that this scrollbar was part of a javascript widget where its position determined position of another DIV in the widget.

Solution (Hack):
Before i found the proper solution i came with a hack - on page load, add 1px to the width of the scrollbar and change its css left to -1px like so (this is jQuery):

$scrollY.css({"position":"relative", "left":"-1px"});
$scrollY.width($scrollY.width() + 1);

This seemed to work for some reason, the scrollbar works after this is applied.

I later stumbled on another solution that didnt smell like such a hack, but i am not sure what side effects it has other then making the scrollbar work. The solution is to set an a meta tag in IE only (because firefox has a bug with this metatag):

Monday, June 08, 2009

Tellurium: A Better Functional Test

Lets face it, Selenium has been around for years, it has been a choice tool for functional testing for many because it is free, has good support, and it works. Sure, it hasnt seen many updates as some would have liked, for example it didnt have firefox 3 support for a very long time. No big deal right? The latest beta supports firefox, and every one knows how to use it, the feature set has remained pretty much unchanged for years.

Why would you want to break the mold of functional testing and try something new? Well, until very recently, there hasn't been a compelling enough reason to do this. Fortunately, now there is: Tellurium.

Tellurium is another open source functional testing framework that picks up where Selenium has left off, and packs many new great features. The ideas themselves aren't exactly new: caching, UI modules, DSLs to describe the UI, Data Driven Testing, Using a JS framework instead of xpath, just to name a few. These ideas have been around for ages, but never before have they all been implemented in a mature functional testing framework.

This is the reason you should try Tellurium: new features, and the speed of their implementation.
I didnt know what i was missing with selenium until I implemented a few test cases using Tellurium's UI mapping Groovy DSL. This was a year ago, and I took a gamble in a fairly young testing framework based on Selenium server. Let me tell you, it has paid off. Not only are my tests written in a more Object Oriented way, but since upgrading to Tellurium 0.6.0 my tests run faster.

Lets look at some benchmarks.

Right now Tellurium is built on top of Selenium server, it translates its calls into one or more Selenium calls to do it job. Selenium uses xpath as its primary selector, while Tellurium also supports using the sizzle selector engine, in its jQuery selector.
The following graph shows the sizzle engine speed versus the default xpath engine using by Selenium. The blue is the xpath execution speed, and the red and yellow is jquery without caching and with caching, respectively.

As you can see, the speed up from using siggle is about 30%. I should add that this benchmark was taken on IE6, the slowest javascript platform that is still supported by most sites.

This speed up is going to allow you to have more time to do other things, or write better test cases. It can greatly speed up continuus intergration tests.

For more information about caching see this page. For more information about jquery selector see this page.

Another big performance booster in tellurium 0.6.0 is the bulk data retrival that is possible when using jquery. Every one who has used jquery knows about the convenience of $("table td").text(). Tellurium now performs such calls if you ask it for the text of of all cells in the table, whereas selenium will get you that data cell by cell with overhead for every call.

The above graph shows the awesome speedup that is possible with bulk data retrival. Notice the rightmost group titled "Bulk Data". The yellow bar representing Tellurium performance is so small that it seems like it may be missing. In this case, the speedup from gathering all the data in the javascript, and transporting it in one call gives you an incredible speed up of a few 1000%.

Upcoming performance Improvements in 0.7.0

One nice thing about Tellurium is the speed of development, and new features that make it into the build.

I have been keeping an eye on a performance improvement called "Control Group". The idea behind control group is to group together Selenium server calls into groups, execute them, and return multiple data sets. Since the biggest overhead comes from interacting with the server, this will be a big improvement over the current situation.

So, try tellurium out, you wont be disappointed.

Friday, May 15, 2009

HTML forms - Things you should know

This is a list of things every web developer should know about forms. I didnt know these things, and thus wasted many hours banging my head against the desk. Hopefully this post will save someone else that time.

1. Disabled inputs are not submitted.

The HTML spec defines that only 'successful' controls's values will be sent in the form on submit. disabled controls arent 'successful' and are not submitted. If you want to submit a disabled control you will have to either:
  • Enable it right before submitting the form, and then disable it.
  • Copy its value into a hidden input before submit

A form with only 1 text input will submit on enter in that input.

This is another little gem from the HTML spec that drove me nuts for a while. I couldnt figure out why the form was submitting on enter in an input type='text' when no key handlers were attached to the input, what was worse, my on submit validation was skipped. It turned out that if a form has a single input of type 'text' then pressing enter in this input will submit the form. To get around this you must:
  • Add another input of type text and hide it with css

Internet exporer will not submit a form if it contains a file chooser with an invalid file path.

This is a fun one. IE does some rudementary form validation for you, and if it finds that you have selected a file which does not exist, it will not let you submit the form. This by itself is not a bad thing, but what is bad, is that it does not let the user, or the programmer know that the form was not submitted. As a UI programmer, I want to have an error message if the form submition fails, but I have no way of knowing it. To get around this you must:
  • Validate the path yourself using regex, and try to find invalid file paths, and raise error yourself before IE
  • Copy the value of the filechooser into a hidden input, disable the file chooser, and deal with invalid paths in serverside validation.(wont work as pointed out)

Form submitted unexpectedly on enter

I have a form that would be submitted when i pressed enter in a text input field. It would skip over all my validation that i was doing in the input's onKeyDown callback function. I removed the onKeyDown event handler, and still the form would be submitted on enter. The input was not a submit type input so the submission was not expected.

This problem stemmed from the fact that the input box in question was the only text type input box on the form. The HTML4 spec states that if you have one input box of type text, pressing enter in this input box will submit the form!

I solved this by adding another input of type text with style="display:none" and a name:

<input type="text" style="display:none" name="dummyinput" value="" id="dummyinput" >

The reason for this hack being that I had bound on-enter handlers to the first inputfield of my own, and trying to prevent those would break my code also.

Monday, May 11, 2009

Eric's Roommates's Favorite Grilled Shrimp

  • 2T Samba sauce (red sauce from chinese places)
  • 2T Mirin (sweet wine-like stuff japanese cook with)
  • 1T Sesame oil
  • 1/4c Chopped fresh cilantro (dried does not suffice)
  • Juice from 1 lime
  • 1-2 pounds raw shrimp

Marinate 1hr max if at room temp, up to 3-5hrs if in fridge. Grill.

Thursday, April 30, 2009

Book Ratings

Another note to self. Book ratings:
Scale of 1 to 10.
R = reread

Dune 1 - 9
Dune (last one) - 10 R (might be difficult without rereading the entire series)
Alan Stelle - Coyotte 1 - 9 R
Alan Stelle - Coyotte 2 - 10 R
Alan Stelle - Coyotte 3 - 6
Jared Diamond - Guns Germs and Steel - 7

Monday, April 27, 2009

Microsoft LifeCam VX-1000 driver download

The Microsoft LifeCam VX-1000 driver is a pain to find on the internets:

Feel free to click on some of my ads if this post has saved you some headaches or time =)

This driver also works for
* LifeCam VX-2000
* LifeCam NX-3000
* LifeCam NX-6000
* LifeCam VX-1000
* LifeCam VX-3000
* LifeCam VX-6000
* LifeCam VX-5500
* LifeCam VX-5000
* LifeCam VX-7000
* LifeCam Show
* LifeCamCinema

Also, if you cant download the driver from the microsoft site, i am providing a mirror on my server for the download (please be gentle):


edit 7/28/09: Some people are having problems getting this webcam to run on windows Vista with 4GB+ ram. There is a hotfix for that here: (Windows6.0-KB933433-x64.msu)

Friday, April 03, 2009

Trim a string in perl

I am a perl noob and i need trim a string.

1) if i can modify the actual string:
sub trim {$_[0] =~s/^\s+|\s+$//g}

2)if i don't want it to modify:
sub trim {my $s = $_[0]; $s=~s/^\s+|\s+$//g;return $s;}

Wednesday, March 18, 2009

Multidimensional hashes in javascript

When i first started out with javascript i had no idea how to make a multidimensional array or a hash. Then, for a while i did not know how to use it properly after creating it. Now that i _think_ i know what i am doing i want share this very useful knowledge with the world.

First things first. A hash is the corner stone of all javascript objects and it is easy to create:

Each of the above is a perfectly valid way to create and access a hash. Quotes around the name allows you to use reserved words as the name, such as "function".

One thing to note here, is that the name must be either a string or a number, if its a number, you are better off using an array (if all your other keys are numbers too). This means that the name cannot be an object.

Now lets create a hash with more than one dimension. The function below is used to both init and add to a 3D hash.

We make sure not to access any elements that are undefined / not an object.

Now all we have left is a function to get values from our hash. This is not as straight forward as it may seem
The first statement is wrong, because if any of the 3 values passed in does not exist in the hash, you will try to access a property of undefined, causing an error. The second statement makes sure that each dimension exists before trying to access it, and finally returns either the value you want, or undefined.

Thats it!

Thursday, March 12, 2009

ST31000333AS disk size incorrect. 31MB

Problem: Today after rearranging the hard drives in my case, i noticed that my 1TB seagate drive was not coming up, instead i had a 32MB non-formatted drive. Checking the drive's hardware shows that it was indeed my 1TB ST31000333AS seagate barracuda. I tried changing the sata ports, and also ran it in an external usb enclosure. Drive size was reported as being 32MB by the bios and windows at all times. Seatools for windows did not show any problems with the drive.

Solution: I downloaded seatools for dos (direct link to eng iso), and burned it to a bootable cd. Booted to seatools and using advanced options set the drive capacity to MAX. rebooted, checked bios, drive was again 1TB. windows was able to detect and restore my drive letter, and files. I am happy.

Monday, March 09, 2009

Trip's Crazy Spicy Chicken Wings

This was really good. Yummy. Here it is:

there's not really a recipe per se. but they're pretty easy as long as you don't mind getting your kitchen greasy.

basically, you just start with chicken breasts cut up in to bite size cubes. then, the breading. i'm still searching for the best way to get the breading to be 
1) crispy and more importantly 
2) stay stuck to the chicken. 
for the party, i tried marinating the chicken in buttermilk and then dredging in flour.
i have made them since, however, by dredging the chicken in flour, then in an eggwash, then in store bought dried breadcrumbs. this worked much better.

to fry them, i just melted some vegetable shortening (supposedly better than oil because it can reach a higher temperature without smoking) in a pan (about 1/4 to 1/2 deep). then fried them on side #1 until brown, then turning and frying more once or twice depending on the size/shape/etc of the chicken piece. don't put too many in the pan at once or it will drop the temperature of the shortening. add more shortening if the grease levels are too low or if it seems to have lost some of its zip.

for the sauce, i went arount 1/3 melted butter, 2/3 frank's red hot for the "mild" (to me at least) version-- i don't think frank's hot enough on its own, so i add hot sauce (from the little bottles)-- any one that's really hot will do, since 99% of the flavor will come from the frank's.

i think that's it...

Tuesday, February 24, 2009

cross browser key events in javascript

this is a pure JS solution that lets you get the key code from an event, it works for all browser:

Monday, February 23, 2009

Functional Testing with Tellurium

I have recently discovered a new toolset for functional testing. Its called Tellurium and it runs on top of Selenium. Tellurium brings some cutting edge technologies to the table:
  • It's built fully in Groovy and takes advantage of DSLs, closures and other syntax sugar, while letting you code in java if you prefer.
  • It supports JUnit and TestNG unit testing frameworks
  • Instead of relying on xpath to describe the UI, it uses a UI mapping DSL
  • Comes with a firefox plugin for generating UI modules called TrUMP
Even though Tellurium is a fairly young project, it has very good support on the project forums. I have requested a few bug fixes and patches, and had the fixes committed within days. Anyway, the biggest advantage in using Tellurium vs Selenium is the UI mapping. Let's look at what a simple Selenium script would look like versus that same script written for Tellurium.

In this simple script we will click around the Tellurium project page. This is the Selenium version:

And now, the same test in Tellurium. Tellurium uses UI modules to describe the UI in a class that is separate from the test. Here is the UI module DSL:

And this is the Tellurium TestNG test case that uses the above module:

As you can see, the code looks very different. You will notice that the Selenium test is much shorter, but does not re-use UI elements like the Tellurium test does. Tellurium's UI mapping maps UI elements to very short element ids, which support hierarchical nesting, which can greatly simplify large tests.
Another big and obvious advantage to UI mapping is that if your underlying html changes, you would only need to modify the UI mapping DSL, and not need to worry about the actual tests. This is where Tellurium really shines for me.
Modifing the UI maps is really simple using the TrUMP Firefox plugin. TrUMP lets you point and click on the page, and builds out the nested UI module DSL for you.

What you will need in order to use Tellurium for your project
Useful resources for working with Tellurium and TrUMP firefox plugin
The best place to go to find support is the tellurium user group. Questions are answered very fast, and it is the main reason I was able to integrate Tellurium into my functional testing strategy at work.

Also, the Tellurium team has created two videos to help you get started with the project:
Tellurium Demo Video Part I: Tellurium project and TrUMP IDE
Tellurium Demo Video Part II: Create Tellurium Test cases

Tuesday, February 17, 2009

Building fast jQuery plugins

There are 3 million articles out there about making jQuery plugins, but most of them seem to focus on the basics. That is all well and good, but none of those articles will help you if you want to write a fast, responsive plugin that wont peg the CPU.

I will outline some techniques that have worked for me in building good jQuery plugins.

  • Cache your selectors. Not caching can be a real performance killer, once you select an element, cache it, if you plan to use it again. Even ID selectors should be cached. it will always be faster to reuse a cached selector than to ask the DOM for it. When it comes to plugins, you can hide the cached selectors in the main closure, and reuse them in the methods of the plugin.
  • Cache your state. It will always be faster to check if a boolean is true, than to check if a DOM element is visible. Forget about the DOM. Cache everything you will need access to, cache your modifications. DOM access is slow. I will exchange a few bytes of memory for a few ms of execution any day.
  • Use closures. If you dont know how to use closures, you must learn now. You wont be able to write a good plugin if you dont know when and how to use these. You should use the closure to hide all your config data, your cached selectors etc.
  • Dont use $.fn. if it doesnt make sense. Sometimes it makes sense to return something other then the jQuery object from your plugin. You can always pass in the 'this' the old school way as an argument. Sometimes it may be better to return an object that makes some methods from the closure 'public' and exposes some members. This kind of an object can be useful when writing unit tests, or if you want to provide a rich API without bastardizing $.fn.
  • Use functional inheritance. Use this and you will be get private/public members. This is important if you would like to have a clean API. I am talking about the functional inheritance from 'javascript: the good parts' book. See example of what i mean here.
  • Break things up into responsibilties. Let each method inside your plugin handle one thing. Do we need to recalucate something on window resize? Do we need to reload some event handlers after AJAX calls? Dont make one giant 'reload' method when you can have more specific methods that will save time.
  • Time and profile. I wish i had started doing this earlier. Use firebug's timing and profiling to see which portions of your code are slow, and optimize them.
  • Unit test. QUnit is jQuery's testrunner. Use it.
  • Test on a Pentium 3, in IE 6. This is my golden standard. If its fast here, you have nothing to worry about.

Sunday, February 08, 2009

Using jQuery with NYT JSON API

New York Times recently made public a great API that lets you search all of their articles from 1981 to present, and get the data back in JSON format.
I decided to use this API to add some relevant news stories to a site i have been working on. I was going to use jQuery to pull the data using $.getJSON() and shove it into some divs on my site.

I quickly ran into a problem. NYT is retuning plain JSON, not JSONP. JSONP is needed to do cross-domain JSON calls. jQuery will make a jsonp call if you add the following to the request url:
In the background, what happens is that jQuery replaces the ? with a function is creates, for example jsonp1229009. jQuery is expecting a response of:

but new york times is returning:

When jQuery pulls that response into a script tag, and executes in, i get the following error in firefox: "Invalid Label".

What i needed was a JSONP wrapper. Luckly, i have a friend who knows perl =) I asked him to write a service that will take 2 params: url and callback. Where URL is an encoded URL i am requesting, and callback is the param to wrap the response in. It worked out nicely, i can now use ANY JSON API and get JSONP back. This is the perl source:

Here is my crude and incomplete jQuery plugin that gets me a couple of articles with predefined fields and displays them on my site:

i call it like this:

Tuesday, February 03, 2009

Architect - Belgian Connection Lyrics

Lyrics of Belgian Connection from the 2004 album 'I Went Out Shopping To Get Some Noise' by Architect:

You wait and see if I'm not right.
Forty-eight hours and we'll have them aloft.
Then whoosh, up, over and whammo.
Forty-eight hours and we'll have them aloft.
Then whoosh.
There goes the enemy.
Obliterated, finished.
But what are they doing in the meantime?
What do you mean what are they doing?
Probably retaliating the best way they can.
It's a big waste of time, let me tell you.
We get the first licks so they can't do much.

You wait and see if I'm not right.
Forty-eight hours and we'll have them aloft.
Then whoosh whoooosh whooooosh
There goes the enemy.
Forty-eight hours and we'll have them aloft.
Then whoosh
There goes the enemy.
Obliterated, finished.
But what are they doing in the meantime?
What do you mean what are they doing?
Probably retaliating the best way they can.
It's a big waste of time.

Thursday, January 22, 2009

Realtek HD audio fails install

I am using SP3. When i try to intall realtek HD audio drivers the installer program tells me "install failed" and exits. Looking in device manager shows that i have no drivers installed. Its really annoying. SoundBlaster 16 was easier to get working!

The problem is that the MS Universal Audio Architecture (UAA) High Definition Audio also known as HD Bus drivers are either not isntalled or corrupt. Since i am running SP3, they are suppose to be there, so there is something wrong with them.

Step 1: Go into installed programs and uninstall the HD audio drivers. (if they are not there go to step 2) It will complain that a bunch of stuff will probably stop working if you do this. Ignore this warning, and all like it. I mean, who cares if some stuff breaks a little, you just want a 'multimedia PC in 2009'!

Step 2: Reboot your computer, You will need to reinstall the HD bus, the installer for that is called KB888111 and can be gotten here. Now, since you have service pack 3, you wont be able to install these, because windows thinks that you already have them. You need to trick windows into thinking you have SP2:

Step 3: Get into regedit (google it) and edit the following key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows\CSDVERSION
Set it to 00000200 from 00000300. Restart windows.

Step 4: Install KB888111, install your audio drivers. Reboot. Change the above key back to 00000300 (or dont like me, i mean, who cares?).

If this does not work for you, you should just reinstall windows, or, get a real sound card. Ive never had more problems getting sound to work then with this HD audio crap.
Also, i hear this will also work for other sound cards that use this UUA crap.

Thursday, January 08, 2009

Intellij port in use when starting tomcat

Recently, i started to get "Error running Unnamed: Address localhost:8080 is already in use" errors when starting tomcat through intellij. I checked netstat and nothing was using port 8080, restarting the computer didnt help. Interestingly, i could start tomcat from the command line on port 8080.

The same day, ESET NOD32 3.0.684.0 Antivirus was pushed on my box. It was the evil problem. I needed to disable the following things in it in order to get tomcat to launch again:
Setup -> Advanced -> Web Access Protection -> Uncheck "enable web access protection"
Setup -> Advanced -> Web Access Protection -> HTTP -> Web Browsers -> put [x] on java.exe and idea.exe

apply and reboot.