/dev/nikc/blog

Kuolleiden purjehduskenkien seura

Shorts

Mar 2nd 2011

I pity the fool (who tries to lure me into creating a user account)

22:57

A while back, Jeff Atwood wrote about the proverbial Internet Driver’s license. I liked the article and agreed wholeheartedly. Lately even more so.

Nowadays, hardly a month passes when a new service or interesting site doesn’t pop up, that one simply “must” check out to keep on top of the game – especially being part of the industry, but mostly due to curiosity or peer pressure. Often, this site or service will offer a higher level of service if you register as a member. In my case, I tend to create user accounts just to take the alias I use off the market. Or, rather, I used to do so.

Lately I’ve noticed that I mostly shun away from sites that require me to create a new user account. It’ll have to be something pretty damn special for me to care. Despite the fact that I’ve given up on managing my credentials mentally and handed over the task to 1Password. I just don’t want Yet Another User Account, when there are existing established solutions available which will let me identify myself using one that I already have.

So stop asking me to register and let me use the identity provider of my own choice.

Shorts

Jan 19th 2011

Which platform do you want to frustrate you today?

23:05

Thanks to the Mobile Meetup arranged by Frontend Finland, I was presented a quick look into the current state of developing apps for the three leading mobile platforms today, presented by people who are actually doing it. Personally, mobile development is a field I’ve dabbled time to time in over the years, but never created anything useful due to several reasons; me (and my [lack of] creativity) probably being the biggest obstacle and the lack of paying customers for my employers following closely after.

Of the platforms presented today, surprisingly, Qt Quick together with QML seemed the most appealing to the coder inside me, but sadly isn’t very current for me. iOS probably tickled the drag-and-droppers in the crowd – me, not so much. Android should be right down the alley for those who are familiar with razors and/or cranial acceleration towards firm surfaces – not the least thanks to the tools that are (not) available.

It really is a jungle out there. Maybe one day there’ll be a machete that’ll allow us to hack-n-slash our way through it in style.

Jan 13th 2011

Päivän pituus one-liner

16:56

<code>/usr/bin/curl -s http://ilmatieteenlaitos.fi/saa/Helsinki|/usr/bin/grep "Päivän pituus"|/usr/bin/sed -e 's/^[ ]*//' -e 's/<[/]\{0,1\}[^>]*>//g'</code>
Jan 4th 2011

Unexpected asynchronous script execution

17:14

I spent today debugging strange JavaScript behaviour in Firefox. The scenario was as follows:

The main interface of the app I’m working on loads document fragments on demand. These fragments contain script blocks. We use jQuery to load these fragments.

When jQuery.appending a new fragment into the DOM jQuery cleverly extracts all script nodes from the fragment and then synchronously executes them in the order they appear, regardless if their source is external or inline, and only after all scripts have been evaluated returns. A blocking operation, which in our case is what we want.

The script handling the main interface (and pulling in the needed bits) depends on this behaviour —(which might be silly and could be avoided by redesigning the architecture, but that’s a different story)— and today it broke for no apparent reason. After some hours of peeking and poking I found the culprit to be Facebooks’ loader script which appends more scripts with external sources into the DOM. The fact that the script came from Facebook is irrelevant here, the injected script nodes aren’t1.

Safari and Chrome handles this elegantly, leaving jQuery’s behaviour unchanged, but in Firefox it caused jQuery to return prematurely. In Firefox, it looks as if the dynamically injected externally sourced script node is forcing asynchronous evaluation to all dynamically injected script nodes, including the ones with inline source code.

The solution was simple enough: keep the Facebook share script at the bottom, but locating the issue was a pain. Whether or not this is a Firefox bug, I don’t know, but I couldn’t find anything on the issue so I thought I’d give it my 2 cents.

A simple demo, for those who are curious. Latest production version to date of all mentioned browsers were used in testing.

Sep 14th 2010

Dummy sendmail for development environments

21:21

Most developers working with the web will sooner or later need to deal with sending e-mail. Usually it’s a contact or feedback form that needs to be delivered to an inbox in a nearby universe.

What has been bugging me about this is that whenever I need to send e-mail, I actually need to use e-mail, which slows things down and is cumbersome in so many ways, since your sysadmin didn’t configure the mailer on the development server – and more often than not, that development environment is your own laptop and I certainly don’t want to setup a working mailer on mine. Besides, I might not even be connected to a network. And don’t even get me started on when you need to dry run bulk mailing.

Luckily, at least if you’re running *nix, there’s a very simple solution; replace your sendmail binary with the following shell script1:

<code>#!/bin/bash

LOGDIR="/tmp/sendmail-sim"
NOW=$(date +%Y-%m-%dT%H.%M.%S)
CNT=1
PRIVATELOG="$LOGDIR/$NOW.$CNT.log"
COMBINEDLOG="$LOGDIR/combined.log"

# If privatelogs are being used...
if [ ! -z "$PRIVATELOG" ]; then
    # ...make sure the filename is unique and create the file
    while [ -f $PRIVATELOG ]; do
        CNT=$(($CNT + 1))
        PRIVATELOG="$LOGDIR/$NOW.$CNT.log"
    done

    echo "$0 $*" > $PRIVATELOG
else
    # ...otherwise swap filenames
    PRIVATELOG=$COMBINEDLOG
    COMBINEDLOG=''
fi

echo "[$NOW]" >> $PRIVATELOG
while read BUF
do
    echo $BUF >> $PRIVATELOG
done

# Append privatelog to combinedlog when both logs are used
if [ ! -z "$COMBINEDLOG" ]; then
    echo "[$NOW]" >> $COMBINEDLOG
    cat $PRIVATELOG >> $COMBINEDLOG
fi

exit 0</code>

This will result in all input that is sent to sendmail being written to a separate2 log file in the /tmp/sendmail-sim directory, as well as a combined.log for convenient tailing.

Oct 7th 2009

Radion tekstitystä odotellessa

07:11

Kuulin juuri radiomainoksen, siinä mainittiin lopuksi verkko-osoite zodiac.fi. Tai siis, niin minä luulin. Todellisuudessa mainostettu osoite taisi kuitenkin olla zodiak.fi, ainakin mainoksen tyylilajista päätellen, en minä sitä niin tarkkaan kuunnellut ja kofeiinikin kohisi korvissa.

Ongelmallinen tilanne tietysti noin läheiset verkko-osoitteet, kun K-kirjain ei po. sanassa lausuttaessa eroa C-kirjaimesta. Ehkä sitten olisi ollut erottuvampaa mikäli valittu ylätason verkkotunnus olisi ollut jokin muu kuin .fi, tai isäntänimelle annettu etuliite.

Ainakin radiota varten.

Jun 10th 2009

Seamless mp3-playback in flash

20:52

I have the pleasure of working with flash. And when I say pleasure, I actually mean it. Except for on those special occasions, which are more frequent than I’d like them to be.

My latest task was to create a simple tracker(Wikipedia: Tracker). You’ve all seen one of them; drag the samples on to the timeline and press play on tape to hear your masterpiece. All good and dandy, sounds like a fun little project. My only worry was regarding playing back the samples one after another, as working with sounds in flash isn’t quite as smooth as I’d like it to be.

Luckily, we’ve already (heh) migrated to Flash 9 and AS3(Actionscript 3), so I figured most of the pain I remembered from the days of AS2(Actionscript 2) would be gone by now. But how wrong was I…

Flash is not alone to take the blame though. As it turns out, mp3 encoders always create a short lead in and out when encoding. That’s problem number 1.

Problem number 2 is that the Event.SOUND_COMPLETE-event flash so conveniently provides you with, isn’t usable in this case, because playing sounds sequentially when the event triggers, results in a short but disastrous gap between sounds, making the event useless (in this case).

Problem number 3 is an interesting one. Let’s say, that I have a 1.8 seconds long sound. When I load that sound into my flash movie, the Sound-object will say that the duration is 1800 milliseconds. However, when I play it back, the SoundChannel-object will trigger the soundComplete-event a bit before the Sound.position reaches that magical 1800 marker.

It seems, that the good folks at Macromedia Adobe have tried to create a mechanism that works around the automagically inserted lead in and out. The article linked to at the top notes that importing a wav-file into the library will result in gapless mp3-encoded sound, and it seems (just speculating here) that the SoundChannel-object is trying to mimic that behaviour, but failing to do so, or perhaps it’s just the Sound-object that fails at accounting for the lead in and out when setting its own length.

Firstly, it does in no way account for the lead in. Secondly, the unconsistency between Sound.length and the point where the soundComplete-event triggers, makes the situation even worse when trying to programmatically work around the shortcomings of the mp3-format and the Sound API (Application Programming Interface).

Lastly, I’ve found no pattern in the manner that the Sound.length relates to the point where the soundComplete-event triggers, so I can’t calculate it. (Disclaimer: my tests have not been thorough, rigorous and scientific, so this is not to be taken as absolute truth — it also most probably related to mp3-encoding and not the Sound API, but I’m mostly guessing.) The “solution” I came up with, was to play back the sound silently and record the position where the soundComplete-event triggers — certainly not elegant, but it works.

For the overall problem of gapless playback, I used an existing “solution” (scroll down to part b) which is basically an event triggering every millisecond to stop and start sounds at the right moment. Quite resource wasteful and certainly not foolproof, but it solved circumvented the problem at hand.

Shorts

Mar 13th 2009

Selainten kiihdytysajot

14:59

Futuremark (beta)julkaisi Peacemaker suorituskykytestin selaimille. Jos siis tuntuu että toinen selain on toista tahmeampi, saatat hyvinkin olla oikeassa ja nyt voit saada tunteillesi lukujakin tueksi.

Henkilökohtainen suosikkini, Firefox ei päässyt testaamistani selaimista kärkikahinoihin, mutta luulen että tilanne olisi toinen mikäli liitännäisiä ei olisi n+1 kpl käytössä.

Meta

Pages

Search blog

Latest comments