Rotten Code

Not just bad, it's rotten...

Monday, May 07, 2007

Spring Annotations

Sheesh, the trouble I'm apparently willing to go through to save myself a few lines of XML configuration! This story began with the promise that I'd never have to write any more <bean> entries in my beans.xml file... Spring Annotations would do it for me! Great! Even better, any @Entity objects would magically get loaded into Hibernate so I wouldn't have to add those stupid lines for every single class. Real progress!

Spring Annotations web site.

Spring Annotations is in a transitional phase, moving from java.net over to sourceforge. That causes problems, as much of the documentation has already been updated to point to sourceforge urls and classnames, but the actual source SVN repository is still on java.net (at least the one referred to in the docs). And as far as I can tell, they haven't been able to add their project to any public Maven2 repostitory, so anyone wanting to use Maven will need to check out the project, fix their pom file (it's missing a 'description' node) and publish to their own repository. To fix that for you, here's the xml so you can add it to your own Maven2-based project:

<repository>
<id>pelzer-util</id>
<url>http://util.pelzer.com/pelzer-util/repository/</url>
</repository>

<dependency>
<groupId>net.java.dev.spring-annotation</groupId>
<artifactId>spring-annotation-base</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>net.java.dev.spring-annotation</groupId>
<artifactId>spring-annotation-hibernate</artifactId>
<version>1.1</version>
</dependency>


Now that you've got Maven2 going, you're nearly there! In your beans.xml (or whatever you've named your primary Spring config xml, add the following:


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:sa="https://spring-annotation.dev.java.net/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
https://spring-annotation.dev.java.net/context https://spring-annotation.dev.java.net/context.xsd"
default-autowire="byName">

<!-- Enable autoloading for Spring Annotations -->
<sa:annotation-autoload />

...

</beans>


To enable Hibernate @Entity auto-discovery, change your sessionFactory in beans.xml to this:


<bean id="sessionFactory"
class="net.java.dev.springannotation.hibernate.AutomaticAnnotationSessionFactoryBean">


Now, you're ALMOST done, and if you just run as a regular java class, you're actually totally done. But to run inside Tomcat, you need to do one more thing, and that's to create a beacon file, named 'to.properties'. This file threw me off for almost 2 whole days as I tried to debug why Spring Annotations worked great while I was in Eclipse, and passed all our Bamboo unit tests, but wouldn't work inside Tomcat! Create an empty (doesn't have to be empty, just doesn't need anything) file and get it packaged. Since we're using maven, it should be 'src/main/resources/to.properties'. This file allows SA to load up and find all your annotated classes.

Now you're ready to drop your 'bean' entries from the xml, as well as your hibernate schtuff. The simplest, since we turned on autowire, is to just annotate a bean:

@Bean( name="myFirstBean" )

Hope this helps you out. If you end up using my repository, drop a comment! Cheers!

Wednesday, March 28, 2007

Super Mario Brothers in Lego

OK, so I still like to post silly videos:

Tuesday, March 27, 2007

Maven2 and Sun: (javax.transaction:jta:jar:1.0.1B)

I've been essentially working in isolation for the past two months as I draft out the outlines for the Lime Wire Store. One tool that I've picked up that I hadn't used before is Maven (2). Maven does a number of things for your build process, managing dependencies is the one I'll talk about here.

While working on my own machine, I got a basic framework for the store running, using Maven2, Spring, Hibernate, etc. Everything was running great. While I've been working on this, I was working to hire the team that's actually going to build this beast. The first wave of developers will be starting here over the next few weeks, so I needed to pull back and document the environment so that a new developer could come in and check out the code and have it actually compile. I figured that would be a nice feature.

So I set up a VMWare box with a fresh install of Eclipse, and began documenting. Add the AspectJ plugin. Add MyEclipseID. Add the Maven2 Plugin. Add Subclipse. OK, everything's there, let's start building... Maven began to chug away downloading the many dependencies it needed for compilation. Everything was going great until Hibernate started, and failed due to its requirement on JTA (java.transaction). Long story short, the jta.jar must be downloaded from Sun's site manually due to their license terms. What a pain!

But the real mystery is this: How did I ever use Hibernate on my original machine? I guess the answer must be that the Hibernate pom has changed and added the dependency, so it worked back then because it didn't need to pull the jta at all.

Well, I didn't want to have to run the manual download, then run 'mvn install', 1) because it's a pain and 2) because I don't even have a command-line Maven install on my box because I'm using the Maven2 Eclipse plugin! So I needed another solution, and the following change to my pom resolved the issue... Whether everything works or not is another matter, which will be followed up later!

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.1.ga</version>
<exclusions>
<exclusion>
<artifactId>jta</artifactId>
<groupId>javax.transaction</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jta_1.0.1B_spec</artifactId>
<version>1.1</version>
</dependency>

A change of direction for RottenCode

Alright, so this will be the first post here that isn't me pasting in a URL for a funny youtube video or other nonsense, and starting to use this domain for something at least a little bit towards how I originally envisioned it when I registered back in early 2005...

Back then I thought this would be a great place to post truly awful examples of the programming arts at my then-employer Sony BMG Music. The examples were numerous, the quality horrible. But they weren't really as funny as I would have liked, and really to me they were more painful than anything! An example I remember vividly was a mail utility written by a supposed senior java developer that had a signature that looked something like this (warning, may cause your eyes to bleed):

MailUtility.sendMail(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, int, String, String, String, String);

And then I found The Daily WTF, which was updated often, had exactly the same idea as I had, and had actual humorous content.

So no WTF's here, but hopefully some helpful examples as I bash my way through building the Lime Wire Store, a new-from-the-ground-up media store (like iTunes) that will cater to those who believe artists should be compensated fairly for their performances, and that MP3 is the right format for the future (ie Give the consumer what they want). With over 400 million downloads of the LimeWire client and 5-6 million users actively using the client at any time, our user base is pretty large, so the challenges for A) keeping most people happy and B) keeping the site from falling over are huge.

So you'll get to read about some of my mistakes, and some of my solutions, and just some things that took me a long time to track down, so that you don't have to next time.

Welcome to Rotten Code!

Monday, January 08, 2007

Lego Factory Builds Lego Cars (video)

This is an impressive video, to say the least. 2,000 man hours and €3,000 ($3,937) gets you a fully-functional Lego car factory, built of Legos.

Thursday, December 14, 2006

Hacked Teddy Bear (video)



Somewhat disturbing, but what kid wouldn't want an adorable teddy bear with robotic pincers to cuddle with? Future accountants, probably. Everyone should have one.

Friday, December 08, 2006

The Easter Bunny Hates You (video)

Monday, December 04, 2006

Octopus escaping through a 1 inch hole (video)

From the article:

Octopuses have an amazing ability to squeeze through tiny crevices, cracks and holes. My fall BIOS independent studies student, Raymond Deckel is investigating just how small a hole Octopus macropus can fit through as well as how long it takes them to squeeze through different sizes of holes. CAABS intern Rowena Day, NSF-REU intern Jared Kibele as well as teaching assistant Abel Valdivia help wrangle the 232 g octopus, Ray times it’s escape through a 1 inch hole while I shot video clips for later analysis. Location: Whalebone Bay, St. George’s, Bermuda.

Dr. James B. Wood - BIOS
The Cephalopod Page

Wednesday, November 29, 2006

Christmas lights 2006 #2 (Carol of the Bells) (video)

Christmas lights 2006 (video)

Christmas lights from 2005 (my favorite so far) (video)

Tuesday, November 28, 2006

Welcome to Japan. Nothing to see here.

Monday, November 20, 2006

Hitomi Pole Dance (video)



I didn't record this, but I'm sure these videos are going to start flooding the net, as Dead or Alive Xtreme 2 has hit the stores...

I picked up my very own Nintendo Wii this weekend. I was in upstate NY for a funeral, but I still managed to get my butt over to Target at 7:15am to get in line. I was #41 of 42 folks who got systems, so I guess I'm lucky... Though now I find out that the Nintendo Store here in NYC has a surplus of them! But I will always get to say I stood in line... For 45 whole minutes! I'm a warrior.

Now the wait for Super Smash Brothers begins!

Friday, November 17, 2006

Honda Element SC Autocross (video)

Tuesday, November 14, 2006

Dead or Alive Xtreme 2 Japanese TV Commerical (video)

Friday, November 10, 2006

AirWolf pimps out a Daewoo Lemans (video)

Thursday, November 09, 2006

Wii Factory (Wonkalicious video)




Monday, November 06, 2006

Dogs

I'm told this somewhat resembles me:


Wednesday, November 01, 2006

SEMA sideways: Honda's RWD Element drifter - Autoblog


Yes, this thing is ridiculous, but I love it just the same. I wish I saw this in person.
SEMA sideways: Honda's RWD Element drifter - Autoblog

Tuesday, October 31, 2006

Extreme Diet Coke & Mentos Experiments II - The Domino Effect

251 bottles of Diet Coke and over 1,500 Mentos mints. In Experiment #137, they did a mint-powered version of the Bellagio fountains. This time, it's one giant Coke & Mentos chain reaction.

Not as exciting as I'd hoped, but still pretty fun.

Friday, October 27, 2006

Tampon Halloween Crafts



Look and marvel. If I hadn't given away the surprise in the title, would you have guessed these were made by Aunt Flo?

via Tampon Crafts

Pumpkin Burger

Saw this pumpkin burger on the net and wanted to post it... I like the pumpkin seeds on top... Projects like this make me happy.

via Bits & Pieces

Monday, October 23, 2006

Dead or Alive Xtreme 2 TGS Trailer

Dead or Alive Xtreme 2 (DOA Extreme 2) Tokyo Game Show trailer. Full trailer with all girls doing various dopey things.

Lei Fang Pole Dance (Dead or Alive Xtreme 2, DOA extreme 2) Video

High-res version of Lei Fang doing a pole dance. This is totally a sports game. Yeah!

Wednesday, August 16, 2006

My MediaGate MG-25


Bought the MediaGate MG-25 media player for the minivan... The van only had VHS, but it also had an aux-in. The MG-25 was only about $70 shipped and I dropped in a 20 gig 2.5 inch hard drive I had laying around (that smells vaguely of coffee for some reason).

Kids love it so far, they have their own remote so they can choose what to watch.

One of the reasons I got this was that it can play DVD backups (VOBs or ISOs), but the resume feature doesn't yet work correctly for these. Each time you shut down the car, when you power it back on the DVD resumes at the beginning. The kids were good sports about this, but I found it unacceptable. So now I'm reconverting the kids movies for this to Xvid AVIs. Those resume correctly, but obviously you lose menus and special features. But the kids don't care.

Also, you must explicitly hit 'stop' or 'power' in order for the MG-25 to save its resume point. It does not periodically write its spot, so if you forget and simply disconnect power, you'll resume from the last point you resumed from... ie, you watch 30 minutes, hit 'stop', watch another 30 minutes and power off, when you resume you'll be 30 minutes into the film, not 60.

I'm going to write to the company, but I don't think English is their comfort language. Still a great little player, and hopefully it will withstand its travels!

Tuesday, August 15, 2006

Verizon Fiber Optics (FiOS)

Almost got my panties in a bunch there... A bunch of bogs started posting about Verizon FiOS (fiber optic intarweb and teevee) and I got all excited. I LOVE BANDWIDTH. But it's not available in my area (Greater NYC) yet, and the site doesn't tell me when it will be. Give me something, Verizon. Ehhh, too bad. I've been thinking of going to cable modem anyway. DSL is... unimpressive at residential speeds. I miss my Covad at my old place... 5 static IPs, 3.0Mbps dedicated to me! Sigh.

"I'm a Wii and I'm a PS3" Movie

-"I'm a Wii and I'm a PS3" Movie: "Watch this hilarious spoof on the Apple vs Microsoft 'I'm a Mac, and I'm a PC' ads."