BLOG

Fossiling

February 10th, 2008, General, Trips, 2 Comments

The weather yesterday was remarkably nice for the time of year, so I went fossiling in Sølrod municipality. My reasons were because I’d never travelled further south than Ishøj on the S-tog and because this website promised fossilised sharks at Kalstrup lime quarry, and I thought I’d like one for my room.

An hour after leaving the train station at Sølrod in a westerly direction, I was beginning to regret not bringing a map. The area is a hotchpotch of tiny villages and vast open countryside. All I had to go on was a brief glimpse at Google maps twenty minutes before I left home.

I decided to stick to the roads and just enjoy the exploratory walk. During a total walking time of four hours, I remarkably managed to not only find the anticipated kalkgrave, but also to navigate myself to the distant village of Karlslunde and a bus journey home. The only upsetting part was that by the time I reached the quarry, the light was too disappointing for any photography or excavating.

Feeds

February 10th, 2008, Discussion, Good things, 2 Comments

E-mail is fantastically popular and probably the most widely used internet technology. Even the generations outside the traditional scope of the internet explosion seem to grasp the concept. I think the reasons for its growth are two fold. Firstly the direct benefits to communication in the workplace saw it quickly adopted en masse and introduced into employees’ daily lives. Secondly the growth of web-based clients, such as Hotmail, in the late 90′s brought the benefits to the social realm, all wrapped up in an accessible interface. All of this is wrapped up with an elegant name. Electronic Mail is an analogy that most people quickly comprehended by glueing together their experience of the regular mail system along with telegrams and the telephone.

The above introduction already starts to list the reasons why feeds haven’t achieved the same degree of ubiquity. They are sadly still lingering around the fringes of ‘geek territory’ and still fail the explain-this-to-your-parents test. Feed, RSS, XML, Atom, aggregate and syndicate are all terms that do nothing to demonstrate the frighteningly simple concept.

The feed analogy should be as easy to grasp as electronic mail. For those of you still confused by the technology: a web feed is essentially being told about new information in a timely manner within the comfort of your own ‘home’.

We can consider browsing a list of bookmarked websites each day, to be analogous with routinely visiting several shops to see if they have what you want. The fresh milk or new jumper might not be in stock for days, but we have no way of knowing and so must keep checking back. Sometimes we are successful, other times we are not, but the effort is always the same.

In this same world, feeds are much like hand-delivered parcels. We’ve told the shopkeepers what we’d like and so the items are packaged up and sent directly to our door when ready. If receiving an e-mail should be like receiving a personal postcard from a friend, then receiving a feed is having magazines or goods delivered. An e-mail client will receive the former, and a feed reader the latter.

E-mail is of course heavily abused these days. It’s used for many impersonal tasks such as content mail-outs, update notifications, status notifications, etc. In fact it’s precisely because e-mail is so widely adopted that it’s become the landing ground for all these things. E-mail is now like a ringing phone constantly demanding attention.

If having a newspaper delivered to your door sounds preferable to trudging to the newsagents every day, or even having the journalist call you up every time there’s a new story then maybe feeds are for you.

This video is an excellent introduction:

Recently

February 5th, 2008, Drawings, Leave a comment

I just found these half-finished pieces in my sketchbook that I’ve forgotten to finish. I should finish them.

While I was flicking through the images on my laptop a very strange thing happened to the portrait drawing. I started rotating it in Windows Image Viewer and on each 90° turn the image started degrading. Then it started saturating itself, before eventually blurring into the threshold colour mess you see below.

Now I realise that most of the operations available in Windows Image Viewer are lossy (it transforms, reapplies the compression algorithm and then re-saves over the original), but the effect was quite ridiculous/amazing in only about 1800°. I quite like it. I think it looks like some thermal imaging paper baked in the oven.

I’m planning to attend the Copenhagen Ruby Brigade meeting tomorrow night. I think they switch meetings to English should people of limited Danish fluency turn up. I hope this is true.

dsc06604.jpg

dsc06605.jpg

dsc06610-4.jpg

dsc06610-2.jpg

Customising form controls in Rails

February 3rd, 2008, Programming, Ruby on Rails, Leave a comment

Here is a simple way to implement custom form controls while still using Rails’ standard helpers. For this example, we’ll implement a two-state graphical alternative to a check-box (usually implemented by the operating system and uncustomisable via CSS), which represents a standard boolean field in your database model.

Normally we’d do something like in our view:

    <%= form_for @model, :url => { :action => :create } do |f| %>
        <%= f.check_box :someBool %>
        <%= f.submit("OK") %>
    <% end %>

But we’d like to use something a little like this to represent our field instead:

Active
Inactive

Firstly the images are added to our Rails view via the helpers, with the addition of assigning each one an ID and an inline style to hide the one opposing the required default state:

    <%= image_tag("signUpItemActive.gif", :size => "13x18",
        :alt => "Active", :id => "checkActive") %>
    <%= image_tag("signUpItemInActive.gif", :size => "13x18",
        :alt => "Inactive", :id => "checkInactive",
        :style => "display:none;") %>

These are then both wrapped in a single anchor tag, which is given an onclick handler to a JavaScript function.

    <a href="#" onclick="toggleCheckBox(); return false;">
         <%= image_tag("signUpItemActive.gif", :size => "13x18",
            :alt => "Active", :id => "checkActive") %>
         <%= image_tag("signUpItemInActive.gif", :size => "13x18",
            :alt => "Inactive", :id => "checkInactive",
            :style => "display:none;") %>
    </a>

The next step is to modify our standard Rails form to assign the check-box an ID, and hide it with some more inline CSS styling. This means it won’t be visible, but will continue to send its value when the form is submitted:

    <%= f.check_box :someBool, :id => "hiddenCheckBox", :style => "display:none;" %>

The JavaScript function can then be defined in Application.js (this could of course be modified to take the IDs as parameters):

    function toggleCheckBox()
    {
        elementActive = document.getElementById('checkActive');
        elementInactive = document.getElementById('checkInactive');
        elementHidden = document.getElementById('hiddenCheckBox');
 
        if (elementActive && elementInactive && elementHidden)
        {
            var state = (elementActive.style.display == "none");
            elementHidden.checked = state;
            elementActive.style.display = state ? "inline" : "none";
            elementInactive.style.display = state ? "inline" : "none";
        }
    }

There we go! Clicking the dummy check-box graphic will toggle the images and set the value in the hidden check-box at the same time. There is only one remaining step and that is to set the default state of the images to match the existing value of the boolean field. Without this the graphics and the form are likely to get out of sync. Even if the form is for creating a new record, the page will be shown again in the event of a validation error.

Another JavaScript function can take care of this:

  function setCheckBox()
    {
        elementActive = document.getElementById('checkActive');
        elementInactive = document.getElementById('checkInactive');
        elementHidden = document.getElementById('hiddenCheckBox');
 
        if (elementActive && elementInactive && elementHidden)
        {
            var state = elementHidden.checked;
            elementActive.style.display = state ? "inline" : "none";
            elementInactive.style.display = state ? "inline" : "none";
        }
    }

Then call this from the page’s body onLoad event:

    <body onload="setCheckBox();">

Dinner

February 2nd, 2008, General, 5 Comments

Today was my first day off for three weeks. After being holed up in an office (complete with its recent scaffolding sarcophagus) for so long I decided to spend the day out in the open and took a long stroll around Ydre Nørrebro. Despite the recent bitter coldness, the sun was shining through the clouds more than it has done for a long time. My programming-numbed-senses were in overdrive over the simplest things and everything was so heightened. It was great!

One of the places I stumbled upon again was Balders Plads. It is a lovely, small residential square with architecturally grand buildings all varying in style from each other. However because of its location inbetween the far end of Nørrebrogade, Tagensvej, a few squats (+Bumzens Café) and the edge of Nordvest, it has much more of a Kreuzberg feel than similar looking places in København. There were a few apartments for sale on the square. I’d like to live there.

My friend Andreas is staying over with me this weekend. He’s currently living in Stockholm, but is attending an independent gaming workshop in København, where it seems the plan is to stay up all hours and write a game in three days. He arrived at my house at 2am this morning after the busy first day and left again at 8am. I’m not sure when he’ll be back but I cooked my first meal for a while this dinnertime, so I’ll leave some in the fridge for him. Although I expect he will have food provided, so maybe it will be my lunch tomorrow.

dinner.jpg

Multiple Rails applications

January 30th, 2008, Programming, Ruby on Rails, 6 Comments

We are midway through a large project at the moment. It’s our biggest Ruby on Rails project for a client to date and consists of a front end and an administration area based on our DATA CARTON technology. Early on we faced several organisational conflicts between these two opposing forces.

Our DATA CARTON framework was adverse to settling in directly with its public facing companion, our models (while obviously the same) were actually required to be configured in subtly different ways, and with multiple developers and designers working together, we decided to split them into two applications both pointing at the same database.

While these logical units promised simpler security, cleaner directory structures and more streamlined development, we hadn’t tried this before but decided to just forge ahead anyway. These are the problems we encountered and how we solved them:

1. Logins

Our front end is community-based and all users of the system from newsletter subscribers to administrators share a users table. The first thing we did after pointing our database.yml file at the same database was to try logging in to both applications with the test user we had created. After only a 50% success rate, we traced the problem to our password encryption method that uses a mixture of the user’s password choice, a salt and an application specific key string. Different keys are going to result in different hashes and incompatible authentication routines in the applications. A quick switch to using identical strings and we were successfully creating users and logging-in in all possible combinations.

    def self.encrypt(pass, salt)
        finalString = pass + 'somekey' + salt
        Digest::SHA1.hexdigest(finalString)
    end

2. Sessions

Our next thought was ‘sharing sessions would be nice’. Linking administrators directly to the backend from their frontend toolbar without having to login again, passing secret messages back and forth, that sort of thing. Rails offers cookie-only sessions or database based ones. Using the more data-sensitive one is a simple matter of uncommenting these lines from the application’s environment.rb:

    config.action_controller.session_store = :active_record_store

Then in the same file (environment.rb) you’ll find your session security key and secret:

    config.action_controller.session = {
        :session_key => 'some_secret_key',
        :secret      => 'some_secret_hash'
    }

Rails generates both of these automatically when creating your application. They are sent with every non-GET request (i.e. PUT, POST, DELETE) to verify your session and protect against cross-site forgery (there’s actually a few fiddly issues with getting in-place edits working while using this method, but I’ll save that for another post).

The important thing here is to again make sure all keys and secrets are consistent across both applications. So pick one and copy it across. Once you’ve synchronised your environment.rb session settings, you’ll need to uncomment and duplicate your session secret from the top of controllers\application.rb too. Now you’re sharing sessions!

	protect_from_forgery :secret => 'some_secret_hash'

3. Subdomains

We quickly realised that our session sharing was not going to be as smooth as first anticipated, as we typically run our client’s backends on an admin subdomain (i.e. http://admin.abcdefg.com) and as cookies don’t take kindly to being requested by subdomains that haven’t sent them, we still didn’t have our single login functionality.

After much brainstorming and hunting around, we eventually found this genius configuration option that (notice the all important ‘.’ prefix) makes the cookie available to all subdomains on a domain. Finally we had truly shared sessions.

    ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.
        update( :session_domain => '.abcdefg.com')

4. Migrations / Models / Helpers / Deployment

The remaining issues are ones we are still facing and gradually solving. These tend to be less of a technical matter and more of an organisational one. We’re quickly establishing rules for how we order the migration files, share some models while keeping the security sensitive ones separate, bundling all of our helpers up into libraries and unifying deployment. We’re not quite there yet, but I’ll be sure to share our assumptions and solutions soon.

Setting yourself free

January 26th, 2008, Discussion, General, 1 Comment

“Being your own boss” is often touted as a direct route to personal freedom, a liberation of time management and the ability to just take back your life NOW! This is of course rarely true. The reality is extended hours and a constant pressure to succeed. While removing everyone more senior than you from your work life has the wonderful effect of also removing any negativity and frustration (if things aren’t working it’s no one’s fault but yours, if you can think of a better way to do things you can just do it), it also leaves you constantly dealing with a raw reality that a more structured hierarchy would help protect you from.

These days we are usually quite well time managed at Spoiled Milk, but due to several very large projects reaching a simultaneous climax at the end of this month, some of us are currently being forced to work very extended days. Curiously, despite the pressure and stress, the quip of “I’m working 14 hours a day for myself so I don’t have to work 7 for someone else” does hold some ground, although it’s quite often hard to pinpoint exactly why.

-

Ruby on Rails is a programming language and Web application framework that I’ve only dabbled with in the past, but my intensive work pattern recently has doubled up as in intensive training course. I’m tempted to start a series of coding related posts to share the solutions to some of the trickier hurdles I’ve come across.

Would anyone mind? Is this a good idea? I’ll tag them with something appropriate so they can be filtered out, and I’ll try to keep up the amusing stories of Danish police-patrolled cycles lanes.

Change

January 15th, 2008, Discussion, General, 1 Comment

I’ve just been for a swim at a pool I haven’t visited for quite a while. As I walked through the doors I was suddenly struck by the feeling of being in a foreign country. I don’t consciously experience this a lot while in Copenhagen these days, but for a while I was back in an alien society and everything seemed slightly quirky and off kilter: the lighting, the ticket clerk, the supremely relaxed attitudes about nudity while changing, the uptight staff-monitored showering before swimming and the packed pool at 8pm on a winter’s evening.

As I swam lengths I began contrasting my life now with how it was a few years back and what I’ve done inbetween. For about fifteen minutes I could see everything with an old pair of eyes and I was quite dumbfounded at the paths I’d taken and what I’d achieved. This started me thinking about how it was all possible and eventually came back to my much touted belief in the destructiveness of routines and safety.

In the same same way that one rarely takes a random left turn during a monotonous daily commute, it’s near impossible to make radical changes to your life when burdened with expectations and status. I tried to track how I’d managed to build up my own company here in Denmark and what would have been different in the UK. I believe the primary reason was my ability to live in a tiny room on a pittance with minimal possessions for so long. This allowed me the freedom to work hard and learn hard without having to worry about income too much. It actually wasn’t that difficult to do and even now that we are a team of five all earning enough to live, I still don’t feel the need to “raise my stakes” too much.

This prolonged low-risk battle (also shared to some degree by my cohorts) is why I think the company survived the dark days long enough to eventually attain the relative success it has, but it doesn’t answer how I managed to do it. I was previously on a reasonable wage living in a nice, well-furnished apartment and although my life was far from lavish (student debts were enough to neutralise a lot of my earnings), I arguably lived in a much more comfortable style with more freedom to do what I want.

Most of this sneaked up on me over the years and by the time I realised I was actually desperately unhappy with it all, it was almost too late. I had reached an unavoidable expectation level both from myself and of others. You can change a routine and broaden outlooks by moving to a new town, but you still can’t escape YOU; your culture, your society, your career path, your achievements and your failures.

There were lots of parts of me I didn’t want to escape from, but whatever I thought about doing next was fronted with impossibilities and obvious, logical reasons why I would fail. Selling all my things, quitting my job and moving to a different house around the corner seemed both attention seeking and destructive. I reached a point of panic and wanted out of everything. With hindsight this is what fuelled my move to Denmark. Once I arrived I felt free from many aspects of my old lifestyle, but more importantly I felt free from cultural expectations.

No matter how much you believe you can shun the typical trappings of a society, they are always with you: how to queue, how to greet people, how to address a cashier in the bank, where to look when sat opposite someone on public transport, what to wear, when to go to bed. These things are so small, yet so plentiful that in many ways they place unseen chains around every action you take. As time went on I became increasingly aware of the release my move abroad had created and, coupled with literally not knowing what was possible, I decided to try out a lot of things. Everything is a breeze when being from a different culture can be used as an internal excuse and force of reasoning. You can be an outsider and still accepted in a way that transcends social norms, solely because you’re not expected to fit in(*). It becomes a positive and inclusive experience rather than an exclusive and lonely role.

After 2 and a half years, a lot of these feelings are gone from my every day experiences, but I generally feel that they have become integrated into who I am rather than lost by the wayside.

However as I left the building I realised that actually I’d instinctively bought my ticket in Danish, showered and scrubbed all required areas, swum in the regimented lane systems and then paraded around the locker area without a towel to be seen. I even popped a couple of lakrids sweets in my pic’n'mix on the way home. I guess I’ve just accepted a whole new set of norms.

(*) Of course I realise that the pairing of a British person and Denmark’s society is generally quite fortunate in this respect and that many cultural migrations are tarred with enough prejudice to make my writing seem awkward and naive. Sorry.

DJ superteam to play Kalaset

January 1st, 2008, Events, Leave a comment

Normally DJ superteams consist of talented people working together to make music intended to enhance nights out of the house with intriguing rhythms, samples and beeps. Birds of Paradise are a little different because they play other people’s music and some of it is sad. However, they do try to play it in a nice order and include songs to clap along to.

Lucy and Russell’s first joint performance will be this Friday, the 4th of January, from 22:00 to 02:00 at Kalaset.

Kalaset [info (in Danish)]
Vendersgade 16, 1363 København K [map]

Birds of Paradise

The Botanists (day two)

December 16th, 2007, Good things, The Botanists, Leave a comment

On day two we discovered some more instruments in the potting shed and decided to give the vocals a rest while we try to perfect the music. We’ll be gargling eucalyptus tea throughout the festive season. God Jul.

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

The Botanists (day two)