Dent Weekly Updates for 2010-08-29

Powered by Twitter Tools

Dent Weekly Updates for 2010-08-22

  • #ubuntu devs, what are you smoking? the netbook remix includes cups! WTF? #
  • Have now heavily modified some Ubuntu packages to remove the more insane bits: openoffice, cups, f-spot, tomboy #
  • Yay, finally gotten some of the craziness out of #ubuntu netbook remix. Still a few things remaining, but much better now. #
  • I never manage to get empathy to work on #arch not sure why. #
  • It's painfully slow to download #PaulDotCom e206 this morning! #
  • I now have #empathy working at work, at least a bit, no luck with using #pidgin #039;s sipe though :( #
  • I really don't like when people cancel a meeting 2 minuntes before it starts! #
  • World map of happiness: http://www.sciencedaily.com/releases/2006/11/061113093726.htm (well, not really a map, an article about such a map) #
  • #microsoft really, it's 2010!!! How difficult is it to make re-sizable dialogue boxes? #
  • What a straw man argument! I was expecting better: http://theinvisiblethings.blogspot.com/2010/08/ms-dos-security-model.html #
  • Yay, managed to remove the use of MissingH in a #haskell tool. That's always a good thing :-) #
  • I suspect I've found a bug in cmdargs 0.2, however it only manifests itself when building with Cabal. Very strange. #haskell #
  • Ouch, vimoutliner can't be downloaded from the project site, just when I really could need it :-( Anyone out there who has a copy to share? #
  • I wonder if it's the upgrade to #ocaml 3.12 that broke the building of ocaml-data-notation. #
  • I've finally gotten around to finding out how to build #archlinux packages in a chroot. #
  • Worth watching for anyone using functional languages: http://vimeo.com/14313378 #
  • I'm reading complaints from devs running Windows that they need to install a Unix emulator to use Haskell. I love it! #

Powered by Twitter Tools

Dent Weekly Updates for 2010-08-15

Powered by Twitter Tools

XML character dereferencer

Just in case you ever need one:

xmlCharDeref :: String -> String
xmlCharDeref [] = []
xmlCharDeref ('&':'#':'x':r) = let
        (digits, remainder) = span (/= ';') r
        c = chr (read ("0x" ++ digits))
    in
        c : xmlCharDeref (tail remainder)
xmlCharDeref ('&':'#':r) = let
        (digits, remainder) = span (/= ';') r
        c = chr (read digits)
    in
        c : xmlCharDeref (tail remainder)
xmlCharDeref (c:r) = c : xmlCharDeref r

In ghci:

*Foo> xmlCharDeref "hello there"
"hello there"
*Foo> xmlCharDeref "hello there"
"hello there"
*Foo> xmlCharDeref "hello2there"
"hello2there"

Dent Weekly Updates for 2010-08-08

  • #ocaml craziness, 'land' is infix, so "land;;" gives a syntax error, "(land);;" is what you want, but docs don't mention this!!! #
  • Yay, another vim extension on #aur that can be removed since upstream releases as VBA; vim-scripts-xmledit #
  • Surely it's a bit silly that the username counts in replies! #
  • ? @johnnieingram: I'm trying to think how this could possibly be any cooler, but I'm coming up blank http://youtu.be/PfK-UzQ48JE #
  • List changesets touching a set of files #hg for f in *.c; do hg log -f $f|grep changeset|cut -f2,3 -d:|tr -d ' '; done|sort|uniq #
  • Wanted: a #wp plugin that links a blog post to its reddit page (if there is one). #
  • Note to self: the only functioning #arch package for rpm is rpm-org (off of #aur of course). #
  • I'm still not quite back to normal after the £566 car "service" yesterday :( #
  • Seriously considering moving my CMake/OCaml stuff off of bitbucket, git+branches is just better than HG+patchqueues. #
  • So, now cmake-ocaml lives on github instead. #
  • Hacking a bit more on cmake-ocaml; adding simple annot support, not sure what I'm doing though, so likely to not be what people want :) #
  • Many Americans seem to confuse "loud minority" with "majority". #
  • Funny: http://feeds.wired.com/~r/wired27b/~3/IEM0MNEAkaU/ #
  • I couldn't agree more: http://www.thelocal.se/28198/20100805/ #
  • Yay, after recent kernel upgrade hibernate+suspend is now working properly. #arch #linux #

Powered by Twitter Tools

Dent Weekly Updates for 2010-08-01

  • Finally I've upgraded #wordpress on therning.org/magnus #

Powered by Twitter Tools

Any Haskell puzzlers?

I just watched Joshua Block’s talk Effective Java – Still Effective After All These Years. I’m not a Java developeri but I still found the talk very interesting. Mr Block offers tips and tricks to deal effectively with a few aspects of Java, and I’m sure many a Java developer out there would find that part very interesting. For me however, the most interesting part was the appetizers and the dessert :-)

The appetizer and dessert consisted of three puzzlers. A puzzler is a piece of code that high-lights some peculiarity of the language or standard libraries. The puzzlers in this talk were are follows:

Simple question

What is printed by the following code, and why?

public class SimpleQuestion {
  static boolean yesOrNo(String s) {
    s = s.toLowerCase();
    if(s.equals("yes") || s.equals("t") || s.equals("y"))
      s = "true";
    return Boolean.getBoolean(s);
  }
 
  public static void main(String[] args) {
    System.out.println(yesOrNo("true") + " " + yesOrNo("YeS"));
  }
}

Searching

What is the result of the following code, and why?

import java.util.*;
 
public class Searching {
  public static void main(String[] args) {
    String[] strs = { "0", "1", "2", "3", "4", "5" };
 
    // Translate string array into list of integer
    List<Integer> ints = new ArrayList<Integer>();
    for(String s : strs)
      ints.add(Integer.valueOf(s));
 
    System.out.println(Collections.binarySearch(ints, 1, cmp));
  }
 
  static Comparator<Integer> cmp = new Comparator<Integer>() {
    public int compare(Integer i, Integer j) {
      return i < j ? -1 : (i == j ? 0 : 1);
    }
  };
}

PrintWords

This one consists of two classes, which are compiled together:

public class PrintWords {
  public static void main(String[] args) {
    System.out.println(Words.FIRST + " " + Words.SECOND + " " + Words.THIRD);
  }
}
public class Words {
  public static final String FIRST = "the";
  public static final String SECOND = null;
  public static final String THIRD = "set";
}

Now modify the latter like this:

public class Words {
  public static final String FIRST = "physics";
  public static final String SECOND = "chemistry";
  public static final String THIRD = "biology";
}

Compile the second version of Words.java alone and then run PrintWords, what is the result and why?

Any puzzlers for Haskell?

Of course I couldn’t help but wonder what puzzlers there are for Haskell. Do note though that puzzlers aren’t just obfuscated code; they are readable code that you think does one thing but in reality it does something else. I’d really like to read any Haskell puzzlers you can come up with. Post them on your own blogs, or as comments to this post.

NB I should probably mention that I really don’t want answers to the puzzlers. I’ve watched Josh Bloch’s presentation, and I think anyone interested in finding out should watch it for themselves.

  1. If I ever find myself in a situation that calls for Java I’m very likely to spend some time looking at Scala :-) [back]

Modifying Twitter Tools (WordPress plugin) for use with identi.ca

This is almost silly, so I’ll be surprised if it works flawlessly, so far though it seems to work well enough. :-)

I got Twitter Tools to work with identi.ca by modifying the file twitter-tools.php so that the URIs used are:

define('AKTT_API_POST_STATUS', 'http://identi.ca/api/statuses/update.json');
define('AKTT_API_USER_TIMELINE', 'http://identi.ca/api/statuses/user_timeline.json');
define('AKTT_API_STATUS_SHOW', 'http://identi.ca/api/statuses/show/###ID###.json');
define('AKTT_PROFILE_URL', 'http://identi.ca/api/###USERNAME###');
define('AKTT_STATUS_URL', 'http://identi.ca/api/###USERNAME###/statuses/###STATUS###');
define('AKTT_HASHTAG_URL', 'http://search.identi.ca/api/search.json?q=###HASHTAG###');

Hopefully this is all that’s needed :-)

Validating names in SSL certificates using OpenSSL (0.9.8)

Recently I’ve battled with OpenSSL at work. One thing I needed to do was add name validation to a program that previously hasn’t had it. In an attempt to avoid obvious mistakes I went looking for existing examples for how to do it. I came across some code from Secure Programming.com, it can be found in the code from the book in “/spc-1.1/chapter10/8-unix.c”. Just too bad only a part of the code actually works as advertised. On top of that the working part uses old functions which remain in the API only for backwards compatibility.

In trying to fix up that code I wrote the following little example code for extracting CN and subjectAltName:

#include <stdlib.h>
#include <stdio.h>
 
#include <openssl/pem.h>
#include <openssl/x509v3.h>
 
void getCN( X509 * );
void getSubjectAltName( X509 * );
 
int
main( int argc, char **argv )
{
    FILE *fpem;
    X509 *cert;
 
    if( !( fpem = fopen( argv[1], "r" ))) {
        fprintf( stderr, "Couldn't open the PEM file: %s\n", argv[1] );
        return( EXIT_FAILURE );
    }
 
    if( !( cert = PEM_read_X509( fpem, NULL, NULL, NULL ))) {
        fclose( fpem );
        fprintf( stderr, "Failed to read the PEM file: %s\n", argv[1] );
        return( EXIT_FAILURE );
    }
 
    getCN( cert );
    getSubjectAltName( cert );
 
    fclose( fpem );
    return( EXIT_SUCCESS );
}
 
void
getCN( X509 *cert )
{
    printf( "## %s\n", __PRETTY_FUNCTION__ );
 
    X509_NAME *subjName;
    int idx;
 
    if( !( subjName = X509_get_subject_name( cert )))
        fprintf( stderr, "X509_get_subject_name failed" );
 
    idx = X509_NAME_get_index_by_NID( subjName, NID_commonName, -1 );
    X509_NAME_ENTRY *entry = X509_NAME_get_entry( subjName, idx );
    ASN1_STRING *entryData = X509_NAME_ENTRY_get_data( entry );
    unsigned char *utf8;
    int length = ASN1_STRING_to_UTF8( &utf8, entryData );
    printf( "CN value: %s\n", utf8 );
    printf( "CN length: %d\n", length );
    OPENSSL_free( utf8 );
 
    return;
}
 
void getSubjectAltName( X509 *cert )
{
    printf( "## %s\n", __PRETTY_FUNCTION__ );
 
    GENERAL_NAMES *sANs;
 
    if( !( sANs = X509_get_ext_d2i( cert, NID_subject_alt_name, 0, 0 ))) {
        printf( "No subjectAltName extension\n" );
        return;
    }
 
    int i, numAN = sk_GENERAL_NAME_num( sANs );
    printf( "subjectAltName entries: %d\n", numAN );
    for( i = 0; i < numAN; ++i ) {
        GENERAL_NAME *sAN = sk_GENERAL_NAME_value( sANs, i );
        // we only care about DNS entries
        if( GEN_DNS == sAN->type ) {
            unsigned char *dns;
            ASN1_STRING_to_UTF8( &dns, sAN->d.dNSName );
            printf( "subjectAltName DNS: %s\n", dns );
            OPENSSL_free( dns );
        }
    }
 
    return;
}

Based on this I should be able to finish the patch I’ve been working on.

My new browser setup at work

I am very keen on keeping my private and work information separate. E.g. I would never read my personal and work email in the same MUA, instead I read work email in Thunderbird and the few times I read private email during working hours I do that using the web interface to GMail. At home it’s the other way around, Thunderbird for personal email, and a web interface to read work email. I used to have a similar setup for my browsing to keep bookmarks and saved passwords for the different areas of my life separate. Firefox was my work browser and Epiphany was my personal browser.

With the recent move to use webkit I noticed that there are a few bits with Epiphany that really bugs me though. Especially its inability to remember passwords; on my Eee it’s just a killer to not be able to do that. So, I decided to take a look at Firefox again, especially to see whether there are any add-ons that would help. And there are. These are the add-ons I found useful for this:

Profile Manager and Synchronizer

The most important piece of the setup is the addon Profile Manager and Synchronizer. It make sit easy to have more than one instance of Firefox running at the same time, with different profiles active in each one.

At first I tried synchronising profiles via dropbox, but that resulted in a lot of updates each time so I quickly stopped. I can recommend using it once though, to get the profiles to all the computers in the first place.

The plugin author says there will be a version that works with 3.6 soon. In the meantime I can report that I’ve had no issues with manually modifying the version range just to get it to install.

Xmarks

Since I don’t synchronise my profiles I do need to synchronise my bookmarks, and for that I use Xmarks.

Diigo

Diigo is a social bookmarking site. There seems to be about 13 to a dozen of those, but there are a couple of things that make Diigo different.

With the plugin I can easily store away pages for reading at some later date. In the past I’ve had a bookmark folder, or slightly more recently a tag, that I used to mark up pages that I’d like to take a closer look at. I’ve stopped that completely, and now I just mark pages as unread in Diigo. Just another way of reducing the clutter among my bookmarks.

The probably coolest feature is commenting on webpages. I mostly use that to add private comments to web pages, e.g. when I do some research into some topic (so far it’s mostly been for items I’m considering buying), but it’s also possible to make public comments. I’ve found it useful on more than one occasion to have a quick look through the public comments other people have put on pages.