Archive for August 2010

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]