Mr Speaker

mrspeaker's head in a monitor You find yourself at the entrance to the Hompage of Mr Speaker. In a darkened corner sits a trunk containing HTML5 games and some JavaScript tidbits. Next to it you spy a ■■■■■■■ account. Exits are North, East, and .

Functions as RxJS Subjects

Here's a nifty trick if you're using RxJS, and want to subscribe to plain ol' function invocation. This is especially useful if you want to use React, and don't want to bind with Rx.Observable.fromEvent with standard DOM event listeners.

import Rx from 'rx';

const RxFuncSubject = () => {
  const subject = Object.assign(
    (...args) => subject.onNext(...args),

  return subject;

export default RxFuncSubject;

We create a regular function that we extend with both Rx.Observable and Rx.Subject (you need to mix in Rx.Observable as this is extended by Rx.Subject internally).

The function passes its arguments along to the internal onNext function: so it can be called as a regular function but still act like a Subject:

const clicker = RxFuncSubject();
clicker.subscribe(() => console.log('clicked!'));
clicker(); // clicked!

Now it can be used in a normal React component, wherever a function call would be expected!

<MyComponent onClick={clicker} />

Five short years

On Friday, October 22, 2010 I conducted a scientific experiment: if one URL shortener can make a URL shorter, then fifteen URL shorteners can make it reaaaally short. The results were quite as you'd expect: the resulting link was longer than source, and browsers would go into convolutions trying to resolve the chain of shortened shorteners.

2010 was a big year for people who thought it would be a good idea to make smaller URLs. All it took was a rudimentary knowledge of a hash map and an hour of coding and suddenly you had a viable startup on your hands. There are a lot of URLs out there, so the thinking went, and people need a place to make them shorter. Phase 1: Shorten URLs...

So now it's 5 years later, and I thought it would be interesting to see what become of that unraveling chain of hopes and dreams. Here they are, in reverese order of resolve-y-ness:

  1. ALIVE. Correctly resolves to
  2. ALIVE. Correctly resolves to
  3. ALIVE. Correctly resolves to
  4. Service: ? Link: DEAD. I'm not even sure how this one ever worked!
  5. DEAD. Domain squatter-ed
  6. ALIVE. "The internet's first and only sex-positive url shortener".
  7. ALIVE "Free short URLS since 1999"
  8. Service: ALIVE Link: DEAD. This looks reasonable though: "Link Disabled because of T&C violation".
  9. DEAD. Domain squatter-ed
  10. DEAD. "Wurl Redirection Service is permanently closed."
  11. DEAD. Domain squatter-ed
  12. ALIVE. "Snippety snip snip". Whatever that means.
  13. DEAD. Redirects link to a 404.
  14. DEAD. Domain squatter-ed. Also, my office router warns "Gateway BOTNET Filter Alert".
  15. ALIVE. Resolves correctly, but the service has a lovely broken image gif as a logo now.

I was quite impressed to discover that 8 out 15 still resolve the links correctly (counting the T&C violation). That means that only around half of world's shortened URLs now 404: much better than I thought! I'll revisit this post in 2020, so be sure to come back then to see how it goes - just keeping this handy 8x shortened link lying around. I've run it through all the remaining contenders, so I see no reason it won't resolve in another 5 years.

Wanna do new JavaScript + React?

Here's the "easiest" way to get started with the latest version of JavaScript (so much new stuff in es2105!) and the most popular kid (for this week, at least) in the JS framework playground: React.

This approach uses the wonderful new JSPM package manager... so if you're not willing to place your bet on this particular horse, then head over to WebPack land to see if they have a similar guide. Also, if you want to see the final product - here's my "ES2015+React boilerplate".

Read on for more »

Announcing JS.scala v0.1

I'm pleased to announce the initial releas of JS.scala. JS.scala compiles JavaScript source code to Scala source code, allowing you to write your web application entirely in JavaScript! Finally, the expressive power of JavaScript available on the JVM via Scala (some call it "the bytecode of the JVM bytecode").

How does it work? Well, given the JavaScript input:

const a = 42
const b = "Hello, World"
const sq = x => x * x
const dsq = x => {
  const dx = sq(x)
  return dx * dx
const d = dsq(a)

const exclaimer = {
  apply: name => name + "!"

exclaimer.apply("Hello, World")

We get the lovely Scala output: Read on for more »

Mac service: open iTerm at selection path

Opening the current folder or file path in iTerm is something I want to do a lot. The second time I ever wanted to do this I decided I should automate it. The 10,000th time I wanted to do this, I actually did automate it.

Here is an applescripted automator service to open the current selection path in a new iTerm window:

mac services list
Clicking on the option will spawn a new iTerm window, and cd to either the folder path, or the containing folder if it's a file:
path opened in bash
Read on for more »