Drawing a Blank
by Mike Fulcher

BrowserStack tunnel from the command line
Friday, September 20, 2013

I use BrowserStack a lot. Mostly I use it for in-development projects which are served through a local web server, so I frequently find myself going through the steps to create a web tunnel. This can be achieved through BrowserStack’s web interface but for convenience the tunnel can also be set up from the command line using java and BrowserStack’s special BrowserStackTunnel.jar file. Unfortunately, the command is quite verbose:

java -jar BrowserStackTunnel.jar <key> <host>,<port>,<ssl flag>

So to make my life a little easier, I started using this simple bash function:

function browserstack() {
  local port
  if [ $1 ]; then port=$1; else port=4000; fi
  java -jar ~/.BrowserStackTunnel.jar <key> localhost,$port,0
}

Now I can simply run browserstack in bash to set up a tunnel which defaults to localhost:4000. If my local server is running on a different port, I can pass it as an argument, eg browserstack 3000. Note that I’ve moved the BrowserStackTunnel.jar file to my home directory and renamed it with a leading . to make it hidden from Finder. Wherever you’ve placed your own jar file, just make sure to update the function to point to the correct location.

Permalink ›


Bash alias with subdirectory tab completion
Friday, September 20, 2013

I’m always on the command line, so I love aliases and functions that provide quick shortcuts to common actions. Since the actions I do most often are cd-ing into the directories of the projects I’m currently working on, I’ve put together a handy script to make this process as easy as possible – especially when you have (as I do) multiple projects which are organised in subdirectories. What makes this tab completion script particularly useful is that it supports deep nesting (just like standard Bash path completion) and it’s case-insensitive.

Continue… ›


Better indentation for injected Jekyll content
Wednesday, July 31, 2013

As much as I love Jekyll, I do have one (minor) gripe: my carefully indented code goes all to hell when the site is compiled. It’s an understandable issue, but I started wondering if it would be easy enough to apply indentation so that the compiled code comes out clean.

Continue… ›


Spinner: a Ruby gem for tasks with unknown duration
Tuesday, July 09, 2013

Inspired by gems like progressbar, spinner.rb fills a smaller niche by removing the need to increment a progress bar. Instead, spinner.rb prints to the console a tasks counter and a little animated spinner and waits for the tasks to complete. Unlike progressbar, it doesn’t report the percentage of completion or try to estimate how much time is left, which means you can feed in tasks with an unknown duration.

Continue… ›


Ruby boolean type casting
Monday, June 17, 2013

It’s been a pet peeve of mine for a while that Ruby doesn’t provide much support for typecasting boolean values. Many other programming languages implement boolean typecasting (for example in javascript 0 == false and 1 == true). In Ruby you can use the !! (“bang bang”) technique to force a boolean value, but this is a more primitive method that doesn’t account for very much beyond nil representing a false value – everything else will return true.

Continue… ›