Archive for November 2006

Darcs over sshfs

A while ago I found out that darcs doesn’t work over sshfs out of the box. Of course there was a workaround. Yesterday I was at it again, and this time it was sshfs that gave me grief. After another echange of emails I found a solution.

At the moment this is what’s necessary:

% sshfs -oworkaround=rename <remote path> <local path>
% export DARCS_SLOPPY_LOCKS=1
% darcs put <local path>/<repo name>

My Google Reader share

I’ve been using Google Reader to read RSS feeds for a while now. I’m trying to share the stuff I like, the page is here and the feed is here. I’m guessing it’ll turn out to be a superset of the posts I’m commenting on in my blog.

Listing files in Haskell

As I promised earlier here’s a post on my playing with files and directories in Haskell. This was a few days ago so I’ve forgotten a few of the twists and turns that took me to the goal. Forgive me for that.

First, my goal was to list all files below a directory, recursively. I was sort of hoping to find something similar to Python’s os.walk(). No such luck!

I found out a few things.

  1. getDirectoryContents returns everything in a directory, including . and ... I needed a filter to remove them:

    isDODD f = not $ (endswith "/." f) || (endswith "/.." f)
    

    (At first I called it isDotOrDotDot but I like isDODD better.)

  2. I also needed to separate out the directories and files from the result of getDirectoryContents:

    listDirs = filterM doesDirectoryExist
    listFiles = filterM doesFileExist
    
  3. getDirectoryContents returns a list of the contents in the directory you point it to. All file names/directory names are relative to that path. That means the next thing I needed was to join paths. I first couldn’t believe that there wasn’t a function to do that. I mean, I can list contents of a directory, I can find out if something’s a file or a directory, but the most basic manipulation of paths isn’t there. At first I simply concatenated strings, but I didn’t worry about making it cross platform or anything. Then I found that Cabal comes with libraries that handles cross-platform issues properly, but that library was “closed”. After moaning asking on haskell-cafe I found FilePath. It’s even packaged for Debian here.

    FilePath.joinPath takes a list of strings to join, while I was only interested in joining two strings at a time:

    joinFN p1 p2 = joinPath [p1, p2]
    

Putting it all together I ended up with the following:

listFilesR :: FilePath -> IO [FilePath]
listFilesR path = let
    isDODD :: String -> Bool
    isDODD f = not $ (endswith “/.” f) || (endswith “/..” f)

    listDirs :: [FilePath] -> IO [FilePath]
    listDirs = filterM doesDirectoryExist

    listFiles :: [FilePath] -> IO [FilePath]
    listFiles = filterM doesFileExist

    joinFN :: String -> String -> FilePath
    joinFN p1 p2 = joinPath [p1, p2]

    in do
        allfiles <- getDirectoryContents path
        no_dots <- filterM (return . isDODD) (map (joinFN path) allfiles)
        dirs <- listDirs no_dots
        subdirfiles <- (mapM listFilesR dirs >>= return . concat)
        files <- listFiles no_dots
        return $ files ++ subdirfiles

Links and stuff (24/11/2006)

I realised I hadn’t put in one of these posts in a while. The level in my “To Blog” bookmark tag was dangerously high… here we go!

I really enjoy this, rather old article on superstitions in relation to computers. I never bothered counting my superstitions on Windows, but given that I’ve given up on understanding Microsoft’s products I suspect they run in the thousands.

Every developer needs Cenqua’s Commentator. I’m getting it as soon as I’ve saved the money. It’ll be the first piece of software that I pay for myself in years. Worth every penny though.

libgfshare. Please, go off and write some cool software using it. Please! If I were a FirefoxIceWeasel user I would use the Python sidebar. It looks so useful I might look into creating one for epiphany. If you’re considering doing something cool with PDF docs, have a look at extendedPDF. I think I’ve mentioned Rob Bradford’s GConf difftool in another post, or maybe not. Anyway, I’m hoping that’s the first step towards a tool that lets you export GConf settings between machines. Are you a Python web developer, Python Paste is yet another framework.

If you still believe that “do no evil” is enough then you won’t be interested in Google Watch. I however thing they should upgrade their slogan to “do good”, so I am interested.

I found the following post funny, but I’m probably the only one. Havoc doesn’t understand why distributed VCS is better then Subversion. I suppose that’s what happens when you are a famous FLOSS person that immediately gain submit access to any project one shows an interest in. For the rest of us; thank goodness for distributed VCS.

Old news, but Firefly fans are bloody brilliant.

More old news, I don’t really see why I should worry about “identity theft” from someone rummaging through the rubbish in my wheely bins while the UK banks are so careless with client information.

With great power comes great responsibility. It’s sad when language designers don’t believe the developers deserve the responsibility. Here’s a post on the difference in attitude between C# and Python when it comes to empowering the developer.

I had fun reading about the evolution of a Haskell programmer, even though I didn’t understand all the code.

Well, I actually do believe in the cheerleader defense for wireless networks. Anyone who has looked at software security knows that plausable deniability is much easier to achieve than locking down a system. IANAL but I still believe in the phrase “beyond reasonable doubt”.

Now, I wasn’t planning on running Vista on any of my private machines. After reading this, rather long, article on Vista’s EULA I’m absolutely certain of that. I’m almost thinking Microsoft is taking a piss out of their users. However, evidence is mounting that they aren’t. I can’t help but wonder how their “de-activation” will hold up in legal systems outside of the US. I also wonder how much further this distrust-your-user craziness in EULAs can be taken before users start reacting negatively.

Firefox vulnerability, not on Debian?

I received a note about the new Firefox vulnerability yesterday. I ran the proof-of-concept on my Debian machine, using first Epiphany and then Iceweasel. Didn’t work on either. Then I fired up a VMWare image running Windows, with a stock Firefox from mozilla. The proof-of-concept worked just as advertised. So, are the reports missing something (not exploitable on all OSs), or am I just lucky that Debian decided to move to Iceweasel?

hpodder going multi-threaded

This is great news! I can’t wait.

I also love the additions to MissingH, hopefully they’ll make it into Debian soon.

Controlling moguls…

I wonder how difficult it’d be to find out if I am, through some levels of indirection, a stockholder in any MPAA/RIAA/BPI company. Then at least there’d be a chance to exert some control over the madness that’s going on in the board rooms of those companies.

Fun with Haskell

What better way is there to spend a Saturday than playing with Haskell? I sure don’t know :-)

I do have a goal in mind, but for now I’m mostly fooling around with some file-related stuff.

First, I wanted to wanted to load an entire file and print it on stdout. Basically a primitive cat. I came up with the following main:

main = liftM (!! 0) getArgs >>= catFile >>= mapM_ putStrLn

As you can see I did spend some time thinking about Monads lately. Something that’s especially pressing if one wants to do IO in Haskell since the IO Monad can’t be escaped from. Next catFile (which based on the use above should have the type FilePath -> IO [String]). I did some experimenting and searching in Hoogle among the System.IO functions. I found openFile, hGetContents that would let me open and read the file. I played a bit with that:

catFile fname = do
    hf <- openFile fname ReadMode
    conts <- hGetContents hf
    hClose hf
    return conts

That doesn’t have quite the required type, but that isn’t the only problem. The combination of hGetContents and hClose doesn’t quite work—the file is never read (laziness in action!). I removed the hClose (since the process isn’t very long-lived that doesn’t bother me so much) and I added a lines:

catFile fname = do
    hf <- openFile fname ReadMode
    conts <- hGetContents hf
    return $ lines conts

Then I stumbled on readFile and rewrote it as

catFile fname = do
    content <- readFile fname
    return $ lines content

which can be written even shorter as

catFile fname = readFile fname >>= return . lines

I guess it’s time to explain the reason for returning IO [String] rather than IO String. The latter would have simplified both catFile and main. What I really wanted was to make each line of a file an item in a set. My first thought was to fold it:

catFile "test_file" >>= (\l -> return $ foldr Set.insert Set.empty l)

Which can be re-written in point-free style (I hope I’ve gotten point-free right here):

catFile "test_file" >>= return . foldr Set.insert Set.empty

Then I decided to look into Data.Set and found fromList. My first naïve attempt and my point-free:

catFile "test_file" >>= (\l -> return $ Set.fromList l)
catFile "test_file" >>= return . Set.fromList

Then I reversed my thinking and tried to lift the function into the monad instead:

liftM Set.fromList $ catFile "test_file"

At that point I felt I had somewhat exhausted this particular little playground and went on to listing files and directories, but that’s a story for another post.

LugRadio, s4e5

Well, since it seems some of the hosts of LugRadio don’t have the time to read emails in their entirety on the show while at the same time lacking the ability to properly read email and present the gist of it in fewer wordsi I’m posting the latest email I sent them.

We don’t need proprietary media codecs on the Linux desktop. Just wait and Microsoft will in fact do all the work for us. Their current death march into DRM land, while holding TPM and NGSCB by their hands, can only end in one way–consumer revolt. As I see it one of two things will happen, either the computer will lose its status as a media-playing device and go back to being a semi-functional time-wasting device, or it will start making economic sense to Hollywood to stop trying to hang themselves by the neck. In clearer terms, Microsoft will either make sure its so cumbersome to watch a DVD on Windows, or consumer will stop buying content because they can’t do what they want with it. If the former happens then the reason for watching media on Linux goes away alltogether, if it’s the latter then a well-timed push for Free Software (and possible patent reform) will make it possible to develop a truly Free desktop where you can watch your DVDs legally. Either way, Linux prevails.

Aq for prime minister of Great Britain and leader of the free world!

  1. It doesn’t mean I’ll stop sending them emails, it just means that in the future I’ll try to be a bit more careful with wording. I can’t expect Aq (Stuart Langridge) to read all my emails, so expressing complicated arguments might also be something I’ll have to avoid.[back]

Epilicious 0.10

I just released version 0.10 of epilicious. Go fetch it from GnomeFiles.

I decided to toss out all the translations from earlier versions (this is purely a reaction to my own inability to deal properly with contributed translations). So, please, download the POT and localise epilicious!