Ruby, Rails, Mac, and MySQL

Posted by admin, Tue Dec 06 07:09:26 UTC 2005

Seems like everyone has a slightly different story about trying to get RoR working on a Mac with MySQL.  I managed to get RoR working and connecting to an Oracle database (on another machine) from my Mac.  But I wanted to get a local database working for this week, so I started playing with MySQL.

I tried working from a source distribution of MySQL (version 4.1.x), and it seemed to work when I set it up, but when I got back to it after the weekend, I could not get connected to the database server daemon.  Grrr.  So I uninstalled the source distro, and got the binary install of MySQL (version 5.0.x) for Mac OSX (Tiger).  That install went very smoothly, including installing the startup items. 

Then I tried to make it work with RoR.  Not so smooth.  I followed the tangle of instructions from the RoR Wiki, attempting to install/build the mysql gem to no avail.  Then I found this blog.  The primary difference between it and all the other advice was this one line:

<strong><strong>sudo gcc_select 4.0</strong></strong>

So I set my gcc back to 4.0, and tried to install the mysql gem again.  Bingo!  This time it worked.  And now I have a working MySQL 5.0 development database for RoR.

0 comments | Filed Under: | Tags:

Doing Things the Hard Way

Posted by admin, Thu Dec 01 17:20:55 UTC 2005

Aardvark’d the DVD has shipped.  Wonderful story on the trials and tribulations of "doing-it-youself".  Joel, next time maybe you’ll have learned your lesson, and use an existing service like Lulu to publish your DVD’s.  Sheesh.

0 comments | Filed Under: | Tags:

Tightening up Drag &amp; Drop

Posted by admin, Wed Nov 30 11:57:16 UTC 2005

I was trying to implement a drag and drop list in my RoR web application, using the shopping cart demo from script.aculo.us as a template.  But there was one problem.  When I added and removed items from my "list", the entire list was rendered.  In my case, this was worse than inefficient, since some of the "items" dropped into the list needed to be set up using calls to the database.

Now, in the excellent Agile Web Development with Rails book, in Chapter 18, they describe a method of "Dynamically Updating a List", which pretty much did what I wanted, which is just add or remove an "item" from my "list", only updating the item in question.  No drag and drop, though.

The problem was figuring out how to combine these two examples into something that worked.  The solution, as always in RoR, is almost childishly simple to implement, but I spent most of an afternoon figuring out those elegant, simple, 4 lines of code… :-}

In the interests of saving others that afternoon of fiddling, I figured I should post my solution.  I’m simplifying things here.  We are dealing with a simple "list" which contains "items", and when we drag an item into the list it gets added, and when we drag an item out of the list it gets removed.  I’m not "counting" products like in the actual shopping cart demo.

For the drop_receiving element "list", add a position parameter, like:

:position =&gt; :top,

Then, in the add method, instead of:

render :partial =&gt; 'list'

use:

render :partial =&gt; 'list', :object =&gt; item

And in your remove method, instead of:

render :partial =&gt; 'list'

use:

render :inline =&gt; &quot;Element.remove('item_#{i}');&quot;

And for your drop_receiving_element "trash", change:

:complete =&gt; &quot;Element.hide('indicator')&quot;

to

:complete =&gt; &quot;eval(request.responseText);Element.hide('indicator')&quot;

Simple, eh?  Hopefully I’ll soon have an external RoR server where I can post a working version with complete source.

0 comments | Filed Under: | Tags:

Session 2: The Mini starts to strut it's stuff

Posted by admin, Fri Feb 25 10:06:26 UTC 2005

Ok, I was sick for a couple of weeks, and the Mini just sat there, mostly because I was pouting about the mouse. But, I read this week that uControl was updated and working on OSX 10.3.8, so we were off to the races today.

Download and install the new uControl (1.4.6, I believe). Bam! Works just fine, without even having to reboot. I am now a happy left-handed mouser.

So, what to do now? I didn’t order iWork, because I’m not sure I want to go that way just yet. I hear OpenOffice runs on Macs. Little poking around, and I rediscover something I read about a couple of weeks ago. The native Mac OSX OpenOffice is stalled, and just the X11 version is available. That just sounds like too much trouble to me. Isn’t the Mac supposed to just work? So I poke around using Google and discover NeoOffice/J.

That’s more like it. NeoOffice/J uses combination of the Aqua interface and Java, and it’s a fork of the OpenOffice code. All sorts of problems downloading NeoOffice/J from it’s home website, until I discover that it’s mirrored on Apple.com. Download from there is quick, and install is quicker. Hmm. No desktop icon. Where is it? Open up Finder. Oh, I see. Applications folder. There it is. Double-click, and we are rolling.

NeoOffice/J looks just like OpenOffice to me. Let’s find that spreadsheet I wanted to copy and adjust for the new year. File | Open. Hmmm. Looks like the standard Java file dialog to me. I don’t think that’ll get me to my Samba shares on the server. Open up Finder, and navigate to the proper directory. The .sxc files all seem to have NeoOffice icons associated with them… what the heck. Double click on the file I want. SWEET! It opens up in NeoOffice just fine! You know, you can’t do that on Linux with OpenOffice. Just for laughs, let’s try a “File | Save As” to get a new copy to play with for the new year. SWEET! It saves to the Samba share just fine. You can’t do that on Linux with OpenOffice either.

Thus ends the second session on the new Mini. I’m a much happier camper now. Can’t wait to see how a real development tool works.

0 comments | Filed Under: | Tags:

First impressions

Posted by admin, Fri Feb 25 09:12:39 UTC 2005

I was hoping that my first impressions of the Mac Mini would be all good. Unfortunately I hit a snag, right near the start, that kind of soured things.

I got the Mini hooked up via my Belkin KVM+audio switch. I had a few bad moments when it seemed that the video was not working, but it was a false alarm. It’s currently hooked up to the second input on my second LCD screen (NEC Multisync 1880SX), so the “V” part of the KVM isn’t really being used. Initially, it came up with a much smaller resolution than is supported by the screen. It was easy to find and fix this in the System Preferences. Very pretty.

Next, get the network stuff going. We have a Linux-based box serving as primary domain controller on our network. A few clicks around through the network, and I’m all set, able to access all my network files, including my downloads share. Perfect. Futzed a little on the server to enable AppleTalk. Works. Do a little bit of reading, and discover that Samba sharing is better, so the AppleTalk server support is now disabled again.

On to the next thing. I am left handed, so I need to swap the mouse buttons. No dice in the system preferences. Ok. I get it. The Mac is so oriented towards the single button mouse, that this doesn’t come standard with the OS.

Grumble. Grumble. I have a Logitech wireless optical mouse, so I trundle off to the Logitech web site and download a Mac driver. Install the whole package. No dice. Because I’m hooked up via the KVM, the Logitech software insists that I don’t have any Logitech devices installed :-p Fine. Uninstall the software.

Google for answers. I see. Nice little utility called uControl (open source, gotta love it) handles mouse button swapping and much, much more. Great. Download and install it. Reboot to get it working… still not working… Back to Google. Oh. I see. It only works with Mac OSX 10.3.8 if you installed it on a previous version of the OS and then upgraded. :-p Fine. Uninstall the software.

Continue to plink around for a while, exploring the Aqua interface. Frustration with the mouse buttons mounts, until I give up.

Thus ended my first evening on the Mini.

0 comments | Filed Under: | Tags:

I feel like such a lemming...

Posted by admin, Wed Jan 12 10:10:11 UTC 2005

But yes, I did stampede to the online Apple Store, and helped contribute to its near meltdown yesterday. And I did configure a nice new Mac Mini, just for me. Why not? I’ve always held back from “making the switch” because Apple hardware is ruddy expensive, and I’m not sure if I could just switch from cold-turkey Windows and live with it.

Now, I don’t have to shell out a fortune just to try out a Mac. Just Cdn$629 (ok, it was over $800 by the time I was done “upgrading” it) and that was it. I already have a nice Belkin KVM on my desk. I can just hook up the Mini and take it for a spin. If it turns out that I like it…. well, maybe when the lease on my Dell notebook runs out I’ll be taking a closer look at those PowerBooks…

0 comments | Filed Under: | Tags:

Western Canada Java Software Symposium

Posted by admin, Mon Nov 22 15:09:44 UTC 2004

I attended the No Fluff, Just Stuff symposium this past weekend in my home town of Calgary. It was great. I expected nothing less, after having attended the 2003 version in Denver in May 2003. If you’ve been attending JavaOne year after year, then I suggest you take a break next year and try out a No Fluff Just Stuff symposium, especially if one is making an appearance in your home town. It’s better. It’s focused. No vendors. No fluff. Just speakers who are all published authors and acknowledged experts in their fields. I’ll be making more posts on some of the more interesting tidbits later this week. Stay tuned.

0 comments | Filed Under: | Tags:

JBuilder 2005 at BorCon

Posted by admin, Tue Sep 14 10:50:57 UTC 2004

Well, this is my first ever BorCon. Quite interesting, given that we have a brand-spanking new version of JBuilder. Since I’ve been holding off on re-designing one of my older web applications pending the release of JSF, I decided it would be good to concentrate on the JSF sessions. On the weekend, I attended an excellent tutorial by Jeff Swisher on JSF. Since he’s actually been implementing JSF solutions for months now, he had a lot of great information to impart. I particularly liked the way he contrived errors in his examples, in order to illustrate the causes of some of the more obscure error messages that are generated by the JSF framework. Valuable stuff. It’ll save me hours, if not days, tracking down problems once I get going.

The next JSF session I attended was given by Karl Ewald. Since he was one of the Borland developers who worked on the JBuilder JSF support, I had high hopes for this session, and I was not disappointed. Interestingly, unlike Jeff Swisher, who spent most of his time messing about in the faces configuration editor, Karl used the new “Flow” tab on his JSP examples. He showed us how to “sketch out” an entire web application in minutes, generating skeleton artifacts as he went. Wow. A completely different kind of work-flow, but I liked it, and I think it will be a huge productivity booster.

Now, I just have to find a little free time to start using this stuff myself…

0 comments | Filed Under: | Tags:

I knew there was a reason I hated the "m_" naming convention

Posted by admin, Fri Aug 27 18:52:28 UTC 2004

For years, I’ve been diligently erasing all traces of pre- and post-fix naming conventions from the source code under my control. I’ve always hated it. The argument I most commonly make for this is that, IMO, it makes the code less readable. Now, in a happy coincidence, I have been reminded about this topic, when I have actual proof to point at to back it up.

Now, “readable” is a very subjective term. Some people would insist that the prefix “m_” provides additional semantic meaning to the field, telling you that you are dealing with a class field instead of a parameter or local variable. In Java, so does “this.”. Others would add tags like “str” to the beginnings of every String field name. Again, yes, it adds semantic meaning, but any decent IDE will provide the same information in several different forms (tooltips, find definition, etc) without the extra baggage.

So, what about this proof? Consider the following:

Aoccdrnig to rsaerech, it dseon’t mttear in waht odrer the ltteers in a wrod are, the olny iroptmant tihng is taht the fsirt and lsat lteetr be at the rghit pclae. The rset can be a taottl mses and you can sitll raed it wouthit any perbolms.

Now, I hope you see where I am going. The real problem with all these pre- and post-fix notations is that they screw up that first/last letter recognition that seems to be hard-wired into readers of the English language, mostly because of some redundancy features of English. (See the links at the bottom of this post for more information about this.) So, there you have it. Proof that readability in your code is diminished by the use of pre- and post-fix naming conventions.

So let’s all get out there and start improving the readability of our code. JBuilder has some nice Rename Refactorings to help. ;-)

References Comments from a researcher at Cambridge A letter purportedly from the original researcher of the topic

And thanks to Anders for the inspiration from his new CafePress shop.

0 comments | Filed Under: | Tags: