Cache it all

I recently redid my personal web site, at welton.it. Wanting to be quick about it, and make the look and feel a bit more uniform than it has been in the past, I hacked together some pages in Rails. Despite this being sort of a “killing a fly with a bazooka” situation, I’ve been doing lots with Rails, so it was quick to use. Here’s the thing, though: Rails is definitely overkill, as the site is basically static. I don’t need to calculate anything or fetch stuff from a database – I just wanted a reasonably good template system, and I am quite comfortable with Rails these days.

But the idea of leaving Rails running for a static site was of course no good: I basically need to cache the entire thing, so that Rails is simply not involved. How to do this as quick as possible (in between diaper changing and other baby duties!) ? Ideally, it would be possible to introspect Rails in order to know exactly which pages are present, then cache those, and avoid Rails on the server entirely (just generate them locally and put them in subversion), but that proved to be fairly hacky, so I settled for this code, which simply caches all pages which comes across, when caches_pages is placed in application.rb:

class CacheFileName
  include ActionController::Caching::Pages
  include ActionController::Caching::Pages::ClassMethods

  def cachedname(path)
    page_cache_file(path)
  end
end

def caches_pages()
  return unless perform_caching
  after_filter do |c|
    res = c.cache_page
    cfn = CacheFileName.new
    cf = Cachedfile.new :filename => cfn.cachedname(c.request.path)
    cf.save!
  end
end

It simply caches everything. To be able to easily clear out the cache if there are any changes to the site, we record the changes in the Cachedfile model, which is defined like this:

create_table "cachedfiles", :force => true do |t|
  t.string   "filename"
  t.datetime "created_at"
  t.datetime "updated_at"
end

with this model:

class Cachedfile < ActiveRecord::Base

  def Cachedfile.clean_cache
    Cachedfile.find(:all).each do |cf|
      begin
        fn = ActionController::Base.page_cache_directory + cf.filename
        File.delete fn
      rescue => e
        logger.error "Error deleting #{fn}: #{e.inspect}"
      ensure
        cf.destroy
      end
    end
  end

end

which has a class method to go through and clean out all the cached files. I call it manually from ./script/clean_cache:

#!/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'

Cachedfile.clean_cache

It’s not a beautiful system, but it gets the job done.

New “Jim” Maintainer

Tcl is a fairly old language, nearly 20 years old this year. It’s also quite widespread, even if it’s not as popular as it once was. This means that a lot of things are fairly set in stone, and not likely to change short term. It also means that with time, it has grown quite a bit as a system, and has lots of pieces.

Several years ago, my friend Salvatore “antirez” Sanfilippo set out to create his own version of Tcl, something smaller and more flexible, and under his control so as to avoid being tied down with baggage from the past. The result was Jim, which, according to the web page:

… implements a large subset of Tcl and adds new features like references with garbage collection, closures, built-in Object Oriented Programming system, Functional Programming commands, First class arrays. All this with a binary size of about 85kb (that can be reduced further excluding some non-vital commands, and commands not available in Tcl itself).

which has made it popular with people who need a small scripting language for things like embedded systems.

Unfortunately, Salvatore hasn’t had as much time to work on it as he might like, being busy with money making web things (it’s tough to make money on programming languages), so it’s good to see that he has added

The Google street view team is putting in some miles

I’m impressed at how much Google street views are growing. From a high level view, it looks like some sort of 1950’s B movie alien invasion: link.

What’s even more impressive are some of the out of the way places they’ve been: link. I can’t imagine what they were doing up that road. Perhaps they wanted someplace secluded to go smoke a joint, and they left the camera rolling? It’s sure a beautiful road in any case – it looks like a great place to go for a bike ride.

Startups: government help and hindrance

Aaron Swartz writes about what government might do to encourage entrepreneurship:

http://www.aaronsw.com/weblog/prostartup

As an American who has lived in Europe for a while, I’ve seen both sides of the coin (or pond, as it were), and feel qualified to add a few things to the conversation, even if many of these points merit a discussion of their own.

  • He’s right about health care. It’s one of those things with a huge downside risk that people in Europe simply don’t have to think about. You can change jobs, take a break from a job, start a company…whatever, and you never have to think about “what if”. Even if you have the sort of preexisting condition that can hang like a stone around your neck in the US. How to implement such a system (which of course has potential disadvantages as well) is well beyond the scope of this journal.

  • Universal education. I don’t think it’s as great as Aaron seems to think, but I don’t think it’s very influential one way or the other on startups. People get good educations in both places, although, by and large, the best Universities are in the US because they have more money, and have in the past attracted highly qualified people from all over the world. In both places, students manage to meet other like minded people with whom they can start companies. There are definitely improvements to be made to the US system, but that’s really just a political discussion: like I said, differences in universities are not the limiting factor.

  • Minimum income without having to work or even having to look for work sounds like an enormous can of worms. Might be good for startups, but has big risks associated with it, and wouldn’t be politically feasible in the US. Even in most European countries with that sort of thing, you don’t just get money: you have to look for work, do job training, or prove that you’re just not capable of doing anything productive.

And here are some thoughts of my own:

I think it’s best to focus on the startup “curve”, and costs associated with various points on it: when people are just getting started, keep state-imposed costs low. If someone makes a lot of money, worry about taxing it then.

This is quite different than what has previously been the norm in many places in Europe, which have policies akin to slaughtering the goose before it lays any eggs, let alone golden ones. Italy is a particularly bad example, but it’s the place I know best, and not too far off what happens elsewhere in terms of policy: fixed, sunk, startup costs are in the order of 10,000 Euro, which for most people is a lot of money. This creates a bias towards people who already have a lot of money, and away from random people who happen to have good ideas and a strong desire to execute on them. This is something that the US more or less gets right: it cost me $55 in state fees to start DedaSys LLC as a limited liability company (even throwing in money for lawyers and the like, you’re still far under the thousands it costs in many European countries).

Incidentally, it looks like Germany may be on the right track, if you look at the “Mini-GmbH” mentioned in the article. It’s progress, if nothing else.

Beyond that, there is a lot more red tape in Europe, and that, I think, rather than a bit higher taxes for companies that are profitable, is the thing that, outside of culture, probably weighs most heavily on European startups.

Culture, however, is also a very key factor, and not something that will change soon or easily. In Italy, there’s a lot of pressure to land a permanent job, from which you can basically never be fired. The idea of striking out on your own is probably simply not on most people’s radar screens. I think culture is what means that Europe produces tons of great open source software, for example, but relatively fewer startups (if you’re just counting open source startups though, Europe does ok). Perhaps this is slowly changing, but it will take a while, and without some policy changes, the incentives won’t even materialize.

Returning to things that government can do, something critical that many people don’t get is that government funded startups are usually big failures (see the French “Google competitor”) and a big waste of money that would probably simply be better to spend in lowering taxes, improving education, or other “level playing field” initiatives, rather than having government employees attempting to “pick winners”. This is a common problem in Europe, but also in many areas of the US that want to replicate Silicon Valley’s success.

Going back to the US, which was Aaron’s original point of focus, beyond health care, what could the US improve? At the moment, immigration seems to be the big problem: people from all over the world want to go to the US to work and start companies, but look at what kinds of hoops someone (who is coming to spend money and create jobs!) has to jump through to do so:

http://www.techcrunch.com/2008/05/02/coming-to-america-getting-visas-to-do-business-in-silicon-valley/

Embarrassing and shameful.

In conclusion, I think the common theme is that the government can’t really do much to actively promote startups, but can certainly hinder them by setting too high a bar in terms of bureaucracy and fixed costs. Lowering those fixed costs for new companies, be it through at least basic health care for everyone, or lower taxes and less paperwork should be what governments aim for. Given the right conditions and incentives, bright, hard workers will do the rest.

indent-region-as

At times, when I’m working with an HTML file – an article about programming, for instance – I need to include a snippet of code inside a <pre> tag or a <code> tag. It’s very annoying to have to indent that code by hand, and since the language may be anything from Hecl, to Erlang, to Java to C, I don’t want to use something like two-mode-mode for Emacs, so I threw the following elisp together:

(defun indent-region-as (other-mode)
  "Indent selected region as some other mode.  Used in order to indent source code contained within HTML."
  (interactive "aMode to use: ")

  (save-excursion
(let ((old-mode major-mode))
  (narrow-to-region (region-beginning) (region-end))
  (funcall other-mode)
  (indent-region (region-beginning) (region-end) nil)
  (funcall old-mode)))
  (widen))

To use it:

  1. Put it in your .emacs file.
  2. Select the region to indent according to the other mode.
  3. M-x indent-region-as – which will prompt you for the other mode to use. You need to give the function for that mode, such as tcl-mode, java-mode, ruby-mode or whatever.

My elisp is a bit rusty, so I’m sure it’s possible to improve the code above, but it does the job for me.

Craigslist not in Yahoo Search index

Probably not that interesting to most people, but Yahoo Search doesn’t seem to have craigslist in its index:

http://search.yahoo.com/search;_ylt=A0geu5xC60ZI8BgB5Byl87UF?p=site%3Acraigslist.org+jobs&ei=UTF-8&iscqry=&fr=sfp

Google does, of course. This matters to me because I use Yahoo Search’s API to collect statistics for http://www.langpop.com, and one of my sources is craigslist. I let craigslist know about the problem, and hopefully it will be fixed soon, so I can collect the stats for June!

Update

Looks like it’s being indexed again, but still isn’t back to where it once was, so it’ll probably be a few days until I update langpop again.

An impressive amount of resources

In the TechCrunch coverage of Google IO, I was impressed by this:

Not every team has the resources Google does to build for every platform. Google is betting on browser over time for mobile devices; it will be the entry point for many applications.

But today, the only browsers capable for supporting mobile apps include iPhone and few others. So Google is developing Android, which includes world class Webkit browser.

Here at the world headquarters of DedaSys LLC (which for the time being happens to be “in front of David’s computer, wherever that is”), we too have some suspicions about the browser becoming the platform of choice for mobile phones, although there is a big if:

When will the carriers make always on, cheap internet connections widespread?

Until that happens, client side apps will still probably dominate for many things. And of course for applications requiring hardware access, some kind of local program will be necessary as well for the foreseeable future. (And of course, Hecl is a good choice “for the time being”, too!)

Coming back to the phrase cited above, what blows me away about it is the sheer amount of time and money that they’re investing in something that “over time”, they’re not really betting on, in the sense that they just want browsers everywhere? Jumping into a market with a new “OS”, toolkit, etc… just to spread a platform with a decent browser?

Wow. That is a company with a lot of spare change. Most people and companies in business are doing the best they can to stretch out their dollars or euros as best they can. I guess it really takes a behemoth to pour so much in the way of engineering talent and financial resources into something that’s in some ways a bump in the road in terms of their long term vision. Or maybe I’m just reading too much into one phrase?

Minor annoyance: spell checking in Firefox + multiple languages

I write most of my email (in gmail) and submit most web site content in English, however, a significant portion is also done in Italian. I leave the spell checker in English, because Italian is, in general, quite easy to spell, so that even as a native speaker, a helping hand is occasionally welcome. However, it isn’t as if I write Italian perfectly either, so the help there would be nice as well. I find it quite annoying to go change the language in the spell checker option each time, especially when, as an example, I’m responding to email and do 2 in English, one in Italian, another in English, and so on.

Ideally, some sort of adaptive technology would be possible, where it figures out what language I’m using, out of a preselected list, after a few words, and starts behaving accordingly.

It seems as if there is some discussion, so hopefully a solution won’t be too far in the future.

Ubuntu: update, don’t reinstall!

I’ve seen a lot of people talk about simply reinstalling Ubuntu with the latest CD in order to update it to the latest version. I think that’s a bad habit from other OS’s. For as long as I’ve used Debian and its derivatives, the ability to update the system has been one of its strong points.

Here are some reasons to run the updates instead of upgrading via a fresh install:

  • You don’t lose your old configuration information, and by choosing to see the diff’s in configuration files, you can even choose which config files to update, and how.

  • No need to shut down a running system.

  • By keeping an eye on obsolete packages, you really don’t build up any cruft at all, so that’s not a reason to do a fresh install.

  • With a decent internet connection, it’s probably just as fast, if not faster, when you consider it takes a bit of time to get everything installed just the way you want it.

Indeed, yesterday, I upgraded a server I run in Texas from Ubuntu’s edgy eft to hardy heron, remotely, with one reboot at the end to make it pick up the new kernel, and the whole thing came off without a hitch!

Neat Hecl app from newcomer

This is a cool little application, and a helpful tutorial for people trying Hecl for the first time. Since I know the system so intimately, people doing these kinds of pages are always a helpful reality check, pointing out where people new to the language hit stumbling blocks, and providing a guide for people who haven’t “been there and done that”:

http://lauri.ojansivu.googlepages.com/heclcommandlineapp

Thanks Lauri!