Microsoft – an exercise in frustration

I’ve been investigating ways of testing out applications like Stuff to Do on Windows, and boy has it been frustrating. It’s not a fun task in the first place, as I’d rather be coding than trying to deal with crappy incompatibilities between browsers and operating systems.

I first looked into VMWare products, which look pretty good. The Workstation version has a free 30 day trial download, and the basic player is free of charge. Unfortunately the Ubuntu player packages appear to be seriously broken. Qemu also looks like a good possibility. I don’t care if it’s not blazing fast, just as long as reloading a page in IE doesn’t take 5 minutes. I think I could make either one of those options work.

However, the hairy, gorilla size problem is the microsoft operating system itself.

I don’t want to deal with Vista, because it’s a hog, and emulating a hog is bound to be slow. So I’d like to get XP, and since I’d prefer people to respect the licenses of software I write, I think it’s only fair to get a legitimate copy, even if my friends here in Italy will probably think I’m batty.

Overlooking the fact that the basic retail price is $200, which is somewhere north of double what I think is reasonable, it seems as if you can’t even download the damn thing and pay with a credit card. How antiquated is that? I want to be up and running now, not fiddle around with a CD that might arrive a week from now.

The end result: massive amounts of frustrating and nothing to show for it. That I would have avoided if I just found a cracked version. I think for now I’ll just put up some extra ‘get firefox’ banners on my sites:-/

ActiveRecord nitpick – no constant iteration over select results

I need to iterate over a big set of data, and I want to do it without sucking the whole thing into memory. Unfortunately, as far as I can tell ActiveRecord does just that, which is a pity because it could probably be made to do something like this

Foo.find_and_loop(:all, :conditions => '....') do |res|
  do_something(res.foo, res.bar)
end

without too much trouble. You’d have to have some fancy interaction between AR and the connection adapters so as to run your loop at a low level, but it should be possible. All the databases that I looked at let you operate that way in their C API’s.

Doubtless, this is something “opinionated”, and of use to a small percentage of rails users, so it’s probably not worth submitting a bug report, but it’s a minor annoyance all the same.

Caching “streamed” content in Rails

In a previous article, I illustrated one way of generating streaming content programatically.

The application utilizing it is still slow in sending it, though, because it’s got to interact with the database, process the data, and so on. The ideal solution would be to cache it, however, the normal rails cacheing solutions don’t work, because the return value is a Proc, and if you try and write that to disk, it just writes the equivalent of proc_object.inspect, which doesn’t do me much good.

However, I figured out a clever way of running the exact same controller method “standalone”, and stashing the results to disk. I placed this file in scripts/cacher:

#!/usr/bin/env ruby

ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'development'

require File.dirname(__FILE__) + '/../config/boot'
require "#{RAILS_ROOT}/config/environment"
require 'console_app'

app.get '/mycontroller/big_results_method'

resp = app.controller.response
File.open("#{RAILS_ROOT}/public/cached_big_results.csv", 'w') do |out|
  resp.body.call resp, out
end

I think it could be improved, because it seems to be running the DB query twice – once during the actual app.get, and once again when the Proc is called. But, in any case, it works, and now I can call it from a cron job.

Trawling for reading material

Yep, time to stock up on some new books. I’m interested in:

  • Business (startups and the like)

  • Economics

  • Marketing

  • Technology. Classics, though, books about the latest this or that are less appealing these days, because the net simply has so much information available.

That’s certainly a broad range, but the reason I’m writing here, is that I’m looking for books other people like me considered a good read, and not just an idea I can glean from the wikipedia summary of the book.

Yoav seems to share some of my tastes, for instance.

Some of the books I’m considering:

  • Founders at Work, by one of Paul Graham’s collaborators. Looks interesting, but I’m a little bit dubious about the ‘lots of anecdotes’ format. Do you learn anything repeatable from it, or just motivational tales of yore?

  • Something from Guy Kawasaki – Rules for Revolutionaries?

  • Over 20 Years of High-Tech Marketing Disasters

  • Don’t Make Me Think: A Common Sense Approach to Web Usability

What I’ve already read, and would recommend to others:

http://www.dedasys.com/freesoftware/ (under ‘Recommended reading’)

Popouts with Rails

In a previous article about Stuff To Do, my ajaxified priority queue program, I talked about how best to keep track of the user’s state of activity, should they so desire.

I opted for the popup, as that was the best compromise between simplicity, and ease of use for the end user. From an end-user point of view, it’s similar to how gtalk can detach from gmail if you want to run it in its own window.

The trick was to implement the popup/popout in Rails, which actually ended up being pretty easy, and, all things considered, is a pretty cool technique. It’s neat to pop stuff in and out of a web page.

The easy part is popping out the window:

<%= link_to_remote("Pop out " + image_tag('popout', :border => 0),
                   {:url => { :controller => 'tasks', :action => 'popout' } },
                   :title => 'Pop the status window into a popup window') -%>

Which subsequently calls popup.rjs:

page.replace_html('status', "<i><small>status in popup window</small></i></br>" +
                  link_to_remote("<small>Restore</small>",
                                 {:url => { :controller => 'tasks', :action => 'popin' }},
                                 :title => 'Restore the status window'))
page << 'statuspopup();'

Which is pretty simple – the first call replaces the html in the status div, and the second calls the javascript function statuspopup. This lets us replace what was in the status window with some placeholder text and a ‘restore’ link in case things get screwy and the user wants to simply restore the old content of the div in question. It’s worth noting that we also store the popped out status in session[:popped_out] in order to let the application know that the window is “popped out”.

This doesn’t actually pop the window itself up. The statuspopup function in javascript (located in application.js) takes care of that:

function statuspopup() {
  window.newwindow = window.open('/tasks/openstatus','status',
                                 'height=10,width=210,status=no');
  return false;
}

And then the openstatus action opens the same rails partial that the regular page does:

<%= render(:partial => '/tasks/status', ...

Meaning that you don’t have to rewrite the same code in two places.

So, that’s all it takes to pop up a new window, and replace the contents of the old div in the html page giving the user the sense of having popped a piece of the page out into a popup.

So far so good. Now what happens when the user closes the popup? Luckily, we get a reference to the window that opened the popup called window.opener that we can use to comunicate with the main window. For instance, in our case we set up an event listener to fire when the window closes:

window.addEventListener("unload", statusClosed, false);

And this, in turn, takes care of popping the window back into the main page:

function statusClosed() {
new Ajax.Request('/tasks/popin', { method: 'get', asynchronous: false })

$('popoutlink').style.display = 'inline';
w = window.opener;
target = w.window.document.getElementById('status');
code = $('onidle').childNodes[1].innerHTML;
target.innerHTML = $('status').innerHTML;
target.style['backgroundColor'] = '#bbddbb';
target.style['backgroundColor'] = '#bbddbb';
w.eval(code);
}

Once again, pretty simple. What’s happening:

  • Ajax.Request just takes care of letting the rails app know that we’ve popped in, which resents session[:popped_out].

  • Then grab the window opener, and find the status element within that window.

  • Instead of re-rendering everything with a rails partial, we simply transfer the HTML that was residing in our popup to the main window:

    target.innerHTML = $(‘status’).innerHTML;
    target.style[‘backgroundColor’] = ‘#bbddbb’;
    target.style[‘backgroundColor’] = ‘#bbddbb’;

We also fix up the color just a bit, to mark the user as active.

All in all, it’s pretty useful for time tracking. In Linux, it’s ver easy to set the new popup to follow you around the screen, making it so that it’s not a bother at all to wave the mouse at it to let the application know you’re online. All you do is set the ‘on top’ and ‘always on visible workspace’ options – at least in Gnome.

In Thrall to Scarcity

As I’ve talked about in this space in the past, I’ve been coming to some conclusions about free software (open source, or whatever you want to call it): the economics of it, like anything else, are rooted in scarcity, and if you don’t have a bit of that scarcity yourself, you have a lot less leverage

This line of thought comes from the age-old question “how to create free software and make money at it?”. This is a very important question for me, because I enjoy hacking on free software very much, and would love nothing more than to spend my days doing so. Creating new things, though, rather than working as a “system integrator” and tying pieces together with the smallest amount of glue possible. It’s obvious that there is plenty of money to be had for people who simply use free software for their own ends. But what are those ends? We live in a world of scarcity – not everyone can have a fancy car, the nicest house in town, or the fastest computer. Market economies work via the exchange of scarce goods and services. If you have nothing to trade, you have nothing. Now, free software is worth something. Worth a great deal – that is beyond the shadow of a doubt. But since anyone can make a copy, there is no scarcity – once it’s out there, you can’t trade for it.

So… where does this leave our potential free software creator? Let’s think about some of the ways around this problem.

  • You could, as some have argued, decide that since software has aspects of a public good, and decide that it should be provisioned by the government. Computer users pay taxes and there is a ministry of software that pays people to work on infrastructure type projects like the Linux kernel, Apache web server, and the like. Whether you like this idea or not probably depends on what you think of governments, free markets and so on, and thus becomes a much broader debate, but suffice it to say that it’s not going to happen soon, because free markets do provide software, so most governments aren’t likely to fiddle with the system in radical ways.

  • Work on contract to create custom systems for clients. This works, up to a point. Since the initial system doesn’t exist, there is your source of scarcity. The client wants it, and won’t get it – free or proprietary – unless they pay you. It’s also worthwhile to think about the “chain” of trade in this case.

    Where does your client get their money? If you’re writing free code that will simply become a cog in their proprietary system, the actual money comes from the scarcity they have created, so while you may be writing free software, in one sense, you’re simply offloading the burden of creating scarcity to someone else, who is then able to pay you for your time. The other possibility is that your client works in the “real world” of scarcity directly – they sell books or beer or cars or something else where the product is, by its nature inherently scarse.

    In this case, they still have the leverage – you work to help their business, but they are the ones in the driver’s seat. Your work isn’t worth much without their scarcity-based business. And they’re not very sensible if they pay you for things that aren’t directly related to their business. So it’s going to be harder to create something new and interesting from scratch.

I’ve alluded to it in the past, but consulting operations have several problems, especially when considered from the point of view of someone who wishes to create software:

  • The more time you spend putting existing pieces together, the better you are doing financially, because you can finish the project quicker, in less time, and so have more of a margin. These sorts of business will tend towards system integration, rather than the creation of new things. That’s not a bad thing, and I mean no disrespect to those who are in that business, but it’s not really what I want to do, and it certainly doesn’t answer the question of how to write new free software and get paid to do it.

  • When you create a one off solution that is not completely tailored to one client, if you make something that’s proprietary, and know you can sell it to a few more people, perhaps you can beat the free software guy on price, because you can afford to sell yours at a lower price, knowing you’ll spread the costs of producing it over a few clients. If the free software guy manages to sell the same free thing to several clients, you have to ask how ‘free’ the software is in the sense that it is apparently controlled tightly enough that these other clients can’t come into possession of it on their own. Once, again, scarcity.

  • It’s not a business that ‘grows’ as well as having a proprietary product, because it’s very linear. To make more money, you have to add more people (of uncertain quality, I might add). With the proprietary product, on the other hand, you could likely sell 100, 1000 or 1000000 copies with a workforce of the same order of magnitude. This leaves you a bit more breathing room – if you’re a consultant, the minute you take a break, be it a vacation, or even go to sleep, you’re not making money because you’re not engaged. That’s sort of a scary prospect as one ages, and needs to dedicate time to other things in life. At 20, I could spend all day every in front of the computer. At 30+, now I have a wife. Maybe there will be kids some day. A successful product-based business would allow me time for those things that a billable-hours business might put more constraints on (of course, there are obviously no guarantees that any business will be successful, but for the sake of argument, we’ll treat failure as failure and not worry about it more).

So, there you have it. In one way or the other, to make money at something in the long run, you are going to have to find and sell a product that people cannot effortlessly get for free.

I Spy

Well, not really, but some people might think so, or feel intruded on…

To back up a bit, and put that in context, I’m currently contemplating ways of making Stuff To Do, my web based todo list/time tracker/work organizer more able to track when a user is active. Currently, it marks you as active if you do anything at all in its web page. The reason I adopted this approach is that I want the program to help the user out, not make the user a slave to the program (ok, switching tasks, hit start..stop…stop stop start stop start start…bleagh!). However, even this approach relies on the user keeping the window open, and visiting it every now and then, which is less likely if you get ‘in the zone’ and are concentrating on your own work. A couple of methods for dealing with this come to mind:

  • Platform specific binary that can be installed to keep track of when the user is active. This would be the most accurate way of determining that information, but also the most intrusive, and probably the least convenient for end users, who would have to install something on their machines.

  • A reminder. Instead of tracking the user, try and get their attention to come back to the web page and let the app know they’re still alive. Not very appealing, because the concept of “bug the user so they pay attention to me”, which is not in keeping with the “be unobtrusive” philosophy of the system.

  • A small pop-out window with “active?” javascript code embedded in it. On Linux (Gnome’s window manager at least), you could even set this little window up to follow you around the desktop in order to register the fact that you’re active. Advantages: web based, more accurate than the current system. Cons: annoying window following you is….well, annoying. Having a little window open all the time might be an annoyance as well.

Thoughts? Would you use any of these, or consider any or all of them too high a price to pay to keep track of your hours?

Using Migrations Outside of Rails

A while ago, PragDave wrote about using Rails migrations outside of Rails.

I wanted to be able to have things work ‘just like in rails’, so I hacked up a quick script that runs all the migrations in the files/ directory:

require 'rubygems'
require_gem 'activerecord'

if ARGV[0] =~ /VERSION=d+/
version = ARGV[0].split('=')[1].to_i
else
version = nil
end

@logger = Logger.new $stderr
ActiveRecord::Base.logger = @logger
ActiveRecord::Base.colorize_logging = false

ActiveRecord::Base.establish_connection(:adapter  => "mysql",
:username => "dbuser",
:host     => "localhost",
:password => "xxx",
:database => "yyy")

ActiveRecord::Migrator.migrate("files/", version)

It would be even nicer to have a config file, but that should be very easy to do with YML.

I run it like so: ruby domigrations.rb. I believe that the Migrator.migrate call isn’t documented, so I don’t know how safe it is to count on it, but for the moment things seem to work quite nicely…

Mobile Phone Shopping List 1.0

I created a mobile phone shopping app a while ago with Hecl, and since it seems to have become fairly popular, I did a second, more polished version that is still very simple to use: ShopList.

I think it’s a good way of utilizing a mobile phone and the web together – you enter the list of things to get in a web page, then the phone fetches that list. Realistically, inputting a long grocery list on a phone would drive you mad, whereas with this application, it’s quite fast, and what’s more, it makes use cases like this possible and simple: I’m going to the store, so my wife creates a list on the web site, and sends me the list id, which I use to fetch the list when I’m at the store.

Oregon – Italy high tech links

I received a very interesting email the other day from an individual who works for the state of Oregon seeking to forge ties with high tech companies abroad. They don’t have a great deal of resources, but they do have some contacts, and are open to dealing with even relatively small organizations.

I have to say that there is some really interesting stuff happening in Oregon in terms of open source lately (beyond Linus Torvalds living there), so if any European companies, or university professors are interested in going over to have a look, I’d be more than happy to pass the information along.