Thursday, July 31, 2008

Randomizing a recordset

One very common request on websites is to show a random few items from the database. Historically I have done some very elaborate coding to accomplish this. I've even gone to the extremes of allowing a weighting system on the entries so some records will come up more often than others. If true equal randomization is a must, such as in an advertising package, this would still be necessary.

At least 90% of the time a simple method that appears random is going to make everyone happy. Below I have pasted the very simple code which will allow you to get a random selection from mysql or ms sql.

MS SQL
order by NewID()
example: select top 5 * from Videos order by NewID()

mySQL
order by rand()
example: select * from Videos order by rand() limit 5

Using either of these puts all the work on the database.

Monday, July 21, 2008

Batman 'The Dark Knight' review

After the last Batman movie I was expecting quiet a bit out of the newest movie. I've always admired Heath Ledger, and I think he did a great job as the Joker. The acting was good. The special effects were great.

When watching any "hero" movie I am accustomed to a certain amount of suspension of disbelief. Vests that not only stop bullets but also stop the kinetic energy. People falling 20 stories are saved by being stopped instantly on a rope. But Batman tried to push this too far. The joker and crew were able to set explosives anywhere the wanted, in any size without being caught. Boats with large security details had the entire hold full of explosives. A hospital appeared to have a small bomb in every room. What do you say to the nurses as you wander from room to room planting C-4 explosives?

After we passed the 2 hour mark I was just ready for it to be over. I think the movie was worth seeing, but I would recommend waiting for the DVD.

Friday, July 18, 2008

Land of the Free?

About a month ago we noticed several of the shingles on our roof had slipped out of place. Mid way through putting a new roof over top the old one security shows up at my house and informs me we need permits. I give him a look like he told me Santa Claus is coming to town and explain that I am repairing damage to my roof and figure he will go away.

Instead of going away he tells me the county government requires a license for any roofing work. He leaves and I come inside to call the county. I talk to a young lady on the phone and explain the situation. My roof was damaged, and I am putting the exact same color of shingle over top the old. She tells me that I do have to put in an application for a permit. It is at this point that I actually begin to believe that no matter how absurd it sounds, it is true.

The permit was only $10, plus a stamp and about an hour of my time. The issue I have is that I need to get permission from the government to repair my own house. A repair that, if delayed, could have cost me tens of thousands of dollars in interior damage had water gotten through to the interior.

Property tax is rent you pay for the land the government owns. You have to pay the government for the privilege of any improvements, or even repairs, you make. Once you make improvements they come out and increase your rent. The government can kick you off that land at anytime so they can build something else there. You can now be locked up without any reason given, or even notification sent to your relatives, if they suspect you of ties to terrorists. Which really means they can do it as long as they are willing to say they suspect you of such ties.

Land of the free? Really?

Thursday, July 10, 2008

Raspberry Season


When I first moved in there were a few scraggly raspberry bushes at the corner of my house. They really are not very decorative and I honestly kept meaning to cut them out, but I am basically lazy and never did. This year I was actually going to do it and noticed a bumper crop of berries coming on so I just cut everything but the berries out of the spot two months ago.


In the last week I have gotten 8 cups of berries from this small patch. I've done a lot of berry picking in my life and I've never seen so many berries from such a small patch. I will really hate cutting them down before I sell the house next year.


The first 4 cups of berries I turned into the pie on the left. My parents gave me the recipe and it tasted heavenly. The pie was a little more runny than I would have liked. I am not sure if I needed a little more flower or a little more cooking time, but I still rate it as a success.



Over the past few months I've been playing with Crumb Bar recipes. I started with a blueberry crumb bar recipe from AllRecipes.com. These were delicious out of the oven, but the next day they were a bit bland. On the right is the picture of my newest version of the recipe. I will not be altering the recipe any further as it came out perfect. The pictures are not the best as it was late with bad lighting and I was playing my So You Think You Can Dance Drinking Game by the time they were cool.

Tuesday, July 1, 2008

Pandora - the Music Genome Project

I spend anywhere from 40-80 hours a week at my computer with my dog for company. She's a good dog, but not much of a conversationalist. Thus, I spend a lot of time listening to music. I discovered Pandora about a year ago and think it is the best online streaming music site. It is free to use, and the advertisements are well done and non-invasive.

One nice feature is that it was built intelligently from a buffering standpoint. It attempts to buffer an entire song ahead. I've actually lost my internet connection for a couple minutes and not had my music miss a beat.

The best feature is how a user creates custom stations. Many years ago they started the Music Genome Project. They took songs and defined hundreds of attributes for each song. These attributes are things like "Subtle use of vocal harmony", and "Groove based composition". When you log into Pandora you create a station and enter a song or group you like as an initial seed. Pandora begins to play music based on this and you can give a particular song a thumbs up or thumbs down. Pandora tracks this information and refines the play list until you rarely get a song you do not like.

In the left navigation of my blog you can see I included a section with my Pandora stations. You might find that one of my stations is a good starting point for you.