The ultimate work place.

http://www.team5150.com/~andrew/carmack/johnc_plan_1998.html#d19980204
"The research getaway went well. In the space of a week, I only left my hotel to buy diet coke. It seems to have spoiled me a bit,"

http://steve.yegge.googlepages.com/innovation-101
"I've often idly wondered what the ideal innovation environment is. I know it's not at home -- staying up all night just to get some free time for innovation doesn't scale well when you have a family and a day job. Home has its share of distractions. And I know it's not in the office, at least not the space we're in today.

Every time I let my thoughts wander on this subject, the same vision comes to mind. I'm sitting in a comfortable armchair, in a large room or atrium that's lit primarily by daylight coming through large windows. There are nice green plants everywhere, including a large fern-ish looking tree (apologies; botany has never been my strong subject) next to me. There are people coming and going nearby, but their noise is white noise, and it's not terribly distracting. I've been in this place a hundred times, in a hundred different locations.

It's a hotel lobby."

Steves vision resonated extremely well with me. I've seen about the same vision since I was a kid. Mine was more like a big white snowed in house ontop of a mountain with large windows looking out over lovely scenery, perhaps in Canada or Norway, maybe even Sweden ;) There I could watch people in the valley while doing my programming and research...

How to connect to Spotify through a SSH tunnel 2

This time a bit simpler with Tunnelier and WinSSHD instead of freeSSHd/Putty:

Things you will need:
1) Computer behind some sort of obstructive proxy where you want to use Spotify (named "school computer" from now on).
2) Computer "in the open" (named "home computer" from now on) with a stable internet connection where you can install your own software and manage the firewall/router freely. You will need the following software:
3)
WinSSHD and
4)
RabbIT Proxy (RabbIT4-bin)
5)
Java 6 Runtime (This page will install a runtime in Programs/Java/jre6)
6) Not needed but can make debugging very easy: A free
logmein account. Install it on the home computer. This will with high certainty able you to remote control your home computer from the school computers browser (if you're allowed to install the needed plugin).
7)
Tunnelier. Putty is an alternative but is harder to configure/understand YMMV/IMHO.

You will now install WinSSHD and RabbIT proxy on your open home computer. This will setup a SSH-server that listens on port 21 and a web proxy on your home computer that listens for HTTP-requests on port 9667. You will then be able to connect to your home computer from school with Tunnelier and establish a secure SSH tunnel between your school computer and your home computer.

Step by step:

1) Install WinSSHD on the home computer.
2) Open port 22 in your router/windows firewall. Tip: Only open port 22 for the ip-range your school uses.
3) Try connect from school with Tunnelier or Putty on your home computer router ip adress and port 22. If you don't know your home computer ip adress: When youre at home Google for "What is my ip" and visit the first page. It will tell you the adress.

When you can get a SSH connection to your home computer from the school computer it's time to move on with installing the web proxy on your home computer:

1) Download RabbIT4 to your home computer and unpack it in for example Programs/RabbIT
2) Create a new file called startproxy.bat and add the following line to it (your paths may vary):
C:\Program\Java\jre6\bin\java -jar jars/rabbit4.jar -f conf/nocache.conf
3) Click startproxy.bat and the web proxy is started.

At school:

1) Install Tunnelier/Putty on your school computer and add a new configuration with your home computer ip and the port you have found out to be open, in my case port 22.
2) Add a tunnel configuration. In Tunnelier you flip to the C2S Fwding tab and click "Add"
3) Status=enabled, Listen Interface=127.0.0.1, List. Port=9667, Destination Host=127.0.0.1, Dest. Port=9667, Comment=My home proxy
4) Flip back to the Login tab and enter the username and password of your homecomputer (most often "Administrator" or the name you selected when installing windows).
5) Click "Login"
6) Accept the key and a commander-like ftp-window will open. You're now inside your home computer and you can close the ftp-window. The tunnel is established.

Start Spotify and try to login. When the login fails you will be able to insert a proxy. Select a HTTPS proxy and insert 127.0.0.1 and port 9667. Leave user/password blank.

Login to Spotify again.

Magic.

(For those of you that managed to get logmein to work you will understand that you actually can do all of this configuration in a browser on your school computer.. You can also use the same tunnel for use with the web browser..)

A javax sound engine that reuses unactive Clip objects

The API for handling sounds in Java 1.6 (javax.sound.sampled.*) is a bit cumberstone to work with. You can't just load a sample and start it and think the underlying mixer/dataline etc will do their best to play the sample. If you do you will probably hear clicks and sometimes the .start() method of the Clip will not start the sample at all, despite you flush it and reset the frame position.

So. You will need a sound engine of some sorts that are able to reuse Clips as they are not used anymore (when the LineEvent.Type.STOP is recieved for the Clip). I have made one that looks like below. To make a resuable Spring component I guess you would like to make a constructor with resource path to the sample used in the private method createNewClip:

import javax.sound.sampled.*;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Queue;

public class SoundEngine
{
  HashMap<String, ArrayDeque<Clip>> clipQueues = new HashMap<String, ArrayDeque<Clip>>();

  public void play(final String soundName)
  {
    final Clip unactiveClip = getUnactiveClip(soundName);
    unactiveClip.flush();
    unactiveClip.setFramePosition(0);
    unactiveClip.start();
  }

  private Clip getUnactiveClip(final String soundName)
  {
    final Queue clipQueue = clipQueues.get(soundName);
    if (clipQueue == null) {
      clipQueues.put(soundName, new ArrayDeque<Clip>());
      addNewClipToQueue(soundName);
    } else if (clipQueue.isEmpty()) {
      addNewClipToQueue(soundName);
    }
    return clipQueues.get(soundName).pop();
  }

  private void addOldClipBackToQueue(final String soundName, final Clip unactiveClip)
  {
    final Queue clipQueue = clipQueues.get(soundName);
    if (clipQueue == null) {
      clipQueues.put(soundName, new ArrayDeque<Clip>());
    }
    final Queue<Clip> queue = clipQueues.get(soundName);
    queue.add(unactiveClip);
  }

  private void addNewClipToQueue(final String soundName)
  {
    final Queue<Clip> newQueue = clipQueues.get(soundName);
    final Clip newUnactiveClip = createNewClip(soundName);
    newQueue.add(newUnactiveClip);
  }

  private Clip createNewClip(final String soundName)
  {
    final URL sound1Url = getClass().getResource("../" + soundName);
    final Clip audioClip;
    try {
      final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(sound1Url);
      audioClip = AudioSystem.getClip();
      audioClip.open(audioInputStream);
      audioClip.addLineListener(new LineListener()
      {
        public void update(final LineEvent event)
        {
          if (event.getType() == LineEvent.Type.STOP) {
            addOldClipBackToQueue(soundName, audioClip);
          }
        }
      });
      return audioClip;
    } catch (UnsupportedAudioFileException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (LineUnavailableException e) {
      e.printStackTrace();
    }
    return null;
  }
}

Mobile flickr explore that actually works

When I have time over I like to browse flickr explore to see all new awesome photos people upload. I also like to do that with my phone on flickrs mobile version that can be found here: http://m.flickr.com/explore/?

The problem is that the mobile version doesn't show todays explored pictures, or at least doesn't conform to the normal explore page. There is also a bug when you select "next page" you see the same page over and over again. At least in my mobile phone.

So instead of complaining I made a small jsp page using the flickrj API that works exactly as I want it to work in my phone:

http://www.defblog.se/explore/

Tada!

EDIT 2009-06-04: Changed the URL so it's easier to remember.