Thursday, December 23, 2010

after a request, page reloads 2 times and contains very little html

I just fixed a very strange issue in our application.

It went something like this:
User would click on a link that opened another page. This page would flash for a second, then another page would open containing just the string "2010".

The bug came from QA as being a regression related to recent development, so i started debugging in the code. There was nothing in the logs.

Then i opened firebug, went into "net" mode and persisted it. I saw my original request made, along with headers, and then another request made, this one had no headers at all.


document.write is evil. There was recently a change to the code which attempted to make the copyright year dynamic by replacing it with
document.write(new Date().getFullYear());
inside of a script tag. This alone wouldn't cause the issue, but document.write only works correctly if its called when the page is being rendered. If the page is rendered, it will overwrite the entire page with whatever its writing out. The issue was the the page the user was going to next, was gotten via ajax, and thus the script was called after the page was loaded, overwriting the entire page.

Oh the glory of being a programmer.

Saturday, December 04, 2010

Convert map to object in groovy

You need to convert a map into an object in groovy. There must be a better way then iterating through the map and setting all the properties in the object via reflection or otherwise. There is:

posting with syntaxhighlighter

I always forget the markup for posting syntax highlighted code. here it is:

<script class="brush: java" type="syntaxhighlighter">

thank me later

Monday, November 29, 2010

fixing java.lang.NoClassDefFoundError: javax/el/ELContext error

I got the error java.lang.NoClassDefFoundError: javax/el/ELContext  when i was trying to run a unit test.

el-api.jar needs to be in your class path. This is usually found in the tomcat/lib dir. I usually add everything in the tomcat lib to my classpath

select from two tables into a single column

delete from user where id not in (select from person a UNION select from merchant b)

Tuesday, October 26, 2010

No Hibernate Session bound to thread

I am converting an application that uses HibernateDaoSupport in the DAOs to use POJOs instead.
Each pojo now must autowire a sessionFactory in order to hook into hibernate.

I am getting the following error when i try to getSession() on my sessionFactory:

No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

add a OpenSessionInViewFilter to my web.xml and filter on * with it

Saturday, October 16, 2010

MLSPin google maps grease monkey script

I am looking at houses.
I am on the mlspin website which has addresses but no maps. I end up having to go look up these addresses in google maps.

This plugin adds a google map iframe on each listing page in mls pin.


Runs on:

Thursday, September 02, 2010

Babushka's Mushroom Soup

  1. make chicken or beef broth in a 2 liter pot
  2. add some rice (4-5 TBSP)
  3. let boil so that rice and potatos cook
  4. cut up some mushrooms and add them. wait until it boils
  5. combine ghee, 2 grated carrots and 1 chopped onion, salt, pepper, 1/4 tsp sugar. cook in the microwave for 2-3 mins
  6. when the halved potatos are cooked, take them out and mash them
  7. add potatos and ghee mixture to the soup
  8. take out some broth and put it in a cup, add 2 tablespoons of mushroom cheese, and mix
  9. add mushroom cheese mixture into the soup
  10. add bay leaf and greens


For those who are wondering what mushroom cheese is. here is a link to an example of it.
I found some being sold in a Russian store. You can buy ghee at whole foods

Tuesday, August 24, 2010

Waiting for things in javascript

Sometimes i need to wait for something to come into existence in javascript, and then do something with it. This is usually because another frame (shudder) is still loading and i need something in it. Also it helps with IE bugs where something should be there, but isn't because IE is taking a stupid long time to load it.


Use this utility function to create a check/act loop.

Friday, July 23, 2010

Make a Map from a list, perl style

Make a Map from a varargs list. Useful for iBatis parameterClass objects.

Thursday, July 22, 2010

Charles Schwab reconcile button in online banking

I made a grease monkey userscript to add a reconcile button to chuck schwab online banking checking site, so you can balance your checkbook more easily.

Bank of America had this feature on their online banking website and i missed it, so i added it to chucks site.

Get the script here:


I just noticed that the heading of this blog claims that it will also be about Catman, but there are no posts about him.
Behold Catman

How to autowire things in spring

In order to autowire something the following things must be true (that i know of)
  • - The object you are autowiring needs to be annotated with @Component
  • - The object that will contain the autowired object needs to come from the spring context, meaning:
    • - applicationContext.xml needs to have a bean definition of it
    • - the place where its is newed  needs to be replaced with the call to pull it from the WebApplicationContext

Thursday, July 15, 2010

intellij 9 autoscroll to/from source

Intellij 9's autoscroll to source/autoscroll from source is broken.

Sometimes it doesn't actually scroll to source when i view a file.
I don't know.
I don't know how to fix it either.
I wanted to blog about it so that maybe someone will find a fix and leave a comment.


Tuesday, June 29, 2010

IE8: content-disposition:inline, opens as download

We just had a pretty weird problem. Internet Explorer 8 decided to open some links as downloads instead of just navigating to the files as per usual. All normal browsers did not have this problem. I immediately checked the headers which revealed nothing out of the ordinary:

Server: Apache-Coyote/1.1
Cache-Control: public
Expires: Thu, 12 Jul 2012 19:13:38 GMT
Pragma: Thu, 12 Jul 2012 19:13:38 GMT
Content-Disposition: inline; filename="Recipe_Details_Attachments.htm"
Content-Type: text/html
Content-Encoding: gzip
Vary: Accept-Encoding
Date: Tue, 29 Jun 2010 19:13:38 GMT
Connection: close 
The Content-Disposition: inline; part tells me that the browser should not open this as a download.

My coworker who i now owe 6 beers suggested that because of IE's stupidity it is looking at the entire Content-Disposition line, and doing substring matching on first 'attachment' and then 'inline'. He was correct. IE stupidly saw this line as basically Content-Disposition:attachment;

The fix was to change the filename to something that did not include 'attachments'.

Monday, June 14, 2010

NPR's On Point Theme song

For years now ive been trying to figure out NPR's 'On Point' theme song. It sounds like a pretty cool song but they only play 10 seconds of it or so. I was listening to some Four tet today and figured it out the song is:

Four tet - Everything is Alright

 And sadly it seems like everyone else on the internet knows this already. i wonder why i failed at googling it so many times.

Wednesday, June 09, 2010

viewport resize event in IE

There is no viewport resize event in internet explorer, there is a window resize event, but its not the same. A window resize can mean that the size of the document within the view port has changed, for example 10 pages were added to the document.

I needed to know when the actual window was resized, so i wrote this hack to make that easy:

Friday, June 04, 2010

SQL: how to execute procs and run functions

In SQL client of your choice:

Thursday, June 03, 2010

Disabling an input is slow on IE

So we ran into a problem today where disabling a massive amounts of inputs was really slow in IE8. It would take several seconds to disable 200 inputs. Caching the DOM elements in an array did not seem to help much. Setting the actual html attribute was the slow part.
My coworker came up with a pretty great IE hack to speed up the process of disabling and enabling the inputs:

faking it turns out to be faster then doing it the real way.

Friday, May 14, 2010

Code Ericisms

I know some guy who writes pretty funny stuff in code. I am going to write some of it down for my own amusement.

returnStatus = "HTTP/1.1 500 Done blowed up\r\n"

Saturday, April 24, 2010

Migrating to syntaxhighlighter 2.1.x

I recently decided to upgrade to syntaxhighlighter 2.1 from 2.0 on my blogger blog. I thought it was going to be as easy as dropping in a new version. I was wrong, the TEXTAREA in which i was putting my code is no longer supported. instead SCRIPT tags are used to enclose the code! AHHH! I have about 40 code snippets on my blog and conversion seems very not-fun.

I started to hand convert some of the entries, to find that the new blogger post editor was also losing all of my tabs! This was going to be painful to do by hand..
Alas, i decided to try to do it with javascript, and it worked!

I pulled in the latest jquery into my template to ease the pain. Instead of the regular synataxhighlighter init i now have this:

Now, i dont need to hand convert all of my textareas to the new format, and the tabs are saved. Good deal!

Friday, April 23, 2010

Populate a DTO with mock data

Every so often i need to have a list of some simple DTOs in order to build a screen. The DTOs need to be populated from the database, but the query is not ready. Its somewhat painful to write dummy data creation methods over and over again.

Using Groovy(though not required), Spring and a bit of reflection i cover most of the simple DTOs.

To use, pass the class a list of which you expect

Wednesday, April 21, 2010

jQuery plugins: default options

jQuery plugins should expose their default options as a global hash. This is useful if you want to always override the defaults in the exact same way across your entire site.

Most good plugins already do this, for example jQueryUI plugins do this. Here is the plugin code that will let you expose your defaults as a global variable:

Tuesday, April 13, 2010

Tibetan Prayer Flag Cat Toy

I recently got a Tibetan Prayer Flag in the mail from the Dali Lama. I am not a Tibetan, nor do i pray, but my cat loves it. This is by far his favorite toy. Thank you Dali Lama.

Thursday, March 25, 2010

Bogdan Raczynski Samurai Math Beats Lyrics

i just wanna play checkers, one and together
i just wanna play checkers, one and together
learnin ninja-moves
karate battle stars we'll become
you and I together, let's learn ninja moves
lets learn to battle the galaxy for ownership of the kingdom
and whats to come
we'll do battle in outer-space and fight the bastardly citizens of who resist tem.bu....
you and i doin ninja moves
doin karate moves
doin black-belt style
black belt
lets just fight the forces of evil in our galaxy, together
with our light sabers
with our pistols and guns and sticks and bones and rabbits and dogs and poop and all we can find
la la la la.. waaa...
black belt
these are the kenji's samurai math beats yes uh, yes uh

Tuesday, March 16, 2010

jQuery: Detect Windows XP Theme

I started building a jquery dropdown widget, and i ran into a problem where i was not styling the dropdown arrow correctly because i developed the widget in the classic theme, but the xp theme styled widgets differently.

Clearly i needed to be able to assign different classes to my widget depending on the user's theme if i wanted the widget to look natural to that user.

The problem is that the user's theme setting is not something available through a javascript api call, nor is it in the user agent string. I used a javascript technique called feature detection to get this information. Here is how it works:

We create a button element and assign it background color called 'ButtonFace'. This is a special system color that is different depending on what theme you use. Next we need to get the computed color of the button element, and remove the element from the DOM. The idea is that a user in XP theme will have a slightly different colored button than a user in the classic theme.

I used some jQuery to make my life easier, but it would be easy to port this code to any other framework, or do it in plain javascript.

The code above plugin will create a new object $.support.windowsTheme which contains a name member that will be set to 'xp' if user is using the XP windows theme, 'classic' if they are using the classic theme, and undefined if they are using a custom theme, or another operating system.

To see this code in action look at this demo page

For further updates to this code please visit the jquery plugin page

  • This code does not check if the user is actually using windows, you would need to add that check yourself.
  • I have tested this code in firefox 3.6 and IE6,7 on windows XP. This code should really be also tested on Vista and Windows 7.
See also:
It has come to my attention that someone has already done this before

Wednesday, February 17, 2010

Pear Infused Vodka Recipe

I had a really great tasting pear infused vodka over the weekend. It was full of flavor and very sippable. I got the recipe of how it was made from the dude who made it:

- 2 pears
- 1 liter vodka
- 4 whole pods of cardamom
- 2 whole cloves
- 1 cinamon stick


Take 2 pears, chop them up into chunks (discard the core/stem, but leave the skin on). Put them in a bowl or other infusing vessel. Pour about 800-850 ml vodka over the top (I add extra because some of the vodka inevitably disappears. I guess the pears drink some and some of it evaporates. Annoying.) Cover the vessel and let it sit for a week at room temp. After a week, add 4 whole pods of cardamom, 2 whole cloves, and a cinnamon stick. Then, let it sit for another week. Strain, pour in bottle, chill, enjoy.

SQL: check if a query returned any rows

Sunday, February 07, 2010

Avocado Infused Vodka

I made some avocado infused vodka last week. It is good if you really like avocados. Like any infused vodka the taste is less vodka-y. Sipping a shot is now doable with a lesser quality vodka. I made the infusion by using 2 ripe avocado fruit over 4 days of infusion. 1 fruit was added and removed every 2 days.

The avocado taste is not very strong, neither is the smell. There is a slight creamy avocado taste to this infusion which is nice.

Wednesday, January 27, 2010

SQL: describe a select statement instead of table

QA asked me to put max lengths in input fields that would map to values that would eventually be inserted into the Oracle database. The problem was that these values were not going into a single table, but about 10 different tables, which were defined by a complex select statement. I didnt want to describe each individual table to find out the max lengths on the column names

Take the complex SQL statement and create a view with it:

Then describe the view, and drop the view when you are done with it.

Friday, January 22, 2010

IBatis: Iterate over multiple lists at the same time

I needed to verify if each record passed several rules, where each rule consisted of several flags and their values. The problem was complexity: I had 7 flags(which had 3 possible values) to check, and 1 to 5 rules per status. This could lead to some ugly and hard to test SQL.

Another problem was that you cant iterate over multiple lists at the same time (using the same index) in ibatis.

The solution was to use Ibatis's Iterate directive. I would iterate over lists of maps, where each map represented a rule, and each bucket of the map represented a flag and its expected value.

Those iBastis code ended up looking something like this:

and the parameter class had the following code:

This worked pretty well to abstract the flags and rules away from the iBatis sql and keep them all in the rules class.