/dev/nikc/blog

Kuolleiden purjehduskenkien seura

Dec 20th 2012

Jumping jack tab

15:07

I use the console a lot. I also like to patch together small scripts to make my shell experience smoother and more efficient. (Read: indulge my laziness.) Inspired by a talk by Paul Irish where he introduces his selection of tools - specifically a command for quickly jumping into a project folder, which I naturally immediately adopted. Just to show off, I also included tab-completion.

If you feel you could use it, snag the source code below (and party on!), or download it from the gist.

Setting up is pretty straight forward and is "documented" in the comments at the top. If you don't like z for the command, just change the name of the function. (It's the last function in the source.) Don't forget to change the command on the last line or you'll lose the tab-completion.

#!bash

#  Usage:
#
#  In your .bashrc
#
#  export PROJECTS_HOME=<path_to_projects_root>
#  source jump-to-project.bash
#
#  In you shell:
#
#  $ z <project name>[ENTER]
#
#  Use [TAB] for auto-completion, double tap for a list.
#
#  Optionals:
#
#  export PROJECTS_SUFFIX=<optional suffix to strip>
#
#  For prettier tab-completion, fill PROJECTS_SUFFIX with a
#  value you want to strip from folder names. I use '.dev.local'
#
#  export PROJECTS_TALKATIVE=1
#
#  For some feedback when switching into a project folder,
#  fill PROJECTS_TALKATIVE with any value.

if [ "x$PROJECTS_HOME" = "x" ]; then
    echo "PROJECTS_HOME not set"
    return
fi

_find_all_projects () {
    if [ "x$1" = "x" ];
    then
        find $PROJECTS_HOME -maxdepth 1|xargs basename -s "$PROJECTS_SUFFIX"
    else
        find $PROJECTS_HOME -maxdepth 1 -name "$1*"|xargs basename -s "$PROJECTS_SUFFIX"
    fi
    return 0
}

_find_project_path () {
    find $PROJECTS_HOME -maxdepth 1 -name "$1*"
}

_find_project () {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts=$(_find_all_projects)

    COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
    return 0
}

z () {
    if [ "x$HOME" = "x" ]; then
        echo "\$HOME not set"
        return 1
    fi

    MATCHES=($(_find_all_projects $1))

    if [ "x$1" = "x" ]; then
        echo "Usage: zz <project>"
        echo "Projects:"
        echo ${MATCHES[@]}
        return 0
    fi

    if [ ${#MATCHES[@]} -eq 0 ]; then
        echo "No match for $1"
        return 0
    fi

    if [ ${#MATCHES[@]} -gt 1 ];
    then
        echo "Ambiguous match '$1': ${MATCHES[@]}"
    fi

    cd $(_find_project_path ${MATCHES[0]}) && [ ! -z "$PROJECTS_TALKATIVE" ] && echo "Project ${MATCHES[0]} in $(pwd)"

    return 0
}

complete -F _find_project z

Shorts

Jul 29th 2012

Tankkilaukussa Motoristin tietokartasto 2012

16:24

Hankin navigointitarpeisiini hiljattain Motoristin tiekartaston vuoden 2012 painoksen. Ostin kartaston Bookyn verkkokaupasta, koska se oli siellä viidenneksen halvempi kuin Karttakeskuksen verkkokaupassa.

Kartan valitsin, koska mielestäni reitin silmäily ja suunnittelu on sillä nopeampaa ja helpompaa kuin navigaattorilla. Vaikkakin pääasiassa suunnittelen kun suunnittelen reittini etukäteen tietokoneella, etenkin lennossa reititys on kartan avulla huomattavasti digitaalisia apuvälineitä kätevämpää. Tärkeä piirre on myös tiepäällysteiden näkyminen kartassa, ainakin minulle joka en suosi hiekkateitä. Eikä kartasta lopu kriittisellä hetkellä akku.

Ensivaikutelma kartastosta oli kuitenkin pettymys. Vain yksi-, kaksi- ja kolminumeroisten teiden numerot löytyvät kartoista. Seututiet, joita matkanteossani suosin, ovat kartassa anonyymejä. Käytännössä tämä osoittautui kuitenkin melko vähäiseksi haitaksi, koska suuri osa näistä teistä vie kylältä toiselle ja tienviitat ovat helpommin havaittavissa kuin tienumerot.

Toinen häiritsevä tekijä on aukeamien taitto, jossa ei ole sivulta toiselle toistuvaa kaistaletta, toisin kuin aukeamien välillä. Kun karttaa on tarkoitus käyttää vain yksi sivu näkyvissä, on vaikea ymmärtää miten tällaiseen taittoon on päädytty. Alla olevassa kuvassa näkyvä Hikiän ja Oitin välinen osuus on valitettava esimerkki tällaisen sivujaon haitoista.

Taajamakarttoihin ei ole merkitty kuin merkittävimmät sisään- tai läpiajoväylät, mikä on kai tavallista, mutta harmillista kuitenkin. Mielestäni hieman suuremman mittakaavan vaatimat muutamat lisäsivut eivät olisi haitaksi. Ainakin minun tankkilaukkuni karttalokeroon mahtuisi huomattavastikin paksumpi nide.

Myöskään huolto- ja tankkausasemia ei ole merkitty kuin taajamakarttoihin ja pääkaupunkiseudun kattavalle aukeamalle. Mielelläni olisin nähnyt ne maantiekartoissakin.

Loppujen lopuksi, hinta ei kuitenkaan päätä huimannut ja kartasto on käytössä osoittautunut toimivaksi, joten olen hankintaani tyytyväinen.

Shorts

  • Generate data, will, as the name suggests, generate data for inserting into your pristine, empty database.

    (0) #

  • Since I have no real content to share, I'll post a few more dummy content providers. Fixie.js (not moustache complete) FlickrHoldr (moustache complete).

    (0) #

  • Just when you thought your website was complete, you found Clippy-js.

    (0) #

  • I've been using Dummyimage.com for generating placeholder images for a while now, but it seems there are now at least two three alternatives; Placekitten.com for when you need cute, and Placesheen.com for when you don't. Placehold.it seems to be pretty much a clone of dummyimage.com. And if you need a noisy background image, look no further than NoisePNG.

    (0) #

May 7th 2012

Ramblings of a beginner motorist

17:03

After putting it off for years and years I finally got myself a motorcycle driving license last fall, along with a motorcycle to go with it, of course. Now, after putting it off for months and months, I thought I'd jot down some words for generations to come to liven up this nowadays very stale blog of mine.

This is a posthumous recounting of my complete (albeit still fairly brief) career as a motorist, so it's a bit on the lengthy side.

The bike

I wanted a classic, that much I was sure of. Something with as little plastic as possible. But at the same time, something reliable, because I neither enjoy nor am very competent at repairing stuff. That, I thought, spells "japanese motorcycle", because of their reputation for being virtually unbreakable workhorses.

I had previously been looking at a Honda CX, but my memory failed me by one letter and I ended up window shopping for a Honda CB instead. Which was a fortunate memory lapse, because I really prefer its' appearance over the CX's.

Ultimately, I got myself a Honda CB750K7 (1977), drove it for a week, after which it was stolen. Thank goodness for insurance!

A month or so later, I bought my second Honda CB750K7 (1978), which I still own today.

The bike is essentially in original condition; cosmetically worn but runs very well. The side covers have been replaced at some point, though, and are of the wrong colour.

Gearing up

Beginning motorcycling is expensive, really expensive. But initially going cheap, and later replacing substandard gear is even more so. Thus, I decided I wouldn't cut corners based on price - after all, it's all about my own safety and comfort.

But finding good quality gear is not easy, however, and it's increasingly hard when you're as vain as I can be. I wanted something that matches the feel of the bike I ride, and to make it even more difficult, something without huge brand marks printed on the chest or back - a much too prevalent feature when it comes to motorcycling wear.

Eventually I found Halvarsson's Classic Thunder leather jacket, and Halvarsson's Morgan Classic leather trousers to match. A comfortable outfit with protective armor, and, most importantly, which also matches my other criteria.

The new season arrives, with no spark in sight

With the amount of daylight increasing by minutes every day and the remaining snow receding at an accelerating pace, I was eager to get the bike back on the road. In early April, I performed spring maintenance on the bike, installing new filters and replacing brake fluid and engine oil. But unfortunately the battery had died during the winter. An unfortunate incident which delayed my start of the season, because during easter no shops are open.

A week later, I swapped in a new battery and fired her up with a "single push start," as if she had been sitting under a palm tree all winter. And even though it was a very cold day, that couldn't keep me from aimlessly riding around for a few hours, as I knew I could thaw my frozen body in the sauna afterwards. The most important thing was that the season was now officially opened.

Fixer-upper

For this season, as it is my first full season, I've decided to do only minimal work on the bike. Just enough to keep it in good running condition, but nothing more, and mostly just concentrate on the driving. Perhaps next spring will bring along bigger overhauls and repairs.

I did replace the shitty aftermarket mirrors one of the previous owners had fitted, with aftermarket replicas. Not only an improvement in appearance, but a gigantic functional improvement as well! The ones I replaced had a silicone lined joint (which looked like some DIY magic) which caused the mirrors to vibrate to the extent of being completely useless already at very low speeds, whereas the aftermarket replicas vibrate only slightly at highway speeds. Marvellous!

Also, I fitted a chrome visor on the headlight, because I can. Now she's officially a custom bike :-)

For those interested, I keep a gallery of snaps from my day-trips.

Feb 21st 2012

Fluent I/O from Down Under

08:20

I stumbled upon an article about Fluent.io, a product in the making by the guys who brought you Google Wave, Google's now discontinued attempt to radically renew collaboration and real time communication on the internet.

After reading the article and watching the promo video, I must say Fluent.io looks promising - I certainly welcome the innovation and any attempt to improve the status quo. Especially the search looks impressive - a feature where the otherwise lovely GMail falls short in ways I can't even begin to describe.

But at the same time I can't help feeling a bit concerned. While there is potential to make using e-mail a smoother, less painful experience, the stream UX is likely to lower the threshold to send short spur of the moment messages, wherein lies a risk of making e-mailing too similar to instant messaging or commenting on Facebook. A trait I feel would be counter productive as that would hardly reduce the number of e-mails received, and I'm sure anyone would agree todays torrential stream of e-mail is one of the biggest, if not the biggest, reasons e-mail is as unusable as it today is in the first place.

The problem would probably not be apparent to the one using Fluent.io, but rather to the one who isn't. Using Fluent.io you will most likely get all the messages intelligently grouped as a single item, perhaps even merging sequential messages for the same subject as a single one, while the one sticking to a non-intelligent client will simply get an inbox full of stub messages. A similar phenomenon probably occurred when GMail gained popularity, but I believe this effect has since diminished by the introduction of integrated Google Talk, as well as the wide adoption of Facebook for inane communication.

But there probably isn't reason for alarm, because there seems to be no plans for a free subscription - who the hell pays for anything anymore these days? Or have you heard of anyone using Flowdock?

Feb 11th 2012

How I created a Pong-clone using Node.js, Canvas, WebSocket and DeviceOrientation

11:14

For my first Node.js project I created a Pong-clone. The game was presented to the public during Luxus Digital Week; a conceptual digital exhibition organized by my employer. You can see the game in action in the below video.

Read the rest of this entry »

Shorts

Jan 4th 2012

Sublime Text 2 and the command line

15:15

Since about half a year ago I migrated from Textmate to Sublime Text 2, simply because it's awesome. Of course, as with all software, it has its shortcomings, but nothing I can't live with.

But one thing which really bothered me and occasionally made me return to Textmate was Sublime's lack of a command line companion tool. I spend a lot (most) of my time on the command line and the lack of a command line helper was a real drag. But as I like both the command line and Sublime Text 2, and not willing to give up either, I simply wouldn't believe the situation couldn't be remedied and embarked on a mission to find a solution.

If all you need is a shortcut for opening files and folders, a simple alias is enough:

alias slt='open -a "Sublime Text 2"'

But this doesn't allow for creating new files or the use of pipes. Both of which are frequent use cases for me. To accomplish this, a bit more code in the form of a bash function comes to the resque:

function slt() {
    if [ -z "$1" -a -t 0 ]; then
        echo "slt file [...]"
        return 0
    fi

    if [ -z "$1" ]; then
        open -a "Sublime Text 2" -f
    else
        for arg in $*; do
            [ ! -f "$arg" -a ! -d "$arg" ] && touch $arg
        done
        open -a "Sublime Text 2" $*
    fi

    return 0
}

And voila! Copy and paste into your .bashrc and your new best friend can now be used to edit new files and read stdin1 from the command line.

Disclaimer: This script hasn't been tested on anything other than OS X 10.6.8. Most likely if you're on Linux you won't need any of this extra malarkey, and if you're on Windows, well, you have my sympathies.

1 There is one shortcoming; only piped content works, not redirected input. If you can fix this, you're welcome to leave a comment, but I'm not losing any sleep because of this.

Meta

Pages

Search blog

Latest comments