Ruby Nuggets

This is just a place for me to record the lessons I learn on how to do things (ranging from simple to complex) in ruby and rails. This description is a bit out of date. The topics covered are now expanding into other programming languages such as Erlang, Haskell, LISP/Scheme, Javascript, Flex/ActionScript, etc. But I will be sticking with the name for historic reasons. I wouldn't want to confuse the masses of loyal followers I have.

Thursday, April 02, 2009

Two more complaints about Django

1. No multiple database support. Some people have created some solutions, outlined here, but no support in the mainline of 1.0. This is so ludicrously basic for any site that is more complex than a blog that I just don't know how it's gotten this far without it.

2. There is coupling where there doesn't need to be coupling between "INSTALLED_APPS". In order to turn on the Django admin site app, you have to turn on the auth app which in turn requires the session app. This means that I have to create a bunch of database tables IN MY CORE DATABASE (see #1 above) if I want to use Django's much touted Admin Interface for my existing data models. Aside from having extra tables laying around that I really don't want there, this means I have a separate set of admin users and passwords that I have to keep in sync -- as well as separate active sessions in the browser.

I'm sure there's some, possibly even mostly legitimate, reason or reasons for this coupling, but it still sucks in my case right now and for my requirements there is no reason why I couldn't be done without it. I guess I'll have to look into implementing an alternative auth module that breaks the coupling. Of course I don't have time for that, so what will happen instead is that I'll leave those tables there and work on core stuff while trying to ignore them every time they clutter up the display of my data model.

Monday, February 23, 2009

Surprise python type.

>>> type(sys.maxint)
<type 'int'>
>>> type(sys.maxint+1)
<type 'long'>
>>> type(int(sys.maxint))
<type 'int'>
>>> type (int(sys.maxint+1))
<type 'long'>

That last one surprised me.

Tuesday, January 20, 2009

Default-Browser-"Proxy": Does this exist? If not, why not?

Being that I am at least in part a web developer, I have quite a few web browsers installed on my system.  Generally speaking I do most of my "personal" browsing in Safari and most of my "work" in Firefox (primarily for Firebug).  

I have Safari set as my default browser so that when third party programs (News Readers, etc) want to open a URL in the default browser, it shows up in Safari.  This is fine except every now and then I do something which triggers the "open this in the default browser" action where the target is something I need to debug with Firebug (or want in Firefox instead of Safari for some other reason).  

When this happens I usually just copy/paste the URL that is now open in Safari over into Firefox.  But sometimes I get into a work flow where I am in a test-debug-retry loop that contains one of these calls to the "open this in the default browser" action.  In those cases I spend an awful lot of time copy/pasting URLs.  One possible work around would be for me to temporarily set Firefox to be my default browser during periods like this, and then set it back when I am done. 

There are several problems with this approach.  First, it's not overly difficult but it would be a bit cumbersome to do this browser switching on even a semi-frequent basis.  Second, it would require me to remember to switch it back when I'm done.  If I forget, the worst that would happen is something opens in Firefox and I have to paste it into Safari, then go switch it back.  But I'm sure I would forget all the time and this would become at least as annoying as the original problem.  Lastly, there would be occasions when the problem would be inverted -- I am primarily working with work stuff (w/ Firefox set as my default browser) but open a one-off article on something that I want to read in Safari.  

Another solution might be to somehow (browser extensions? javascript links?) get a button into each browser that when clicked will open the current document in the other browser.  This would make my situation better but has it's own problems (not the least of which is that as you start scaling the problem out to other browsers like Opera, Camino, lynx, etc, not only does it become annoying to have so many of these buttons featured prominently in the UI, but it would also become quite a burden to manage to create them for every browser).

I think I have come up with a good solution though -- what I want is something I am thinking of a "Default Browser Proxy".  The problem with this name is that the use of the term "proxy" in the context of a web browser invokes the idea of an HTTP proxy, that is a piece of software which proxies your web requests to the web for you.

What I want is something that proxies these "open this URL in the default browser" requests to the (appropriate) browser for me.

Essentially, I want a piece of software which I can set as the default browser on my computer (running Leopard, but the same thing should work on any platform) which responds to all the requests a browser normally would from other programs, the primary one being "open this URL please" but which then allows me to choose which browser (of the many I have installed) the action should actually be completed by -- and then forwards the request for action on to the selected browser.

A program that functions as I have just described would ALMOST be enough to solve all of my problems right out of the box, but I think the problem would then become that you every "open this url" request would require you to stop and select a browser which would become pretty tedious.  This would be easy to solve though -- you would just need a good UI design on the panel that asks you which browser you want to use.  

I am picturing that at the top it would list all of the browsers it knows about with the icon for each one, sorted in order of some combination of how frequently it's chosen ever and how frequently it has been chosen recently.   Then below that, there would be a number of checkboxes with certain ones checked by default -- one of which might be "always open URLs from this domain in this browser".  That way, once I have chosen that links from e.g. reddit.com go to Safari, I won't ever be prompted for where to open them, they will just automatically go to Safari.

Of course there would need to be some secondary UI for editing the routes you have set up later in case I decide I want to read reddit in Camino instead of Safari or something along those lines.

You would also need a handy button you can click to switch to "Browser Compatibility testing mode" where either it asks you for every link where to open it (even if you've already chosen a permanent route by domain etc) or better yet just automatically opens it in multiple/all browsers simultaneously.

Of course this makes me realize that the initial popup interface should function such that if you hold down a modifier key such as control or command while you choose what browser to open with, it will open with multiple ones from the get go.  Of course doing this should probably automatically uncheck the "always open URLs in this browser" checkbox, but allow you to re-click it after selecting multiple browsers in case you do want to default some pages to opening in multiple browsers.

So, does something like this exist?  If not, why not?  If I don't find it by Saturday I will probably take a crack at creating one.  The real question then becomes whether I should write it to work for my exact environment (Leopard) or every environment.  The big choice there is really what UI toolkit to use.  It feels like the same software should work on every platform but on the other hand Cocoa is really pretty and there are no good cross-platform GUI libraries that I've used that I actually like.  Sigh.

Thursday, November 13, 2008

Book Meme

That will find the developer note tags used by my company, as long as they are addressed to me.

by James Edward Gray “TextMate: Power Editing for the Mac".

continue the meme.

  • Grab the nearest book.
  • Open it to page 56.
  • Find the fifth sentence.
  • Post the text of the sentence in your journal along with these instructions.
  • Don’t dig for your favorite book, the cool book, or the intellectual one: pick the CLOSEST.

Thursday, October 16, 2008

No watchpoints in pdb or winpdb? Really?

Anyone know of a free debugger/IDE for python that has watchpoints?

Monday, October 13, 2008

Removing the blue focus ring glow on a focused input field in Safari

I found myself needing to remove the blue glow around the currently focused input field in Safari today and the only thing I could find online about it at all was this post which suggests a rather complicated workaround involving creating an extra containing div and using negative margins to mask off the glow.

I discovered a far more simple solution that does not require creating non-semantic markup:


:focus {
    outline: none;
}


This seems to do the trick. I would've just posted this on the Spoiled Milk blog but they don't have comments enabled for some reason. In the meantime I'm posting it here in hopes it helps anyone searching for solutions to the same problem.

As they mentioned in the Spoiled Milk post -- I would not generally advise doing this sort of thing as it reduces usability, however in our particular case we were using a specially shaped input field and adding the same affect back in a cross-browser way.

Friday, August 01, 2008

MySQL error 1005 (HY000), errno: 150

ERROR 1005 (HY000): Can't create table './db_name/table_name.frm' (errno: 150)

I get this cryptic error about once every six months and I always have to search for the solution. Each time it's a little bit faster because I remember what it was a little bit sooner during the process, but I figured if I just wrote it down here, I wouldn't have to search anymore.

The cause of this error, in my case right now at least, is that my table definition included a foreign key constraint that pointed to a non-existent table.

MySQL developers: If you happen to read this, how about reporting the error as "I'm sorry, I cannot create the table table_name in the database db_name because a foreign key clause in the table definition referenced the non-existent table 'foo'" instead of the above? Just a thought...