Software


So Firefox 2 is out, and it looks much like its predecessor. The upgrade was painless, nothing broke. So what, exactly, changed? Well one thing is that it has support for JavaScript 1.7, which (among other things) includes support for array comprehensions via iterators, generators, and other Pythonic things.

What caught my eye was that it supports map natively. For anyone using Prototype and getting annoyed with its performance, this could be a big thing. In a few simple tests I found that the exact same loop code runs 2-3 times faster with the native map as compared to Prototype’s implementation. If we could somehow harness that power…

Simple and easy javascript dependency management.

Why?

This plugin grew out of my desire to use javascript effectively in my new job. We began using UJS, and that was a good step in the right direction. The problem was that I found myself wanting to break the code I was writing into logical sections, so I created this convention:

The url /account/edit automatically includes /javascripts/account/edit.js if it exists, otherwise it would try /javascripts/account.js, and otherwise nothing. This convention worked pretty well, except that I found that often controllers would share code. I could have just included the controller javascript as well, but on top of that there was another convention: /javascripts/models/base.js, which communicates with the server (getting JSON back), and its subclasses. Controllers didn’t have a 1-1 mapping to models, so I needed some mechanism to specify what should be included where without a bunch of conditional statements in application.rhtml.

How to use it

My solution (from one index.js):

// require prototype menu models/tag models/interest builder moo.fx.pack.js

This is the first line of the file, and it tells my plugin to make sure that it includes these files before it includes this one when using javascript_include_tag. So the output of javascript_include_tag('index') would be this:

<script type="text/javascript" src="/javascripts/prototype.js"></script>
<script type="text/javascript" src="/javascripts/menu.js"></script>
<script type="text/javascript" src="/javascripts/models/tag.js"></script>
<script type="text/javascript" src="/javascripts/models/interest.js"></script>
<script type="text/javascript" src="/javascripts/builder.js"></script>
<script type="text/javascript" src="/javascripts/moo.fx.pack.js"></script>

It also handles recursive includes:

A.js: // require B …

B.js: // require C …

C.js: …

Here calling javascript_include_tag('A') returns:

<script type="text/javascript" src="/javascript/C.js"></script>
<script type="text/javascript" src="/javascript/B.js"></script>
<script type="text/javascript" src="/javascript/A.js"></script>

And, if two different scripts require the same script, it’ll only be included once:

A.js: // require prototype …

B.js: // require prototype

javascript_include_tag('A', 'B'):

<script type="text/javascript" src="/javascript/prototype.js"></script>
<script type="text/javascript" src="/javascript/A.js"></script>
<script type="text/javascript" src="/javascript/B.js"></script>

This even works if you include ‘A’ and ‘B’ in different calls to javascript_include_tag.

Installation

script/plugin install http://eventualbuddha.textdrive.com/svn/javascript_require/

Having a full-time Rails job can really spur you to find out more about what’s going on in Ruby and Rails. I’ve found that I’ve learned quite a bit about what’s going on in the last month and that I’m still learning at a breakneck pace, so here goes, in no particular order:

Piston

“Vendor branch management” gem that lets you store other projects (like Rails plugins) inside your own repository while retaining the ability to update them. This is particularly useful with Rails because you don’t really want to have outbound connections fetching your svn:externals every time you do a Capistrano deploy.

All my svn:externals have been Piston-ized.

EZ-Where

A Rails plugin that allows building the ActiveRecord find options hash based on Ruby code:

Article.findwhere(:all) { |article| article.publishedat < => (from..to) }

Great for complex queries. Using this plugin in WishRadar cut about 45 lines of code that generated SQL manually into about 12 of easy-to-read ruby.

Continuous Builder

An “Official” Rails plugin to make it easy to set up continuous integration testing with email and Campfire notification support. I’ve been using this for about two weeks and it’s pretty reliable, though setting it up with a Subversion post-commit and getting migrations to run is a little tricky. My hacked continuous_builder.rb’s make method:

def make @output = cd #{@options[:application_root]} && #{@options[:bin_path]}rake db:migrate RAILS_ENV=test && #{@options[:bin_path]}rake db:migrate RAILS_ENV=development && #{@options[:bin_path]}rake #{@options[:task_name]} RAILS_ENV=test make_successful? end

To prevent Subversion from blocking when doing a commit, run scripts with STDERR redirected to STDOUT and put the process in the background:

/path/to/continuous-builder 2>&1 &

“My Rails Toolbox” Article

Wonderful list of stuff to use on a Rails site if you’re serious about going to production.

Caboo.se RDOC Documentation Project

They’ve started work on an app to make it easy to produce diffs for documentation purposes. Better Rails docs now!

FixtureScenarios

A large fixture set is very hard to manage, so a plugin to keep them in discrete ’scenarios’ making them independent and “preventing you from changing your assumptions in a dangerous way” is a great idea. Beware, though - it may not play nice with other fixture-related plugins. (in case you’re wondering, it’s better than FixtureSets)

memcached

A network-enabled memory store that basically acts like a giant hash. Good for sessions and whatever other data you need to cache in your app. See the article. Haven’t used it much but I’m looking forward to it (trying to avoid the premature optimization itch).

QueryTrace

A plugin to print a stack trace with each SQL query in your logs. This hasn’t proved invaluable yet, but I’m guessing that once we start optimizing our queries and caching, it’ll be a lifesaver.

hpricot

Fast - like C fast - forgiving HTML parsing. Yeah baby.

Rails 1.2

This will include ActiveResource, DHH’s latest code built to tackle one half of the REST web services problem, as well as some nifty enhancements to routes that will cover the other half.

RSpec

Unit testing done in a more DSLish way. Specify what should happen, and in what contexts, and you’re halfway done with your tests. Really more of a psychological helper than anything else, but that’s what good DSLs are for, right? Check it out at rubyforge. I haven’t tried this yet, but it’s on my list.

One of my biggest annoyances with Firebug was that when you are in the Inspector and wish to get an element into the console, you have to use some JS hackery in order to do it. Well, at some point this limitation was removed — or it never really existed except in my head. All you have to do is reference $1 in the console. Yay!

I’ve used NewsFire for all my RSS needs for a while now. I don’t really like the fact that I had to pay for it, but I understand that there’s very little incentive for a developer to do a good job (or do anything) when he is not compensated for his work. So I paid for a license. Why? Because it looks great and is drop-dead simple to use (space bar and enter key are almost all you need), and none of the free alternatives worked as well, as much as I might have liked them to.

A feature that was added recently is the ability to watch video podcasts from within the app. So what? I don’t watch any - oh wait, I do watch Ze Frank. Hey that’s pretty cool! I can make it bigger without the silly cmd+opt+8 trick, and the space bar works.

If you’ve been itching to drop NetNewsWire Lite and go for a better app, this weekend people who buy NewsFire will get Inquisitor for free. And those who blog about the promo will get Inquisitor free too ;) .

I’ve renewed my interest in access control systems recently, and decided to review them a bit more formally rather than looking at specific implementations (NTFS permissions, UNIX permissions, etc).

Access Control Types

Discretionary access control

This system has users with directly assigned permissions. Assets have a concept of an owner, a user which controls access to that asset. An asset without an owner is theoretically defenseless.

Mandatory access control

This is a bit like concentric circles of trust, reminiscent of Meet the Parents, where users are placed in one of the circles and are allowed to access everything on that and all lower levels. Think “Classified” and “Top Secret”.

Role-based access control

This is widely regarded as a best practice, is where users have many roles, roles have many users, and users get permissions based on what roles they belong to. A user without roles has no access. This is great where you have large groups of people who all have similar access needs, such as point-of-sale employees.

What about the enterprise?

The above work well for single applications, but what happens when you have many applications? Each application’s administrator will likely need to manage the same set of users, or at least a large subset of them. This is inefficient, but also leads to other problems. The biggest problem is the fragmentation of roles. A few course-grained roles may be just fine for the primary users of an application, but what about those users who require access but are not easily pigeon-holed? Consultants, contractors, people from other departments, etc.

One paper I read suggested using a request-based permissions system, using a few course-grained roles to cover what can be easily covered. Users will then request specific permissions as they require them, with the request and approval process made a part of the system.

For example, I’m in marketing and I get the default set of permissions that come with that job. I typically do not need access to my company’s source control repositories. At some point I find that doing my job does require it for some reason, so I need to get access to it somehow. In the role-based system one of three things might happen:

  1. I’m given an existing role that allows SCM access
  2. An existing role is fragmented into roles with smaller permissions, and I’m assigned one of those
  3. A new role with the permissions I need is created without changing existing roles

The first is unlikely because it will likely give me more access than I need. The second is likely if this hasn’t been done for anyone else before, the third if it has. The paper I’d read claimed that, over time, this parallel management of applications would cause the number of roles to multiply until it became unmanageable, losing the benefits of the role-based system.

Under the request-based system I’d simply request access to the SCM. That request would be routed to the appropriate person to be approved or rejected. The access I obtain is assigned to me personally, not through any particular role.

Over time this leads to privilege accumulation since users will actively pursue obtaining the permissions they need to do their job, they won’t be so active in shedding those they no longer require. Therefore a periodical, hierarchical audit should take place.

Well, it seems that TextMate has grown another arm, and this arm specializes in blogging. This post is the first one I’ve written in it, and so far it seems pretty good. Simple configuration, easy to change post settings, etc.

In other news, I’m annoyed. Thanks world.

Grams and Grandpa Black gave me a book for my birthday called “The Automatic Millionaire” by David Bach. I read the introduction, and so far I’ve been amused at the style of his writing, which is a bit like a traveling medicine proprietor from the early 1900s, and by the obviousness of what he’s saying.

He claims that budgets don’t work. Discipline doesn’t work. Paying bills first and saving some of what’s left doesn’t work. Buying on credit doesn’t work (except in real estate). I agree with him, but the funny thing is that this is not really new to me - my other grandparents (the Donovans) have been telling me and my sister this for years, particularly that last point.

The most important thing about all of this, and the reason why discipline doesn’t matter, is that your finances should be automatic. This is again something the Donovans told me many times. I have a number of automatic financial transactions set up, but not all - some of which are intentional. I’m not sure why, but I thought that having to manually pay my credit card bill every month would give me more control, or at least notice, of my financial situation. It hasn’t. I always pay in full, so that doesn’t vary. It hasn’t made me more aware of my spending, as I’d hoped it would. In all it’s made me more worried about it.

The funny thing is that I could have easily applied the lessons I’ve learned from Agile Programming to my finances, the biggest one being that of automation. In software, you have certain assertions that, given such and such parameters, must be true. There are ways of codifying these assertions into what is usually called a Unit Test. After a while you end up with a suite of tests that, if comprehensive, will tell you how well your software is abiding by its contract. The problem with unit tests is that they atrophy very easily. It’s so easy to forget or intentionally skip the tests when developing. That’s why they need to be automated. When they are automated, you can’t ignore your software’s contract violations because they are in your face. The point is this: automate, or it will never happen.

The same applies to finances, though to a lesser extreme. I do pay my credit card bill even though it’s not automatic because there are serious and immediate consequences to my not doing it.

I’d taken a few steps on my own before I got this book that I think have helped my finances and my sanity:

No, I don’t want a receipt

I tried, unsuccessfully, for a long time to record every financial transaction I ever was involved in. This was detrimental because I spent more time on the overhead of bookkeeping than the money involved was worth. I constantly worried about stacks of unfiled receipts, staring at me on the kitchen table. I wanted to aspire to some level of financial mastery as the banker in Atlas Shrugged, who balanced his huge banking empire down to the penny.

I can’t do that, nor do I really want to anymore. Do I ever really want to find out how much I’ve spent on movie rentals in the last month? Or on eating out this last week with employees from j2? No. Not really. The need has never come up, and I don’t think knowing would benefit my financial situation much.

Quick, what’s the balance?

I wrote a script a while back to get the balance of my Wells Fargo accounts. It worked, but wasn’t that great. I’ve since improved it and added one for my credit card, and both of these show up on my desktop, updated automatically every three hours. This helps me track my finances much better than tediously recording receipts ever could.

Technorati Tags: , , ,

As I sit on my mom’s new sectional and look around her house, I start to wonder how I’m going to get home since I forgot my wallet…

Windows Vista is coming soon and with it a reevaluation of my choice to switch to the Mac. I very much doubt I’d choose to switch back, given the phenomenal power and beauty of OS X. Yet here are the things that, nearly three years later, still irk me:

WMV

Roughly 15% of the video content on the web that I encounter is in WMV format, usually v9 or greater. This presents a challenge that I haven’t quite conquered. Had the percentage been closer to 50%, I’d probably have figured out a way to play these files. Which I actually just did - Flip4Mac plays at least one file that I tried to play before. Problem solved.

Internet Explorer

This isn’t a Mac problem per se, but the effect is the same. Many website operators still think that they can just ignore that part of the population that doesn’t have IE5.5+. They can choose to do so, and I can choose not to use their website even when I have access to IE.

I mainly experience this problem through others, like my mom. She works for Kaiser, and Kaiser’s intranet assumes you are using IE for certain things like accessing Lotus Notes. Creating (or supporting) a monoculture like IE on Wintel is just begging for difficult and expensive IT maintenance.

Perhaps they’ve run the numbers and determined that they’d have greater support costs trying to support other browsers (i.e. Firefox) than a reduction of the usual IE/Windows problems would cover. If that’s the case, so be it. That’s just not a company that I’d want to work at.

Incidentally, my company, j2 Global, does a good job of allowing a heterogeneous set of browsers and OSes to be used in-house. Kudos.

Games

I don’t frequently play games, and the ones I did before (Diablo II, StarCraft) actually do run on a Mac. My current game is Counter-Strike, which I’ve picked up again after a long break. I’ll probably stop playing it once I get a social life, but until then it’s fun sometimes. It only runs on Windows, so I have to devote part of my PC to Windows.

Attitude

Why the choice of OS should be such a hot-button issue I don’t know. You are not your OS, and an attack on it is not an attack on you. I have to remind myself of this sometimes whenever someone starts saying bad things about Macs. Usually the speaker is part of the anti-Mac bandwagon whose ideas are not based on fact but on hearsay, but not always - its the latter type that I try to listen to and respond in kind. With the former sometimes they are unwilling to listen to reason and prefer their version of reality where Macs suck just because, but many aren’t so far gone and will listen when I put the facts to them in a non-threatening way.

Needless to say, this position of having to justify my decision over and over gets tiresome. The desire to take the blue pill and go back to sleep sometimes floats by my peripheral vision, but it’s easy enough to avoid.

Windows

Turning my attention to Windows now, I think it’d be interesting to take note of the things Microsoft would have to include (or exclude) in Vista to make me switch back, or at least to actually want to use Windows for anything other than gaming.

A decent shell

CMD just doesn’t cut it. It’s not so much the shell itself as the lack of utilities for it to make it a useful place to do something. Where are grep, sed, awk, less, ssh, gcc, wc, etc? I could use cygwin, but that would only have some pull if the other issues I have with Windows were fixed. In this respect, MSH looks somewhat interesting.

A better file system

NTFS is fine, a big improvement on FAT and FAT32. However I want the UNIXy goodness of symbolic links, arbitrary mount points, or good substitutes for these. Screw Windows’ drive letter convention! I’m pleased that Vista will at least be minimizing the focus on drive letters.

A better alt+tab

Command+tab in OS X allows me to use the arrow keys and the mouse once it’s up. Windows could take a cue from this. Exposé is another feature that Windows could use to manage its many windows.

A better task bar

Mac OS X has the dock which, while being basically a launcher, also shows me which programs are running, lets me open a file with a specific app, and more. That said, I don’t really use the dock. I use QuickSilver, and there is no good substitute on Windows (AppRocket doesn’t cut it).

Better integration of common services

Mac OS X has global spell-checking and an easily accessible Address Book API. These two are worth quite a lot to me. Mail, Adium, and many other apps use the Address Book to find contacts. The experience is just nicer.

Bundles

Mac OS X has a concept of bundles, or packages. It basically is stopping to ask the question of why file name extensions should only apply to files and not folders. This allows awesome things like single-file application installs and the ability to just try out an app without copying it to /Applications.

Windows has either installers or zip packages that need to be copied somewhere (e.g. Program Files, a kind of absurd name). Installers usually just get in the way, and don’t actually let you configure anything for most smaller apps.

Having this ability in Windows would be really cool.

Technorati Tags: ,

This game, Spore, looks awesome. It uses procedural logic to figure out how to animate the characters and create the sounds. Most current games generate all the content beforehand, which is a very time and money-consuming process.

This type of game is what I’ve always thought should be developed. It will eventually allow for better realism. The video is long, but well worth watching. It’s quite ambitious.

Technorati Tags:

Next Page »