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.

Solution:

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.

Solution:
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 a.id from person a UNION select b.id from merchant b)

Tuesday, October 26, 2010

No Hibernate Session bound to thread

Problem:
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

Solution:
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.

download:
http://userscripts.org/scripts/show/88186

Runs on: http://vow.mlspin.com/clients/

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

done!

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

Problem:
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.

Solution:

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: http://userscripts.org/scripts/show/82095

catman

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.
Why?
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.

Thanks.

Tuesday, June 29, 2010

IE8: content-disposition:inline, opens as download

Problem:
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.

Solution:
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.