Skip to content

Nuudelisoppa

  • Archives
  • jQuery-style function calls with callback parameters & parameter expansion defaults

    Disclaimers:

    1. I’m still learning my way with jQuery.
    2. Code here is pseudocode carved from functioning code (and even then only partly so), so it’s untested in real world.

    I was curious as to how jQuery does parameter expansion in event handlers with callbacks. Googling I could only come up with resources that would call their custom functions with parameters given as object literals, like so:

    myFunc({
      parameter1 : 12345,
      parameter2 : "foo"
    });

    , which, when using a callback parameter, would go something like:

    myFunc({
      parameter1 : 12345,
      callback : function() {
        return true;
      }
    });

    Now, there’s nothing wrong with that as such. What I wanted however, was to be able to call my custom functions in the elegant way jQuery does it, without the object literal brackets surrounding the parameters, like so:

    myFunc(12345, function() {
        return true;
    });

    Here’s how I could achieve this:

    jQuery.fn.myFunc = function() {
    	var options = {
    		parameter1 : (arguments[0] || 0),
    		callback : (arguments[1] || function() { return false; })
    	}
    
    	do_stuff_with_param1(options.parameter1);
            return options.callback();
    }
    2011/06/30
  • Bitlbee, Twitter, 403, base_url, “could not find setting”

    The 403 issue is fixed in a new release of Bitlbee, but those of us relying on third-party servers running older versions need to use a workaround. Comment #3 by wilmer on the tracker ticket says the workaround is to issue:

    ac tw2 set base_url http://api.twitter.com/1

    However, applying this to settings on my server running Debian Lenny took some effort, so I’m making a note of the working format here:

    account set 2/base_url 'http://api.twitter.com/1'

    (where ‘2’ is the number of my bitlbee account connected to twitter)

    2011/06/30
  • (Bash) command line equivalent of strip_tags()

    php -r 'echo strip_tags(file_get_contents($argv[1]));' file_to_strip

    And as an alias:

    alias strip_tags="php -r 'echo strip_tags(file_get_contents(\$argv[1]));'"
    2011/06/13
  • Linking to specific language versions of Google’s Privacy Policy

    This took a bit of detective work, so I thought I’d post it here for other googlers to readily see:

    • http://www.google.com/intl/en/privacy/privacy-policy.html is the English Privacy Policy.
    • http://www.google.com/intl/fi/privacy/privacy-policy.html, for example, is the Finnish Tietosuojakäytäntö.

    Replace the bolded part (“fi” in the example above) with the two-letter country code of your choice.

    2011/05/31
  • Palautetta Helsingin yliopiston tietotekniikkaosastolle

    Olinpa eilen repiä hermoni, kun minun piti vaihtaa yliopistoverkkoon saamani käyttäjätunnuksen oletussalasana.

    1. Salasanan pituus on rajattu korkeintaan 14 merkkiin. Miksi ihmeessä tällainen rajaus? Järjestelmät, jotka eivät tue tuon turvallisempia salasanoja, olisi pelkästään tietoturvankin takia syytä korjata tai päivittää nykyaikaisempiin.

    2. Tuo pituusrajoitus paljastuu käyttäjälle vasta, kun salasananvaihtolomakkeeseen on tarjonnut 14 merkkiä pidempää salasanaa (“Enimmäispituus on 14merkkiä”). Miksi ihmeessä vasta silloin? Miksei näitä keskeisimpiä salasanalle asetettuja rajoituksia ole listattu lomakesivulla, jottei käyttäjän tarvitsisi kokeilla päästäkseen niistä perille? Pieni “Apua”-linkki siinä lomakkeen alalaidassa ei aja alkuunkaan samaa asiaa.

    3. Salasananvaihtolomake antaa mukisematta vaihtaa salasanan sellaiseksi, jossa on tyhjeitä ja muita erikoismerkkejä, vaikka tällainen salasana ei toisaalla järjestelmässä toimikaan. Voi hyvä helvetti…

    2011/05/19
  • Different 2.5 ” SATA hard disk connectors

    Today I participated in a reshuffling of laptop hard disks. I’d never seen 2.5 ” SATA drives before, and got confused for a moment by the different connector on the Toshiba HDD2D60, previously connected to a Compaq laptop. The other disk, a WD one, had what I felt looked more like true SATA connectors.

    I figured maybe there was a custom adapter on the Compaq’s motherboard I was supposed to rip out with the disk, but couldn’t find any. Turns out there was an adapter, but it was attached to the disk (duh). So I just ripped that out, and the standard SATA connectors on the disk were revealed.

    This enabled me to connect it to the other laptop, a Fujitsu U9200.

    2011/05/14
  • 404 with WordPress permalinks

    404’s on post permalinks could be due to a number of different issues, but for me it was caused by a plugin gone bad during a WordPress update: Top Level Categories was broken by WordPress 3.1, and replacing it with FV Top Level Categories was the fix.

    2011/05/01
  • How to get the default category ID in WordPress

    Damn it, Google, it isn’t that hard!

    <?php get_option('default_category'); ?>

    2011/04/29
  • All sites’ latest for WordPress

    All sites’ latest is a plugin for WordPress multisite installations to fetch and display latest posts from all sites of current blog’s owner, typically on the root site.

    It is a nasty hack, but works for me (on WP 3.1.1) and doesn’t do any database writes, so testing it is quite safe. There’s no GUI for options, you need to edit the code if you want to exclude some sites for example. You’ll need to modify the code anyway, as you’ll have to set up a special page for displaying the fetched posts and point the plugin towards it.

    Download Footnotes for WordPress (a .phps file, rename it to .php before uploading to plugins/)

    2011/04/10
  • Today’s text

    erk: C0 CE FE 84 C2 27 F7 5B D0 7A 7E B8 46 50 9F 93 B2 38 E7 70 DA CB 9F F4 A3 88 F8 12 48 2B E2 1B
    riv: 47 EE 74 54 E4 77 4C C9 B8 96 0C 7B 59 F4 C1 4D
    pub: C2 D4 AA F3 19 35 50 19 AF 99 D4 4E 2B 58 CA 29 25 2C 89 12 3D 11 D6 21 8F 40 B1 38 CA B2 9B 71 01 F3 AE B7 2A 97 50 19
      R: 80 6E 07 8F A1 52 97 90 CE 1A AE 02 BA DD 6F AA A6 AF 74 17
      n: E1 3A 7E BC 3A CC EB 1C B5 6C C8 60 FC AB DB 6A 04 8C 55 E1
      K: BA 90 55 91 68 61 B9 77 ED CB ED 92 00 50 92 F6 6C 7A 3D 8D
     Da: C5 B2 BF A1 A4 13 DD 16 F2 6D 31 C0 F2 ED 47 20 DC FB 06 70
    2011/01/28
←Previous Page
1 … 10 11 12 13 14 … 215
Next Page→

Nuudelisoppa

Good Noodles.

Twenty Twenty-Five

Designed with WordPress