Playing with JavaScript callbacks

Moin Moin,

while watching a stupid film in TV, what can you better do than playing with Firebug’s JS console. Actually I played with callbacks. Here ist what I did:

console.log("FIRST WAY:")

var fn = (function(param) {
    console.log("param in fn (first way): " + param);    
}('bla'));

var action = function(callback) {
    callback;
}

console.log("calling action:");
action(fn);
console.log("action is a: " + typeof action);
console.log("fn is a: " + typeof fn);

console.log(" ")
console.log("OTHER WAY:")

var fn = function(param) {
    console.log("param in fn (other way): " + param);
}

var action = function(callback) {
    var param = 'other way';
    callback(param);
}

console.log("calling action:");
action(fn);
console.log("action is a: " + typeof action);
console.log("fn is a: " + typeof fn);

Result:

FIRST WAY:
param in fn (first way): bla
calling action:
action is a: function
fn is a: undefined

OTHER WAY:
calling action:
param in fn (other way): other way
action is a: function
fn is a: function

Hm - what’s that? Yeah - just playing around. Actually there are two things which are kind of interesting. First, the anonymous function is called immediately after it was built. Even though it is held in a variable (fn).
The second thing is, that the typeof fn is undefined. Hm … I don’t know why at the moment I am writing this. I would expect it is a string. I will examine this further.

One side note: you have to call the callback in action() in the first approach as a string because it’s not a function - that’s why I assume it should be typeof string.

The conclusion is: don’t use the first way because it does not work and does not make sense at all.

Posted Sunday, November 28th, at 9:46 PM (∞).

CouchDB Article in German PHP Magazin online

Moin Moin,

I just got the info, that my CouchDB article from German PHP Magazine 5.10 is available online:

http://it-republik.de/php/artikel/Ein-PHP-Wrapper-fuer-die-CouchDB-3463.html

You’ll read some basic stuff ‘bout CouchDB and I show a simple way, how to build a PHP wrapper for basic CouchDB operations like adding, updating or deleting documents.

Btw: you should have a look to the new couchone CouchDB API!

Comments are very welcome.

Cheers

Andy

Posted Thursday, November 25th, at 9:44 AM (∞).

Kongo Skulls live 13.11.2010 Platzhirsch Hamburg

Moin Moin,

my good friends from Kongo Skulls are playing a gig in Hamburg this month. Check it out and come over to drink beers ….

Posted Monday, November 1st, at 9:56 AM (∞).

Promote JS!

Moin Moin,

maybe the most important thing I took back home from #jsconf last weekend is the “deep from the heart” Community JS speech by Chris Williams (@voodootikigod) with the call to Promote JS:

JavaScript Reference, JavaScript Guide, JavaScript API, JS API, JS Guide, JS Reference, Learn JS, JS Documentation

Go, do the same and get the code here: http://promotejs.com

Arrrrrrrrrr

Andy (@awenkhh)

Posted Tuesday, September 28th, at 7:27 PM (∞).

Migrating my IMAP mailbox to Google Mail with larch

Moin Moin,

recently I decided to migrate my IMAP mailbox, hosted on one of our server, to Google Mail. There are a lot of advantages using Google Mail or any other (good) web based client. I decided to use Ryan Grove’s larch Ruby program to get the job done.

There is also imapsync written by Gilles Lamiral in PERL.

Everything went quite well besides the fact, that Google is obviously using their own interpretation of the IMAP mailbox folder. I had a lot of issues with subfolders and took the time to move every mail into INBOX.subfolder. Not deeper.

Ok quite a lot of work because my mailbox is 2.8 GB big. But what the heck. You don’t really need a subfolder subfolder in a subfolder structure because Google Mail is using labels for marking emails. And don’t forget that there is a really powerful fulltext search. So keep it simple and forget about the subfolder insanity.

The cool thing is the fact, that larch is available as a gem. So you need ruby (you already have it or you can install it with the supported package manager of your OS) and rubygems. After installing both, simply type:

$ gem install larch

That’s it. A simple command for transfering a mailbox to google is looking like this:

$ larch --from imap://mail.server.com --to imaps://imap.googlemail.com --from- \ 
folder 'INBOX.Andy' --to-folder 'Andy'

This would transfer every mail found in the folder Andy of your IMAP mailbox to a folder Andy in Google mail. After firing this command, you will be promted to give your login credentials of both your IMAP mailbox and of your Google Mail account.

You can also use a config file where you write in your credentials and some migration (folder) information. The file can be found in /home/you/.larch/config.yaml. Note that some options are only available in the latest dev version.

One good thing more. Larch is tracking the status of the transfer of each email in a sqlite3 database (alos in the .larch folder). So in the normal case, no email will be transfered twice but if the email was not already transfered, larch is trying to do so in a second attempt.

My feedback is simple: this is a very easy to use tool and is helping a lot for migrating a IMAP email box to another server. Thanks Ryan …

Andy

Posted Wednesday, September 15th, at 11:40 PM (∞).

Powered by Tumblr; themed by Adam Lloyd.