/dev/nikc/blog

Kuolleiden purjehduskenkien seura

Shorts

Nov 10th 2014

Differential Syncing

16:57

For a personal project, I looked into the magical world of how to sync work from two or more peers on a single item, without anyone losing their work.

Thankfully, Neil Fraser has published a paper on Diff Strategies, Fuzzy Patching, and indeed Differential Synchronization. Even more thankfully, Google has open sourced a diff-match-patch library (ported to several popular programming languages) that does all the heavy lifting for you.

Most likely my personal project will never be finished to a point where it would be made public, but since I found this stuff interesting, I just thought I'd put this out there for others to enjoy.

Aug 24th 2014

Blogi on kuollut, kauan eläköön blogi!

16:14

Kun kahdeksan vuotta sitten muutin Helsinkiin, blogiskene oli suomessa voimissaan. Huippuaikaa kesti kai muutaman hienon ja miitintäyteisen vuoden, jonka jälkeen iski ähky ja inflaatio. Blogeja alkoi syntyä enemmän kuin koskaan, mutta laadukas sisältö muuttui entistä vaikeammin löydettäväksi.

Siitä se ajatus heräsi, kun lomallelähtökaljaa olin ryystämässä. Kun heinäsuovasta on niin kovin vaikeaa löytää neulaa, kenties kädestä pitävä opas olisi vastaus.

Inspiroituneena kasasin kesäloman aikana JustNytin. Palvelua on nyt beta-testattu parisen viikkoa ja toimii riittävän hyvin noustakseen varjoista.

Jos innostuit, lähde mukaan: levitä sanaa, ilmoittaudu kuraattoriksi.

Jul 19th 2014

Better tools for procrastination

14:20

I have a problem: the internet. Or rather the vast amount of interesting content being published versus the time and energy I have to consume it. I'll read an article here, bookmark an article there, but mostly I just open stuff in tabs in order to "read them later." And I know I'm not alone.

Currently, I have too many bookmarks to count both locally and in various cloud services, but more importantly around 80 tabs across 9 windows open. More importantly because those tabs and windows each use up a chunk of the finite RAM memory in my computer. As a result of this my computer almost constantly feels sluggish.

Now, I know the right course of action would be to address my behaviour. But who does the right thing?

In lieu of improving my judgment on what's truly worth my time and attention, I instead found a tool to help me with the immediate symptom: The Great Suspender.

The Great Suspender suspends a tab after a set timeout, unless it matches a white list, or on demand. Individual tabs or all tabs in a window can later be restored as needed.

What I really need is a plugin that will simply close unattended tabs after a period of time. Because, even though I really do revisit some of those postponed articles, many are just waiting to be bookmarked and forgotten about forever. Perhaps I'll add it to my ever growing list of hobby projects...

Shorts

Dec 3rd 2013

Managing scrollTop in your Backbone single-page app

19:04

One of the great caveats of single-page apps is that they rely on taking over many of the browser's default behaviours. One of the more significant ones is how the browser behaves on page-to-page navigation, be it forwards or backwards. By default, the browser will take you to the top of the page when you navigate forwards by following a link. In contrast, you expect to be returned to the position on the page where you followed a link, when you use your browser's back-button.

In case you happen to be using Backbone to power your single-page app, this behaviour can be restored with very little effort and code. Unfortunately, this will only work in browsers supporting the History API, so old-IE (IE 9 and earlier) users are out of luck.

To pull it off, a global navigation event listener is used to store the current scrollTop just-in-time.

// A global a.onclick event handler for all your navigational needs
// see e.g. Backbone Boilerplate for a more complete example
$(document).on("click", "a", function (ev) {
    ev.preventDefault();

    // Replace current state before triggering the next route, 
    // storing the scrollTop in the state object
    history.replaceState(
        _.extend(history.state || {}, { 
            scrollTop: document.body.scrollTop || $(document).scrollTop() 
        }),
        document.title,
        window.location
    );

    Backbone.history.navigate(this.pathname, { trigger: true });
});

Listening to the route event from your Backbone.Router you then restore scrollTop when it exists in history.state, or default to page top. To catch navigation happening via the back- and forward-buttons in the browser, Backbone.history should be set up to listen for popState events by setting { pushState: true } in the options to Backbone.history.start().

// Backbone.Routers trigger the route-event
// after the route-handler is finished
var router = new AppRouter(); // AppRouter extends from Backbone.Router

router.on("route", function () {
    // Inspect history state for a scrollTop property,
    // otherwise default to scrollTop=0
    var scrollTop = history.state && history.state.scrollTop || 0;

    $("html,body").scrollTop(scrollTop);
});

For those who need to see before they believe, take a look at the demo.

NB. The code examples are simplified to the extreme and shouldn't be treated as complete drop in code.

Shorts

Oct 21st 2013

Revisiting an old classic

11:02

Last weekend, I clocked in quite a few hours playing an old classic: Frontier: Elite II. What inspired me to dust off a 20 year old game, was a series of Frontier tutorial videos I stumbled upon. While waiting for the upcoming Elite: Dangerous to be released, I'll probably spend copious amounts of time exploring the vastness of space.

If the idea of being a space trader or rogue assassin tickles your fancy, but you're the kind of person who prefers more advanced graphics, you should check out Pioneer. It's an open source remake of Frontier with a very nice looking facelift.

If you, like me, prefer the original, a good source of information can be found at the Frontierverse website.

Aug 24th 2013

DigiPod wants to revive your old gear

22:57

DigiPod promises to deliver what Silicon couldn't. The sub full-frame sensor is a bit of a let-down, but the prospect of having all that film gear for digital photography is interesting nonetheless.

Shorts

Meta

Pages

Search blog

Latest comments