Friday, August 13, 2010

DBIx::Class join, prefetch

Over the last 15 years I've joined two database tables into a one-to-many relationship about a billion times. But I've never had any software let me loop the left table and right tables separately before. Turns out this magic has been in DBIx::Class for several years.

Runnable demo.

When table 'foo' is in a one-to-many relationship with table 'bar', you can:

my $foo_rs = $schema->resultset('Foo')->search(
{},
{
join => 'bars',
prefetch => 'bars',
order_by => 'me.id',
}
);

while (my $foo = $foo_rs->next) {
printf "%s\n", $foo->id;
if (my $bar_rs = $foo->bars) {
while (my $bar = $bar_rs->next) {
printf " %s\n", $bar->desc;
}
}
}
Output:

1
2
aaa
bbb
ccc
3
Still one SQL statement against the database (fast!). Much prettier than ugly manual de-duping of redundant columns.

Saturday, August 7, 2010

quibids.com, you're my hero!

Holy crap! The people running this auction site must be making a fortune!

Quibids.com is an auction site where you pay to bid. Each bid costs $0.60 and raises the bid price on the item by 1 penny. Items start at 1 penny. I'm watching the bids on a $1600 laptop climb from $50 up to $73 and beyond. A $1600 laptop for only $73? What a bargain, right? Yup, if everyone else would stop bidding and let you win. Hint: They won't.

It says right here that this item "recently sold for $422.59." Someone saved $1200! Good for them! In the process, quibids.com raked in $25,355.40 (42,259 * $0.60) in fees on the sale of a single $1,600 laptop! HOLY CRAP!

Capitalism rules! I need to launch one of these sites and only charge $0.50 per bid!



Update: This ad says "Honda Civic Sold for $2,642!" There's another $158,520 in bidding fees for Quibids.com. Also, for the company spin: Does QuiBids make excessive profit on their auctions? (Of course not! We have to pay rent and stuff! -grin-)

Wednesday, July 28, 2010

OS X "Address Book" sync fail to Google

I assumed this would all "just work" in 2010, but I guess I was wrong. My toys:

OS X 10.6.4 MacBook, OS X 10.6.4 Mac mini
Mail, Address Book, iCal
Google
Mail + Contacts, Calendar
HTC Evo 4G (Android 2.1) mobile phone
Mail, People, Calendar
My email and calendar sync everywhere. Woot! OS X Address Book, however, completely fails to sync to Google. There's a checkbox in Preferences for "Synchronize with Google" that appears to work, but every time I quit Address Book and restart it, that box is no longer checked.

Apparently lots of people spend years fighting this stuff, or spend $100/year for Apple MobileMe. I prefer just giving up on Address Book, satisfied that almost everything Just Works.



Update: Sheesh. OK, so the sync does work even without MobileMe if you work your butt off every time. e.g.: (1) Change a contact in Address Book. (2) Open Preferences, check the "Sync with Google" checkbox (yes, you have to do this every time you open Address Book. Somehow it remembers your username and password though) (3) Right click the MobileMe sync in the top menu bar. "Sync now". (4) Log out of Google Mail. (5) Log back into Google Mail. Done -- your contact change is in Google.

Tuesday, June 8, 2010

Adventure in Serenia

I wonder if my parents or my brother remember me playing this classic in the basement in Livonia, Michigan on our IBM PCjr. I sure do. One of my earliest computery memories.

Tuesday, May 18, 2010

Deadgirl

From: Jay Hannah
Sent: Tuesday, May 18, 2010 12:36 PM
To: Andria Hannah
Subject: movie

Oops, I forgot. Put 'Deadgirl' somewhere Zach won't find it. Not appropriate.

Thanks,

j


From: Andria Hannah
> Okay. Did mention to him on Sunday to watch the other movies
> we rented and that one was a flat out no from him. So we
> lucked out.

From: Jay Hannah
> I'm very disappointed in your judgment that you let ME watch it.
>
> My mother will be calling you.

From: Andria Hannah
> That bad huh? Was is scary?
>
> So to add to my “Do not let Jay do…..” list, I will include
> looking at the dollar shelf.

From: Jay Hannah
> Um, no it was... um...
>
> Let's just say I don't want Zach thinking about zombie sex
> slaves.
>
> waaaaaaaay off the "how to treat women" planet for any 13
> year old.
>
> Or 34 year old.

From: Andria Hannah
> Got it. Maybe that should be back in Family Videos
> “secret room”.

From: Jay Hannah
> Well, it's definitely not porn.
>
> It's just... um...
>
> Give it watch and you tell me what it is. :)
>
> In it's defense, the only guy that lives to the end is
> the only guy that doesn't use the dead girl as a sex
> slave... So I guess it should be in the romantic comedy
> section. :)

Thursday, May 13, 2010

Catalyst and Quality Assurance bliss

I've fallen in love with website testing. Again. Catalyst and WWW::Mechanize are awesome. The scenario below takes several monotonous and error prone minutes to QA as a human, or several seconds as a series of automated tests. New feature + test coverage == Joy!!

$work[0] test count is back over 3,000 again and Hudson is keeping an eye on everything for us every 30 minutes. Very cool.

$ perl -Ilib t/avail_book_SG-autoenroll_cancel.t
[debug] Statistics enabled
1..21
ok 1 - GET http://localhost.omnihotels.com/
ok 2 - Content-type:
ok 3 - title>
ok 4 - Select a City
ok 5 - No errors
ok 6 - !- BEGIN: om/rr/RR1_2.tt -->
ok 7 - !- BEGIN: om/rr/RR1_3.tt -->
ok 8 - !- BEGIN: om/rr/RR1_4.tt -->
ok 9 - !- BEGIN: om/rr/RR1_5.tt -->
ok 10 - Res ID(s) are 40002401426
ok 11 - SG number 62379458 created by sg_auto_enroll checkbox
ok 12 - click Activate Account Password & Preferences
ok 13 - !- BEGIN: om/sg/SI4.tt -->
ok 14 - submit SI4 (form fields should have been defaulted for us)
ok 15 - !- BEGIN: om/sg/SI3.tt -->
ok 16 - submit SI3
ok 17 - !- BEGIN: om/sg/SG6.tt -->
ok 18 - GET /?Phoenix_state=clear&pagedst=RR2
ok 19 - !- BEGIN: om/rr/RR1_5.tt --> Retrieved 40002401426 for cancellation
ok 20 - Click 'Cancel Reservation'
ok 21 - Reservation 40002401426 cancelled
------------------------------------------------
$ cat t/avail_book_SG-autoenroll_cancel.t
use Test::WWW::Mechanize::Catalyst 'Phoenix';

use strict;
use Test::More tests => 21;
use FindBin qw($Bin);
use lib "$Bin/lib";
use phoenix_test;

my %SI3_args = (
loginName => ('jhannah' . time),
password => 't123',
EMAIL => 'jhannah@omnihotels.com',
Question => 'CITY',
Answer => 'Shmomaha',
);

my $mech = Test::WWW::Mechanize::Catalyst->new;
my $pt = phoenix_test->new(mech => $mech);

my $cro_resno = $pt->book(sg_auto_enroll => 'on');
my $msg = qr/Your Select Guest number is (\d+)/;
my ($sgnum) = ($mech->content =~ $msg);
ok($sgnum,
"SG number $sgnum created by sg_auto_enroll checkbox");

$msg = 'Activate Account Password & Preferences';
$mech->follow_link_ok({text => $msg},
"click $msg");

my $msg = '!- BEGIN: om/sg/SI4.tt -->';
$mech->content_contains($msg, $msg);
$mech->submit_form_ok({},
"submit SI4 (form fields should have been defaulted for us)");

my $msg = '!- BEGIN: om/sg/SI3.tt -->';
$mech->content_contains($msg, $msg);
$mech->submit_form_ok({
with_fields => \%SI3_args,
}, "submit SI3");

my $msg = '!- BEGIN: om/sg/SG6.tt -->';
$mech->content_contains($msg, $msg);

$pt->cancel($cro_resno);

Saturday, May 8, 2010

Science can answer moral questions

Listened to this on my iPod yesterday. Watched it on YouTube today. Very powerful if you let it sink in.

Science can answer moral questions

I like this piece a lot more than when he spends most of his energy attacking religion. I already agree with him on most of that material, so it's far less interesting to me and too aggressive for my comfort.

Far better to focus on positive changes in science rather than "that over there is patently stupid."

Thursday, April 29, 2010

Wind tunnel workplace

Arrived at work this morning and the front doors were locked (odd) and one of them was propped open with a sign (odder). The lobby was filled with a loud metallic rattling / vibration sound. I stared up towards the noise as other slightly confused people wandered around also wondering what was going on. Both elevator doors were slightly open even though the elevator cars were not on this floor. (Someone could have fallen into the shaft if they decided to try a little?)

An annoyed management type appeared and told us that the power company had done something this morning (this wasn't our fault, she assured us defensively) which knocked out the "air handlers." She didn't seem to know really what that meant and wasn't in the mood to try to explain anything to the likes of me.

Attempting to head to my office the next security door had a green light (unlocked), but still wouldn't open. It took some serious tugging to gain entry. The hallway was like a mild wind tunnel. Not enough pressure to really effect people, but plenty to effect the doors on both ends. One held shut, the other held open by the pressure. In the next hallway, directly connected to my office, was more whistling of air in a hurry to get elsewhere. Many office doors propped open with trash containers. Home remedy attempts to lessen the noises?

Outside there's only a slight breeze today.

I obviously have no idea how modern architecture works. This is not a special air pressure building as far as I know. I had no idea buildings of this size (8 stories) need powered "air handler" units or the whole building goes a little wacky.

Tuesday, April 13, 2010

Portland's marketplace of ideas... in Omaha

In Portland tomorrow night:

Robert Buels presents "The Amazing Miracle of DBIx::Class"

Rob will give an introduction to and overview of DBIx::Class. It's an object-relational mapping framework, much better than the old Class::DBI, and it will make your life easier if you are currently writing a lot of SQL in your Perl.

In Omaha tonight:

Randal "merlyn" Schwartz (who lives in Portland) presents "Forget the ORM! Persistent Data with non-traditional databases."

What an Object-Relational Mapper is, why it sucks, and a couple dozen alternatives (most open source, many with Perl bindings).

Wednesday, April 7, 2010

Gratuitous Moosey ego stroking

The Godfather of Moose gave me mad shout-outs on his blog for some minor tweaking I did to the Moose website.

Later I expressed some of my recent concern about academia, and he offered this sage advice:

11:37 <@stevan> jhannah: go into their lab, climb up on one of the work benches and yell "ANY OF YOU NANCY BITCHES STEAL MY CODE AND I WILL CUT YOU INTO LITTLE PIECES"
11:37 <@stevan> then kick over a few bunson burners and walk out
11:37 <@stevan> they wont bother you in the lunch room anymore
11:38 <@perigrin> stevan did something like this in Art School
11:38 <@perigrin> 'cept s/bunson burners/cerulean blue/
11:38 <@stevan> I offcentered their pots on the wheel

Saturday, April 3, 2010

Gource: Programmers as action heroes

Check out the history of Perl development 1988-present. As you can see, when you speed it up enough and use lots of colors and movement suddenly programming is exciting to watch! (For a few minutes.) :)

They created that with Gource (watch other, even prettier videos).

At $work[0] we have CVS + SVN history back to 2000. It'd be neat to throw Gource against that and see what I (and my coworkers) have been doing with our lives for the last 10 years.

Wednesday, March 31, 2010

Catalyst::Plugin::AutoCRUD is a sexy beast

Wow. It took me about 30 seconds to add AutoCRUD to my existing Catalyst application. And now I've got a very shiny web 2.0'y CRUD (Create, Read, Update, Delete) application for all my databases. Double clicking pulls up the edit window.

Yes, this wheel has been invented scores of times over the last 10 years. But boy is this one shiny.

Monday, March 22, 2010

Firefly shot me 51 days into the future

I feel pretty good about my project this weekend. I used the University of Nebraska Firefly Cluster for a real project for the first time, completing 51.6 DAYS worth of data crunching while I slept between 3am and 9:30am this morning. The code I ran is my fork + branch of a bunch of Perl from Harvard against the latest human genome from UCSC. Masochists can read all the gory details (username: guest password: guest) and suggest improvements.

Computers are pretty cool sometimes. :)

Thursday, March 4, 2010

ack is awesome!

Wow! People have been telling me this for years, but I was getting along OK with my old school Unix craziness:
$ find ./ | grep -v svn | xargs grep '\-\>Promotion'
But today I couldn't get that working. Something with xargs escaping of -> just refused to fly.

So I installed ack and ran it:
# cpan App::Ack
$ ack '\-\>Promotion'
And it found what I was looking for with zero fuss!
Control/SG.pm
335: $self->Promotion($promo_hash);

View/Web/Phoenix/lib/Phoenix/Controller/SG.pm
2844: $c->log->debug("you have these PromotionCode's already: " . (join ", ", keys %{$sg->Promotion}));
2846: unless ($sg->Promotion->{$preauth}) {
Holy buckets! That is AWESOME! Thanks Andy!

Friday, February 19, 2010

Thursday, February 18, 2010

Actor Colin Firth on meditation

WHYY in Philadelphia, Terry Gross, Fresh Air, Feb 3 2010:

Starting at 28m mark.

Did you practice meditation?

Not seriously. I just tried to learn to be quiet a little bit. I actually went to a monastery. A Buddhist monastery to learn something about meditation. I have never practiced it with any great discipline, but I did find it to be, even in its probably shallowest and least-disciplined form, I did find it to be somewhat helpful because however fortunate my lifestyle is, it is not always the most restful.

What made you go in the first place to the Buddhist monastery? What did you want?

Restfulness. I've always been very attracted to the randomness and the unpredictability of my profession. I enjoy not knowing what's next. I enjoy the passionate commitment to something that is going to be gone soon. It's a strange creative promiscuity if you like. Where I move on to the next thing and commit myself with equal immersion and delight in something as if the one before just never existed. I think it's very exciting, but it can create this kind of upheaval because there's no continuity. And however thrilled I am by what I'm doing. However stimulated I am by it, it can be difficult to get back to a sort of a core. One of the things you're doing is taking on different people's lives. You're changing character. You're changing personalities. I find it's not always easy to shake them off. Before you shake one off you're taking another one on. I think for an actor getting back to a sense of who you are without all of that I think can be quite a challenge.

This was about 15 or so years ago. There was quite a bit of upheaval on a personal level. I was single at the time and it seemed that I was always at my happiest when I was employed -- I think there's something perfectly healthy about that -- but I was always happiest when I was engaged in something that was distracting me. I think it was, I felt it was time to discover how to celebrate life or to take joy in life when I wasn't distracted.

-end quote-

I don't really relate to the upheaval sentiment. And I'm not an actor. But the constantly distracting myself sentiment resonates with me. It's too bad the interview ended there. I would have liked to hear more about what meditation taught him, and how.

I consider it most likely that mine is a brain chemistry problem. Probably most expeditiously corrected with medication, not years of monastic study. But I have yet to solve that riddle, so don't know for sure. Stay tuned. I should get this one figured out sometime in the next 40 years or so.

Tuesday, February 16, 2010

Pipeline evolution

Over the last couple of weeks I've been writing and changing a bunch of software trying to answer some research questions. I find the visual evolution of this pipeline interesting. Maybe you will too.

Sneak peak of the first chart:

Wednesday, February 10, 2010

$76M? Thanks Catalyst!

Woot! Catalyst, our favorite Perl web development framework, served us well in 2009:
Over $76 million in revenue was booked through omnihotels.com, a 13.5% increase over the previous year; 460,902 room nights were booked during 2009, representing a 28% increase.

Saturday, February 6, 2010

...so complex that you need a large IDE to comprehend it

This is an excerpt from an Omaha.pm thread today.

We're discussing Eliminating Inheritance Via Smalltalk-Style Traits by Curtis "Ovid" Poe.

In his paper, Curtis wrote:
Anyone forced to use "vi" (not even "vim") while trying to create an emergency patch of broken code over a slow telnet connection at 2:30 in the morning is going to get very irritated if your codebase is so complex that you need a large IDE to comprehend it.


Trey wrote:
That is kind of silly. If you're shop is using IDE and developing under that sort of framework, your support people should be familiar with the code and the methods used to program it/maintain it.


Agreed. And have the capacity to perform emergency maintenance remotely via whatever means are necessary to do so.

I don't think he's arguing that slow Internet connections are a good idea. I think he's saying they happen.

Trey wrote:
That's sort of like saying that somebody is going to be irritated because they can't stoke up a hydroelectric plant with bellows...So what??


I love your analogy. :) So what? So your business is losing money in the scenario he describes.

I see this an indictment of relying too heavily on fancy developer tools to gloss over crappy code. If my code sucks in text form, but when I right-click on it a million lines of code in my IDE jumps to my rescue and explains it to me in pretty colors, then I'm helpless without that IDE. That sounds like a bad idea.

In the stack of technology ignorance and dependency I've planted my flag here:

- I don't really know or care about sub-atomic particles.
- I don't really know or care how electrons flow through conductors.
- I don't really know or care about chip design.
- I don't really know or care how hard drives, memory, and monitors actually work.
- I don't really know or care how the Linux kernel works.
- I don't really know or care how perl is written (in C).
- I don't really know or care how most of perl's core packages work (in Perl/XS/C).
- I don't really know deeply or care how most of the CPAN modules I use work (in Perl/XS/C).
- I know EXACTLY how the text of the Perl I wrote works. I do recursive grep's through text files to find out anything I need to know.
- Syntax highlighting is a crutch for the weak.
- Method auto-discovery is a crutch for the weak.
- Per-keystroke debugging is a crutch for the weak.
- Re-runnable images of crashes are a crutch for the weak.
- All that other fancy crap in your IDE is fancy crap I don't need. For the weak. :)

Objectively, my gut-opinions about exactly where that line is are silly. Aren't they?

If you take me and my Apple laptop running Terminal.app to ssh into a server and run vi, and next to me you sit a .NET guy running the latest Visual Studio on a mapped drive; is the total complexity of my dependency stack much smaller than his? (OS X is how many millions of lines of code?)

I don't know. I've now spent an hour arguing with myself about it. :)

In any event, I don't thing it's the use or avoidance of an IDE that makes good or poor code. You can create beautiful or ugly code with the simplest or fanciest of tools.

I do think he has a point. If your "...codebase is so complex that you need a large IDE to comprehend it." Then you're doing something wrong. Use an IDE because you want to, not because it's impossible to survive your mess without it.

/me shakes his fist at XML Spy addicts

Ponder,

j