One feature of the CLR that is not available in C# or VB.NET are module initializers (or module constructors). A module initializer is simply a global function which is named .cctor and marked with the attributes SpecialName and RTSpecialName. It is run when a module (each .NET assembly is comprised of one or more modules, typically just one) is loaded for the first time, and is guaranteed to run before any other code in the module runs, before any type initializers, static constructors or any other initialization code. I wanted to use this feature for a project I was doing but was unable to use it directly in C# so I created my own solution. (more…)
My masters project at DTU involves writing compilers for the .NET platform and since I had never written a compiler before I decided to start by writing a compiler for a simple language called While. This language is used in the Program Analysis course that is taught at DTU and has integer and boolean expressions, read and write commands, an if branching statement and a while looping statement. The compiler compiles this language and the programs can be run with the .NET CLR or Mono. The programs can also be debugged using a free graphical .NET debugger. I put the project up on Google Code, I think it is a fairly nice example of a simple compiler for .NET. It is currently written in Boo but will soon be rewritten in C#. The compiler and its source code is available at http://while-language.googlecode.com.
I recently started playing around with ASP.NET MVC to build a small website. I’m pretty impressed, I like working with MVC a lot better than the web forms model. One thing that ASP.NET MVC offers is to have “pretty urls” similar to frameworks like Ruby on Rails or Django, that is, instead of urls that look like http://example.com/index.aspx?car=Ford&year=1990 you get urls like http://example.com/cars/Ford/1990. This works flawlessly in Visual Studio using the development webserver but there can be some complications when deploying to IIS. The new IIS 7 has support for this built in when using integrated mode, however my webhost is still on IIS 6 and there are problems there. Essentially there are two ways that can be used with IIS 6. The first way is to map all requests to the ASP.NET engine, even ones for images, css etc. That works but has some performance implications. The other way is to use a file extension in all urls, so our example url might have to be something like http://example.com/cars.aspx/Ford/1990/. That’s not horrible but not the way I want it either. So, I came up with another way. (more…)
For those that just want to play the game already, go here to play it
The last few weeks my hobby project has been creating a cardgame in Javascript. I’ve always wanted to create a cardgame and I decided to use simple Javascript so I could make it available online since no-one wants to bother to download small games. I figured there were thousands of blackjacks and solitaires out there so I decided to create my favorite cardgame, Idiot. (more…)
I was watching a movie on my computer the other day and I had gotten the subtitles for it off the internet, I think from http://opensubtitles.com or something like that. The only problem was that they were a bit out of sync with the picture, about 2 seconds too late. Using a good media player, such as VLC you can add an offset to the subtitles every time you watch the movie but I figured I could probably whip up a small script to do it for me so I could just do it once and then have the subtitles correct every time I watched the movie. (more…)
Recently I had a school project where we needed to parse a certain grammar into a syntax tree and do some analysis on the code. Everytime I’ve had to work with trees (which has only been for school projects actually) I’ve been frustrated because it can be hard to visualize the tree, especially when it starts getting large. I’ve pretty much done two things in that situation, either draw the tree on a piece of paper, which takes a lot of time and is very boring, or try to look through the structure in the debugger, which gives you some idea but is not really very convenient. So, when I was working on this new project I figured I could probably come up with some simple way of displaying the tree while I was working on it. I wanted the solution to be re-usable so I could pull it out again the next time I have to work with binary trees without having to change it to match the new project. So, here’s what I came up with.
(more…)
Visual Studio and the .NET framework make it really easy to create Windows Services. All you have to do is create a new project, select ‘Windows Service’ as your project type and you’re all set. However, debugging Windows Services in Visual Studio can be a big pain. The recommended way is to use InstallUtil to install them, and then restart the service and attach the debugger everytime you want to debug it. I wanted Windows Live! Bot to be available as a Windows Service, but I also wanted to be able to debug it without the hassle, so here’s what I came up with: (more…)
A few weeks ago I was helping my sister change her blog. She has a Blogger account but uses Haloscan for comments, since when she started blogging Blogger didn’t offer comments as a part of their service. That has changed now, so I thought it would be much more convenient to have the comments and blog all at the same place. I just needed a way to export her Haloscan comments and import them into Blogger. So I wrote a small Python script to do the exporting for me. (more…)
Updated 05.09.2007: Minor changes to work with the new MSN protocol
My wife showed me a website the other day where you could type in your email address and password for MSN Windows Live! Messenger, and it would show you which of your contacts didn’t have you in their contact lists, either because they’d never added you, or because they’d deleted you at some point. It’s a cool idea and a good way to prune some of the contacts that you never speak to from your contact list. But I don’t really wanna give up my user / pass to some third-party site, even though they promise not to log it anywhere, and most of these sites (at least the ones I saw) tried to make some money by sending advertisements to your contacts while they were checking them, which I definitely didn’t want. So, since I already have a project that uses the MSN protocol I figured I could probably whip something up myself. (more…)
In a previous post I talked about how to integrate ZenPhoto into Wordpress. After I had done that for my own site I still wasn’t happy. I didn’t like the fact that I had to use seperate logins for Wordpress and ZenPhoto, I wanted this to be as integrated as possible. So I figured out a way to make ZenPhoto ask Wordpress for authentication credentials. In other words, if you’re logged into Wordpress, you’re also logged into ZenPhoto. This makes the user/password in the ZenPhoto config file meaningless. Here’s what you have to do to get this working: (more…)