Hi, I'm Benedikt Deicke. I'm a web and software developer at flinc. I'm mainly building user focused web applications using Ruby on Rails and JavaScript. Additionally I'm currently finishing my studies for my master's degree and enjoying photography in my spare time. Feel free to get in touch with me!

November 1st, 2010
I'm joining flinc as a Rails developer

Today’s my first day as a full-time employee at flinc where I’ll mainly be doing Ruby on Rails development. I got in contact with Michael a few months back when he joined the Web Development Fulda group on Xing. We met at the meetup in september and a few days later he invited me to their offices in Dieburg. I was impressed by their product and the spirit of the team, so I agreed on doing trial work for a week. Obviously they liked me and my work and offered me a job.

About flinc

“flinc arranges spontaneous rideshares in realtime. Directly on your navigation system in your car.”

The idea of flinc is to connect smartphones with satellite navigation systems to arrange rideshares in realtime. For riders this results in an alternative to an own car, for drivers it’s an easy way to reduce their costs.

flinc is currently tested in the city of Friedrichshafen and is planned to be rolled out in several innovation regions in 2011. Head over to flinc.org to register and get more information.

Pair with me!

As I’m the third developer at flinc, we’re looking for another Ruby on Rails developer to join the team. If you’re interested in pair programming with me (or of course one of the other developers) while working on an exciting product, send a mail to Michael.

Posted by benediktFiled in Agile Development, Javascript, Other, Ruby, Ruby on Rails

June 24th, 2010
Multitouch Inspector for iPad

During the last couple weeks I’ve been playing around with the iPad and Mobile Safari. I built a little tool to familiarize myself with the Multitouch JavaScript API provided by Mobile Safari as well as web applications for the iPad in general. I named the result Multitouch Inspector because that’s what it does: Inspect the TouchEvents fired by the JavaScript API. ;-) Today I decided to rewrite the tool to drop the dependency on Prototype.js and I published it on GitHub.

Using Multitouch Events from JavaScript

There are four events that are related to touch: TouchStart, TouchMove, TouchEnd and TouchCancel. I’m not sure about what situation would trigger TouchCancel so I decided to skip it for now. Working with the touch events is straight forward:

   1  document.addEventListener('touchstart', function(event) {
   2    /* Do whatever you'd like to do with the event */
   3  }, false);

Of course you can add the listener to any element just like you would with Click or MouseOver events. The function gets passed an object of type TouchEvent. There are several properties on this object, but the most interesting ones are touches, changedTouches and targetTouches. They all are of type TouchList and contain several Touch objects. The touches property lists all touches currently on the screen. The changedTouches list contains the touches that changed and caused the event to fire. The touches in the targetTouches list are those that are currently within the target element.

Every Touch has an identifier property as well as pageX and pageY properties. As you might have guessed already, the pageX and pageY properties include the touch’s position on the screen. The identifier property provides an unique integer for this touch. It stays the the same for this touch as long it is on the screen. This is particularly useful as removing one finger will trigger a TouchEnd event that implies that all fingers were removed, immediately followed by a TouchStart event including the remaining fingers. Luckily the identifier property stays the same for those fingers that weren’t removed from the screen.

Offline Application Caching

In order to use the application without having an active internet connection or simply while the development server isn’t running I’m using HTML5 Offline Application Caching. It works by defining a manifest file and referencing it in the html-tag:

   1  <!DOCTYPE html>
   2  <html manifest="application.manifest">

The manifest file itself looks like this and defines what files are required to view the application while offline:

   1  CACHE MANIFEST
   2  
   3  # c94640e9114e05f16e189605e5b65ba2357117712c949cae92cc29bc1bbd3c47
   4  /images/background.png
   5  /images/icon.png
   6  /index.html
   7  /javascripts/application.js
   8  /stylesheets/application.css

You might wonder about the random string at the top. As the browser will reload everything when it can’t find one file in it’s cache, I’m using this string to force a reload during development. I built a small Sinatra app (see the listing below this paragraph) that generates the manifest and resets this string for every request. As a result, the browser reloads everything while online but falls back to the cached files when offline.

   1  require 'sinatra'
   2  require 'digest/sha2'
   3  require 'pathname'
   4  
   5  # ...
   6  
   7  get '/application.manifest' do
   8    content_type 'text/cache-manifest'
   9  
  10    manifest = "CACHE MANIFEST\n\n"
  11    manifest << "# " << Digest::SHA2.hexdigest(Time.now.to_s + Time.now.usec.to_s) << "\n"
  12  
  13    root = Pathname.new(settings.public)
  14    Pathname.glob(File.join(root, "**", "*")).each do |p|
  15      manifest << "/" << p.relative_path_from(root) << "\n" if p.file?
  16    end
  17  
  18    manifest
  19  end

Issues

There are some issues that I couldn’t resolve while building the application. The startup image will only work while in portrait orientation and its dimension has to be exactly 1004×768. Currently there isn’t a way to define a startup image for horizontal orientation.

While the tracking of the touches works on the iPhone (with iOS 4.0) as well for some reason it isn’t possible to press the buttons in the toolbar. At the moment I have no explanation for this rather strange behavior, but I might take another look at it in the future.

Screenshot & Demo

Now that you have some insights on the internals of the application, here’s a screenshot as well as a link on it to a demo:

Fork it on GitHub

I published the source code on GitHub. Feel free to fork it!

Further reading

  1. Safari Web Content Guide: Handling Events
  2. Making an iPad HTML5 App & making it really fast
Posted by benediktFiled in Articles, Javascript

August 25th, 2009
RSpec and Rails Helpers using the output buffer

When testing helper methods that use rails’ output buffer (for example by calling concat) with RSpec, be sure to add this to your specs:

   1  before(:each) do 
   2    helper.output_buffer = ""
   3  end

Took me a while to figure this one out. Apparently RSpec doesn’t initialize the output buffer and you end up with a NoMethodError on nil.

Posted by benediktFiled in Ruby on Rails

March 19th, 2009
Commander: command-line executables in Ruby

I’m currently building a tool to help managing severals servers simultaneously for Softvision Media. As I decided to write the tool in Ruby, I’ve been looking for a framework to create command-line executables. On GitHub I stumbled over commander by TJ Holowaychuk of VisionMedia that provides a simple DSL for this task. It integrates with OptionParser and the Highline gem for user interaction. It automatically creates common options such as “—help” and “—version”, as well as detailed descriptions about possible commands.

A simple executable could be something like this (taken from commander’s readme):

   1  require 'rubygems'
   2  require 'commander'
   3  
   4  program :name, 'Foo Bar'
   5  program :version, '1.0.0'
   6  program :description, 'Stupid command that prints foo or bar.'
   7  
   8  command :foo do |c|
   9    c.syntax = 'foobar foo'
  10    c.description = 'Displays foo'
  11    c.when_called do |args, options|
  12      say 'foo'
  13    end
  14  end
  15  
  16  command :bar do |c|
  17    c.syntax = 'foobar bar [options]'
  18    c.description = 'Display bar with optional prefix and suffix'
  19    c.option '--prefix STRING', String, 'Adds a prefix to bar'
  20    c.option '--suffix STRING', String, 'Adds a suffix to bar'
  21    c.when_called do |args, options|
  22      options.default :prefix => '(', :suffix => ')'
  23      say "#{options.prefix}bar#{options.suffix}"
  24    end
  25  end

There are still some rough edges, but in general it works pretty well.

Posted by benediktFiled in Ruby

August 8th, 2008
HowTo: Phusion Passenger aka mod_rails for Apache

Yesterday I decided to give Phusion Passenger aka mod_rails a try and installed it. It was dead simple to set it up and to deploy rails applications with it. I’m now using it for several “small” applications, for which the whole overhead of setting up a cluster of mongrels and a proxy doesn’t seem to be adequate. I’ll give you a short summary on how to install mod_rails for apache2 on Debian Etch.

First, install the passenger gem using RubyGems (if you don’t have Ruby and RubyGems running on your server, install them first – of course):

   1  gem install passenger

Afterwards, run the passenger apache2 module installer using this command:

   1  passenger-install-apache2-module

It’ll check for the required software to install the module, compile it and copy it to the correct folders. If some software is missing install it using aptitude (ie. aptitude install g++ if you’re missing the GNU C++ Compiler).

Next, create two new files in the /etc/apache2/mods-available directory. One called mod_rails.load:

   1  LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.2/ext/apache2/mod_passenger.so

... and the other one called mod_rails.conf:

   1  PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.2
   2  PassengerRuby /usr/bin/ruby1.8

Now you can enable the module using a2enmod and restart apache.

   1  a2enmod mod_rails
   2  apache2ctl restart

That’s it! Now simply deploy your rails application, just make sure apache’s document root is pointing to your applications public folder. Passenger will automatically detect your rails application and start up processes as needed. You can check it’s status and stats using the passenger-status and passenger-memory-stats commands. For more details on mod_rails, take a look at it’s documentation.

Posted by benediktFiled in Articles, Linux, Ruby, Ruby on Rails