This is a blog about me, Seinfeld, okonomiyaki, japanese toilet seats, and other things of interest

Thursday, September 27, 2007

Just Married!

Wow, what an amazing day. Good friends and family celebrating with me and Angela. Probably Ar!s describes it better in words than I could ever do.

A few pictures are available here.

Now we're busy packing up the flat before going on honeymoon to Kenya and Tanzania tomorrow. Then back here the 20th of October before moving to Oz the 27th of October.

I'm married! (who could ever have thought :-))

Monday, September 17, 2007

Slashdot

Is anyone actually reading slashdot anymore? I just realised today that I haven't read a single slashdot article in last week! Usually I look at the headlines in my rss reader and just move on as there is nothing of real interest anymore (and if it is interesting it's a day or two late).

Vinyl

Went on a shopping spree on Ebay the other day and purchased the following old goodies (on vinyl of course):

Kraftwerk - The man machine
Dusty Springfield - A girl called Dusty
Al Green - Let's stay together
The Smiths - Hatful of hollow
The Stone Roses - S/T
The Motown Collection
Al Green - The Best of Al Green
The Chi-Lites - Chi-Lites

I'm particularly pleased with Let's stay together that I've been looking for for quite some time.

Just bought - for maybe the first as well as last time - seafood sticks today. These usually go by the name crab sticks in the US, but for some peculiar reason are they called seafood extenders in Australia. Seafood sticks are mostly made of surimi, a kind of fish puree from really cheap fish that no one else wants. Nowadays all kinds of things are made out of surimi, and in Oregon there's even a surimi school.

Thursday, September 13, 2007

Exit Only

So I've finally written my first at least slightly useful Erlang module, fetch. fetch is an url-fetcher that can download the content of a url or a list of urls specified in a file (one url per line):


-module(fetch).
-export([fetch_url/1, fetch_urls_parallel/1,
fetch_urls_sequential/1, main/1]).
-import(lib_misc, [pmap/2]).

% Returns {Url, content}
fetch_url(Url) ->
inets:start(),
case http:request(Url) of
{ok, {_, _, Body }} ->
{Url, Body};
% Error, return empty string
{_, _} -> {Url, []}
end.

% Reads the file File name and returns a list with one item per line
read_lines(Filename) ->
{ok, F} = file:read_file(Filename),
string:tokens(binary_to_list(F), "\n").

% Fetch content of all urls in list parallel to list of format [{Url1, "content"}]
fetch_urls_parallel(L) ->
pmap(fun(X) -> fetch_url(X) end, L).

% Same as above but sequential
fetch_urls_sequential(L) ->
lists:map(fun(X) -> fetch_url(X) end, L).

% Usage fetch:main(filename)
main([A]) ->
% Read the file
L = read_lines(A),
% Download content
R = fetch_urls_parallel(L),
% Print each url and content size
lists:foreach(fun({U,C}) -> io:format("url:~s ~w ~n", [U,length(C)]) end, R),
% Stop and exit
init:stop().

Start with
diaspora:~/uri_test$ erlc fetch.erl; erl -noshell -s fetch main uris3.txt

(lib_misc need to be in your Erlang path)

The interesting part is fetch_urls_parallel that uses the lib_misc:pmap function from Joe Armstrong's Erlang book to fetch all urls in the list L in parallel. This can be contrasted with fetch_urls_sequential that fetches each url one by one using normal lists:map.

For fun I decided to write something similar in Ruby and compare the speed. Here's the Ruby code:

require 'open-uri'
require 'timeout'

threads = []
File.open(ARGV[0]) do |f|
f.each do |l|
c = ""
threads << Thread.new do
begin
Timeout::timeout(20) do
open(l) do |response|
c = response.read
end
end
rescue Exception => e
ensure
STDOUT.printf "%s %d\n", l[0...-1], c.size
STDOUT.flush
end
end
end
end

threads.each {|t| t.join}

Using a file with 100 urls and running each program 100 times I found that the Erlang code was almost 50% faster than the Ruby code! Not really sure why, but I suspect that open-uri plays a big part.

Tuesday, September 04, 2007

Icecream eating motherf**kers

I usually don't like whatever meaningless stuff bands say between songs at gigs: "Are you feeling alright?", "It's great to be back in X!", "Save the environment". I mean, just get on with it and play dammit. If I wanted to hear spoken word I would go and see Henry Rollins or Ricky Gervais. I'm sure that Kraftwerk doesn't say a word between their songs and they are still better live than all other bands put together.

Ok, Fugazi are quite entertaining, especially when they have to deal with all violent idiots that seem to hate their message and music so much that they just have to go and see them live and annoy everyone around them. This is an amazing clip where they have to deal with some icecream eating motherf**kers.