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.

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

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

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

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

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

Caveats:
  • 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:

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

Directions:

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

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

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

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

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

Wednesday, December 16, 2009

JdkDynamicAopProxy ClassCastException

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

Solution:
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:
proxy-target-class="true"