Thursday, October 28, 2010

Real Men of Genius

REAL MEN OF GENIUS

Today we salute you Mr. Beer In A Giant Slingshot Man.
(Mr. Beer In A Giant Slingshot Man)
Some men use giant slingshots to send soft capsules of water to their far away friends, you send beer in solid containers.
(hey, send me some ice)
That's right, nothing says "Thanks for being my wingman" like a silver bullet concussion.
(feel like I was hit by a train)
Your combination of bravery and stupidity in being willing to stand behind that giant slingshot even though that beer can might come right back at you is truly to be praised.
(oooooooof, I think I cracked my sternum)
So load up another Old Milwaukee, and crack open an ice cold Bud Light, O'Master of Disaster. You might as make use of those Kidneys while you still have them.
(Mr. Beer In A Giant Slingshot Man)

Sunday, April 4, 2010

Happy Easter

I've never been a huge fan of Yams or Sweet Potatoes; my palate seems to taste them as a cross between a Potato (something I do like), and a squash (something I can force myself to eat because its "good" for me). Still, every now and then this root finds its way into a dish on a table where I dine (usually at the holidays) and I occasionally give it a chance. This Easter it was a Yam Casserole that I had to give a chance to for its somewhat unique and festive preparation.

Being short of marshmallows to top the Yams, one of the creative chefs in my house dug into the undistributed marshmallow peeps and threw a few in on top of the brown sugar. I suspect they didn't cover the entire dish just in case this turned into a culinary disaster.

The sugar coating on the peeps added an interesting texture to the dish which I wasn't really expecting. The marshmallow center of the peep remained almost fluid (more so than a marshmallow would have) and was another welcome surprise. Aside from that the recipe was pretty much what you would expect from Yams.

I found that I did enjoy this twist on the recipe more than the standard approach but its not to the point where this is a dish I would personally request. The reviews around our dinner table were also mixed with my daughter Brittany giving the big 'NO' vote on the peeps. If you are going to give this a try you might want to prepare a half/half dish just to see how well it is received.

Happy Easter!

Thursday, February 26, 2009

MySQL Delete Duplicate Records with Alter Table

So your application has been humming along live for a couple of months and suddenly you find that one of your database tables contains duplicate records. You review the table structure and find that it does not have a unique constraint defined on a field (or group of fields) that should be unique. So how can these duplicates be eliminated?

I've encountered many solutions for joining a table to itself to identify and delete groups of duplicates, but on large (1GB+) tables this will cause a full table scan (unless you run it in batches) and could be very difficult on a production server. Another option is process the deletions through a temporary table and then rename the tables. So after you've eliminated the duplicates you still need to add the unique constraint to the table; wouldn't it be better if you could handle everything in one shot?

MySQL includes an option for that in the ALTER TABLE syntax; ALTER IGNORE TABLE. The IGNORE option works a bit like 'INSERT IGNORE INTO table1 SELECT * FROM table2...' in that the first record remains in the table but subsequent records are silently dropped.

Here's a "fun" example of how this all works:
mysql> create table tp_test(
a int(11) auto_increment primary key,
b varchar(25) not null);
Query OK, 0 rows affected (0.05 sec)

mysql> show create table tp_test;
+---------+-----------------------------------------------+
+---------+-----------------------------------------------+
| tp_test | CREATE TABLE `tp_test` (
`a` int(11) NOT NULL auto_increment,
`b` varchar(25) NOT NULL,
PRIMARY KEY (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+---------+-----------------------------------------------+
1 row in set (0.00 sec)

mysql> insert into tp_test (b)
values
('Chickens'),('eat'),('corn'),('corn'),
('and'),('other'),('grains'),('grains');
Query OK, 4 rows affected (0.00 sec)

mysql> select * from tp_test;
+---+----------+
| a | b |
+---+----------+
| 1 | Chickens |
| 2 | eat |
| 3 | corn |
| 5 | corn |
| 6 | and |
| 7 | other |
| 8 | grains |
| 9 | grains |
+---+----------+
8 rows in set (0.00 sec)

mysql> ALTER IGNORE TABLE tp_test
ADD UNIQUE INDEX `test1` (`b`);
Query OK, 8 rows affected (0.00 sec)
Records: 8 Duplicates: 2 Warnings: 0

mysql> select * from tp_test;
+---+----------+
| a | b |
+---+----------+
| 1 | Chickens |
| 2 | eat |
| 3 | corn |
| 6 | and |
| 7 | other |
| 8 | grains |
+---+----------+
6 rows in set (0.00 sec)

Tuesday, October 21, 2008

This blog - An Introduction

So I created this blog a long time ago in an attempt to get a free GrandCentral account from Google. Sadly that did not work so I'm left with this blog called Random Ramblings, and no awesome GrandCentral phone service. I've decided to take advantage of this to just talk about whatever is on my mind at any given time.

Writings here will range from obscure bits of knowledge to in-depth technology information (if I ever get around to writing it up). I'll also talk about my adventures and mis-adventures in fatherhood and life in general. The first post looks like it will be about my new diet since that is really what everybody is asking me about right now.

If you like what I write, let me know, it will encourage me to write more, if you don't like it, don't read it and it won't bother me in the least. If you have suggestions for improvement I take critism well enough as long as you don't feel the need to write flames into the comments. If you have a subject you'd like me to consider for a future post feel free to suggest it.

Thank you, and happy reading