Practical advice for the coming invasion

Planning for Aliens

Archives Posts

ActiveRecord Style Validation using SQLAlchemy and Elixir

April 20th, 2008 by Sean

Update: Turns out I missed the boat on this one. This has already been implemented in Elixir.

I just spent the better part of today putting together the pieces in order to create ActiveRecord like validation in my Elixir models. Here is what I wanted to be able to do:


class Tag(Entity):
label = Field(String(200))
before_insert('validate_label')
before_update('validate_label')

def validate_label(self):
Some validation code here

I wanted to be able to write custom validation methods in my model and then hook them into sqlalchemy events like ‘before_update’ so that before any data goes to my app’s database it is first validated. Then at that point I can catch it and redirect the user to change the invalid data.

Earlier I had stumbled upon this code by Beachcoder. While I was excited to see that it could work, I was having a difficult time understanding the approach, largely because a lot of this stuff was essentially a black box to me. So I got under the hood and came up with my own approach. I’m not sure if it’s better or even complete, (even though it seems to work and I pass all my unit tests), but that’s why I am posting it here. Feedback is welcome!

from sqlalchemy.orm import MapperExtension
from elixir.statements import Statement
class HookExtension(MapperExtension):
"""
Given a hookname and a list of callbacks, (which are just methods associated with the instance)
this mapper extension overrides the given hook with a function that executes each of the callbacks.
"""
def __init__(self, hookname, callbacks):
MapperExtension.__init__(self)
def execute_callbacks(mapper, connection, instance):
for f in callbacks: getattr(instance,f)()
setattr(self, hookname, execute_callbacks)

def create_hook_statement(hookname):
“”"
A simple class generator. Given a sqlalchemy hook name like ‘before_insert’ or ‘before_update’ creates
an Elixir statement. The statement excepts a list of ‘callbacks’ which are names of methods associated
with the Elixir class that will be executed based on the hook.
“”"
class HookStatement(object):
def __init__(self, entity, *callbacks):
ext = HookExtension(hookname, callbacks)
entity._descriptor.add_mapper_extension(ext)
return HookStatement

before_insert = Statement(create_hook_statement(’before_insert’))
before_update = Statement(create_hook_statement(’before_update’))

Archives Posts

Motorola Q Review

September 5th, 2006 by Sean

I have had the Motorola Q for 3 months. People want to know — do I like it? Well people, here is my answer:
General Overview
The Q is the latest Smartphone offering from Motorola. It is running Windows Mobile 5.0 Smartphone edition. It has a full QWERTY keyboard, a bright, large screen and a very thin profile that borrows from its cousin the RAZR.Motorola Q

The Good

The Q has a lot of upside.

Price: At $200 with the purchase of a new Verizon plan, the price can’t be beat. If you buy it at full retail, it comes with the slightly heftier price tag of $500. Compare this to similar offerings and you will find it is still a very modest price.

Form Factor: The Q fits nicely into the palm of your hand. Although its width initially had me concerned, that feeling quickly passed as soon as I realized how easily it fit into my shirt pocket. It’s also slips comfortably into normal pants pockets and its presence is not as easily detected as the clamshell models I previously preferred.

One drawback I see with the shape of the Q is that when using it as a phone, a wide portion of the screen is pressed against your cheek, and so it is constantly smudged.

The Keyboard: The Q is the first phone of its class with a full QWERTY keyboard. Responding to email, text messages and entering data is a breeze. There are a few problems and drawbacks with the keyboard. The keys are rather hard plastic and are not very comfortable — I have a texture phobia and these keys do not help matters. I have a feeling normal people won’t care. Also, you will never be able to text IDOL04 to vote for Taylor Hicks because the letters underneath the numbers do not line up the same way as on a traditional phone. You’ll have to ask your non-Q owning friends to help you out.

Smartphone Software: This phone can accomplish almost anything you need it to accomplish. Keep in mind that the Q does not have a touch screen — it’s a Smartphone not a Pocket PC. This means that you can’t edit documents since only the Pocket PC software will allow you to do that. The Q is the first Smartphone with a QWERTY keyboard, and as such it is the first Smartphone where the ability to edit documents would actually be a useable feature. I have a feeling this ability will be available as a software update in the near future. In the meantime, even though you can’t edit them, you can view virtually any document.

If you are not happy with the out of the box functionality there are hundreds of Windows Mobile 5.0 compatible third-party applications to take advantage of. For instance, I am using Oxios ToDo list in order to use my Q in my Getting Things Done (GTD) system. (More on GTD in a future post). I also highly recommend AgileMobile for instant messaging. Watch out though, it drains the battery quickly.

Email is easy to get going. I use ActiveSync to sync with Accenture’s exchange servers for work, and I just use the built-in browser to access Google’s mobile web interface to check my Gmail account.

Miscellaneous: The Q also has: built in Bluetooth, a slot for MiniSD memory (I bought a gig for $60), voice notes recorder, excellent media player, pretty good camera, (I actually use it vs. didn’t even bother with previous phones), and very good voice quality. It excels at its basic function as a phone.

The Bad

It’s certainly not perfect.

Smartphone Software: I know this made the list of pros, but something has to be said about the negative aspects of the phone’s software. There are a wide ranging set of user interface problems associate with the Windows Mobile Smartphone software. Basically, it’s not as well thought-out as Palm software so you click through more submenus then you should rightfully have to.

Email: Again, this was a pro overall, but as of now you can’t set the Motorola Q to accept push email. I think this feature will be available soon as a software upgrade, but for now you’ll have to settle for checking your email every 5 minutes. I suppose this would be an acceptable interim solution, if it weren’t for the…

Battery Life: The Q sucks the battery dry when you are using it as a phone. I’ve found I have approximately 3-4 hours of talking time. When I’m primarily using the data features and not the voice features, the battery easily lasts all day. If you are on the phone a lot and not near a charger, this is not a good phone for you. My life consisted of a series of stressful and long phone calls in the last few weeks before my wedding, so I am very familiar with the poor battery life of the Q. On the bright side, the battery life has gotten better over the past few months, so I can skip charging at night every once in a while — but this is risky so I don’t recommend it. Also, I noted significant improvement in battery life when I set my email to sync manually. Syncing every 5 minutes drained the battery quickly.

The Data Plan: $45/month for less than DSL speeds is just too much. You can’t get the Q without a data plan. I guess you can, but you really shouldn’t. The Q assumes you have a plan and doesn’t ever warn you if you are about to use the data network. Expect to see charges for accessing Verizon’s data network on your bill each month even if you have gone out of your way to not use the data services. Don’t get a Q without a data plan.

Conclusion

In general I am extremely pleased with this phone. It accomplishes exactly what I want. I recognize that it is not as powerful as a bigger and chunkier Treo 650 or similar Pocket PC devices, but I also felt it was more important to have something that was truly mobile and didn’t make me feel like tightening my belt to keep my pants on when I put it in my pocket. I can check my email and respond. I can view attachments. I can create voice notes, take pictures, read my Bloglines account, chat with my friends on AIM and Google Chat, watch videos, listen to music and place phone calls. The best part is that all of this functionality slips into my shirt pocket for $200. It may not be the iPod of Smartphones, but I thinks it is a glimpse into the future of our mobile lifestyle.

Archives Posts

how to install tortoiseSvn (subversion for windows users)

August 29th, 2006 by Sean

1. Open up your web browser to the TortoiseSVN downloads page.

2. Scroll down until you see a post entitled “The current version is…” and download the file that ends with the .msi extension under the 32 bit subheading. It will look something like the following, but the numbers could be different: TortoiseSVN-1.3.5.6804-svn-1.3.2.msi

3. You will be directed to a screen with a list of locations and download links on the right side. Scroll down until you see the location nearest you, in my case it is Phoenix, AZ.

Download the file to your desktop or where you can find it easily.

4. Once the file completes downloading, open it and click through the wizard. There are no special options, just keep clicking ‘next’ until you can click ‘install’. You will have to reboot your computer to finish the installation.

5. Once your computer has finished rebooting, TortoiseSVN is now installed. Right click anywhere on your desktop and you will now see two additional options: SVN checkout and TortoiseSVN.

6. Now we need to adjust the configuration settings. Right click anywhere on your desktop and within the TortoiseSVN submenu choose “Settings…”

7. Highlight “General” and click the “Edit” button next to the words “Subversion configuration file”

8. Delete everything in that file and insert the following:

Note: Ensure that there is no leading white space, (tabs or spaces), in your file when you cut and paste the selection below.

[auth]
[helpers]
[tunnels]
[miscellany]
enable-auto-props = yes
[auto-props]
* = svn:needs-lock=*

9. Save your changes and close out all of the TortoiseSVN windows currently open.

10. Open up My Documents and create a new folder. If you are following these directions, I have sent you an email with some information. Name the new folder the same as the name of the repository that is within that email.

11. Right click on your new folder and choose “SVN checkout”. In the “URL of repository” field enter http://meshsandbox.com/svn/(the name of your repository). Leave everything else and click OK.

12. Enter in the username and password I provided you. Make sure and choose the option to save the name and password, otherwise you will be entering it in quite frequently.

You have successfully installed subversion and checked out a working copy of your repository. Chances are there are no files in your repository, so let’s add one for practice:

1. If you have a file that you know you want to be under version control, drag it into the folder we have just created. For future reference this folder is called the “Working Copy”.

2. Even though you see the file in the folder, it is still not in the repository. As you recall from this article, what you have on your computer is merely a copy of all the files held within the repository. Anyone with access to the repository has a copy of it and it is up to you to update the real repository with any changes you have made. Right click on the document, go into the TortoiseSVN menu and choose “Add”.

3. The file is now part of the repository, but now you need to committ your changes. Right click anywhere within the window and choose “SVN Commit”. This will permanently save your changes to the repository. Now, whenever anyone checks out or updates the repository, they will have your file.

I will create another set of directions to clarify these last few steps. I have also created a screen cast that illustrates how to check out the repository and add a file as described above. You can view it here. I recommend clicking on the icon with the double boxes located in the bottom right corner of the video box to expand it to full screen.

You can also download the zipped windows media file here if you want a clearer picture.

Archives Posts

Subversion Repositories for Everyone

August 25th, 2006 by Sean

I offered to create Subversion repositories for some of my family and friends and to my surprise, quite a few were very interested. This article is to give a broad overview of what Subversion is and why it is incredibly useful.

What is Subversion? Subversion is version control software. Version control helps a group of people manage a set of shared files.

For example:

You are working on a presentation with three other people. You go home and after watching an inspirational television program you feel the urge to update the slides. Just before you head off to bed, you email the new presentation to everyone on your team. At the same time another member of your team also updated the slides and emailed their changes to everyone. The next morning when you check your email you have two separate versions of your presentation and the joyless task of merging both sets of changes into one version. Version control solves this problem.

All files controlled by Subversion are stored in a repository. This is basically a digital vault that everyone on your team can access from anywhere with an internet connection. Each person who has access to the repository maintains an updated copy of all the files on their computer: this is called your “working copy”. Each person has their own copy. Once you are done working, you update the version stored in theSubversion Workflow Diagram vault. This is called, “committing” your changes. The next time someone on your team updates their working copy it will contain your changes and they will be working on the most recent “version” of the file. This is why it’s called “version” control.

As of Subversion 1.2 you can now lock files. When one member of the team locks the file, no other team member can make changes to the file. In our example above, you would have locked the presentation before you started making changes, so the other member of your team couldn’t have made changes to the document.

I’ve created a workflow diagram to show the process you would use to update a file when it is under version control using Subversion.

Note: Using Subversion it is possible to have multiple people working on one file at the same time. Subversion would then merge the changes and pass off any complicated conflicts to a human. However, it can’t do this with complicated files like Microsoft Word, Excel or Powerpoint. This is why the repositories I am creating for my friends and family will be set up to require locks as I have described above.

Filed under Computer Nerdiness having 1 Comment »