Make apps4halifax – Intro

Halifax Regional Municipality is introducing ‘apps4halifax‘, its first-ever Open Data App Contest. Similar initiatives have been successful in Ottawa, Edmonton and many other cities worldwide.

Residents can submit ideas or code apps using the HRM Open Data catalog. The best submissions may win cash prizes and awards.

The Open Data catalog is implemented using the Socrata Open Data Portal. The SODA 2.0 restful web service API allows developers to query and consume live data from the public data-sets.

The Socrata developer documentation explains how to use queries to endpoints, supported datatypes and response formats.

The currently available data-sets include Crime occurrences, Building types, Buildings, Bus Routes, Bus Stops, Bylaw Areas, Civic Addresses, Community Boundaries, Park Recreation Features, Parks, Polling Districts, Streets, Trails, Transit Times, Waste collections and Zoning Boundaries.

You can construct web service query URLs like this:

You can determine the RESOURCE-ID for a dataset like this:

  1. Go to https://www.halifaxopendata.ca/
  2. Click on a dataset name
  3. Click the “Export” button
  4. Under “Download As”, copy one of the links, e.g. JSON
  5. The resource id is the part of the URL between “views/” and “/rows.json”

As an extremely useful example, you could query fun things like all HRM garbage collections occurring on Wednesdays:

http://www.halifaxopendata.ca/resource/ga7p-4mik.json?collect=’WEDNESDAY’

As a simple and quick way to create web pages that interact with these web services you could use JQuery and its getJSON() function.

I will probably follow up with more posts on this topic soon.

Reflexionen der Moderne im dramatischen Werk Ernst Tollers

About 12 years ago, in July 2001, I submitted my thesis “Zwischen Weltverbesserung und Isolation – Reflexionen der Moderne im dramatischen Werk Ernst Tollers” to complete my university degree in Mathematics and German Linguistics and Literature.

I wrote the document using Latex and GNU Emacs on a GNU/Linux system. It is available in PDF format.

The LaTex source files of the thesis are also available. The structure is very straightforward and uses predefined macro definitions that can be generally useful for writing essays, books and academic papers in the Liberal Arts.

For those who are fed up with their word processor messing with their layouts and prefer to just write plain text: Take a look at how simple, for example my introduction chapter is.

If you are interested, feel free to reuse my LaTeX macros in STYLE.tex.

The LaTeX code is compatible with TeX Live, version 2012. On Debian stable (wheezy) installation is as simple as

sudo apt-get install texlive texlive-latex-extra texlive-lang-german evince
wget https://github.com/odoepner/toller-moderne/archive/master.zip
unzip master.zip
cd toller-moderne-master/src/main/tex
pdflatex MAIN.tex
evince MAIN.pdf

Play MP3 or OGG using javax.sound.sampled, mp3spi, vorbisspi

I tried to come up with the simplest possible way of writing a Java class that can play mp3 and ogg files, using standard Java Sound APIs, with purely Open Source libraries from the public Maven Central repositories.

The LGPL-licensed mp3spi and vorbisspi libraries from javazoom.net satisfy these requirements and worked for me right away. As service provider implementations (SPI), they transparently add support for the mp3 and ogg audio formats to javax.sound.sampled, simply by being in the classpath.

For my AudioFilePlayer class below I basically took the example code from javazoom and simplified it as much as possible. Please note that it requires Java 7 as it uses try-with-resources.

Maven dependencies

  <!-- 
    We have to explicitly instruct Maven to use tritonus-share 0.3.7-2 
    and NOT 0.3.7-1, otherwise vorbisspi won't work.
   -->
<dependency>
  <groupId>com.googlecode.soundlibs</groupId>
  <artifactId>tritonus-share</artifactId>
  <version>0.3.7-2</version>
</dependency>
<dependency>
  <groupId>com.googlecode.soundlibs</groupId>
  <artifactId>mp3spi</artifactId>
  <version>1.9.5-1</version>
</dependency>
<dependency>
  <groupId>com.googlecode.soundlibs</groupId>
  <artifactId>vorbisspi</artifactId>
  <version>1.0.3-1</version>
</dependency>

AudioFilePlayer.java

package net.doepner.audio;

import java.io.File;
import java.io.IOException;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine.Info;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;

import static javax.sound.sampled.AudioSystem.getAudioInputStream;
import static javax.sound.sampled.AudioFormat.Encoding.PCM_SIGNED;

public class AudioFilePlayer {

    public static void main(String[] args) {
        final AudioFilePlayer player = new AudioFilePlayer ();
        player.play("something.mp3");
        player.play("something.ogg");
    }

    public void play(String filePath) {
        final File file = new File(filePath);

        try (final AudioInputStream in = getAudioInputStream(file)) {
            
            final AudioFormat outFormat = getOutFormat(in.getFormat());
            final Info info = new Info(SourceDataLine.class, outFormat);

            try (final SourceDataLine line =
                     (SourceDataLine) AudioSystem.getLine(info)) {

                if (line != null) {
                    line.open(outFormat);
                    line.start();
                    stream(getAudioInputStream(outFormat, in), line);
                    line.drain();
                    line.stop();
                }
            }

        } catch (UnsupportedAudioFileException 
               | LineUnavailableException 
               | IOException e) {
            throw new IllegalStateException(e);
        }
    }

    private AudioFormat getOutFormat(AudioFormat inFormat) {
        final int ch = inFormat.getChannels();
        final float rate = inFormat.getSampleRate();
        return new AudioFormat(PCM_SIGNED, rate, 16, ch, ch * 2, rate, false);
    }

    private void stream(AudioInputStream in, SourceDataLine line) 
        throws IOException {
        final byte[] buffer = new byte[65536];
        for (int n = 0; n != -1; n = in.read(buffer, 0, buffer.length)) {
            line.write(buffer, 0, n);
        }
    }
}

Direct Google image search URLs

Problem: This URL does not actually execute an image search:
http://images.google.com/?q=oliver+doepner

For direct links to a Google image search, I have successfully used this URL pattern:
http://google.com/search?tbm=isch&q=oliver+doepner

The “+” sign is just a URL encoded space character.

X with Eddie Vedder at Oracle Party

Part of the JavaOne conference this week was a huge party by Oracle on Treasure Island, San Francisco. It featured a live concert (photos) from around 8pm to 1am with Kings of Leon, Pearl Jam and a band that was apparently big in the US indie scene in the 80s called “X”.

I enjoyed Kings of Leon – who had the unenviable task of warming up a crowd of thousand of mostly male IT dudes, then a great Pearl Jam gig and stayed to see and dance to X, until in the end Pearl Jam’s Eddie Vedder reappeared and joined X on stage …

Doing HTML5

It’s refreshing to take a Dive Into HTML5.

Reading the HTML5 spec is even more fun. It’s only 600+ pages after all … :)

My personal “IT résumé” website at odoepner.github.io has recently become HTML5 compliant (using W3C validator). It was mostly a matter of changing the doctype and cleaning up the existing XHTML somewhat.

While I was at it, I also added in some CSS3 to make it look a little nicer. The result is tested on most browsers.

World calendar

Facts due to movements of earth and moon:

  • 1 solar year = about 365.25 days
  • 1 lunar month = about 29.5 days

The leap year rules from the Gregorian calendar are good because they keep the calendar year well aligned with the solar year.

But the weird lengths of the months and shifting week day of January 1st are drawbacks in many respects.

It would be so much nicer to have a perennial calendar so that every year begins on the same week day and the week day of any given day in a month is predictable.

For these and many other reasons, I like the proposed World Calendar.

Consider vending misers to save energy at work …

A power meter is now installed in the upstairs lunch room in Halifax at the company that I currently work for. It measures the power consumption of both vending machines at the same time (using a power bar).

vending-machines-metered

The meter shows both the current consumption in Watts (W) and the accumulated energy use in kilo Watt hours (kWh). I installed it yesterday at 2:45pm and will let it run for 1 week (to get good data).

green-team-metering-in-progress

After that we will do some cost/benefit analysis regarding the potential installation of vending misers.

If you are in our Halifax office you can go and see for yourself how the consumption kind of alternates between roughly 150W (between refrigeration) and roughly 800W (during active refrigeration).

If you want to do something similar with other electric appliances, e.g. at your homes, you can buy those power meters devices at Canadian Tire or similar stores. This is the one that I am currently using.

Tested old-o.github.io on all major browsers

I just tested my personal “résumé” – British folks would say “CV” – website at old-o.github.io successfully on IE8, IE9, Firefox 3.6 to 9, latest and older Chrome versions, Opera 10 and 11 and Safari 4 and 5.1. It works on all browsers and looks fine.

You might wonder if I have all these browser installed? No, I don’t. I used the amazing browserling.com service that runs all the various browsers in virtual machines “in the cloud”, and embeds the UI in their website. Cool stuff and currently free for everyone to use!

One caveat with browserling.com is a tool called IETester that they use to emulate the ancient IE5.5 and IE6 browsers. Its seems to have bugs related to PNG graphics which prevented reliable testing. So if anyone out there still uses IE5.5 or IE6: Please visit old-o.github.io and let me know if you can see the photo of me on the page with the transparency effect.

On the newer CSS3 capable browsers, my site now sports drop shadows and rounded corners, using border-radius and box-shadow.

I also tested W3C standards compliance (HTML5, CSS3) and all my pages did pass those tests as well, except for some stuff caused by bugs in the CSS3 validator at w3.org. What a nice way to end the computer oriented part of the day …