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…)
I’ve recently been developing a Visual Studio AddIn and I wanted to use custom icons for a command I had. Looking for a solution I found the offical MSDN article on the subject, that might possibly be the most misleading and useless article ever. Add the resource file in Visual Studio, then exclude from project, rename your images to numbers, edit with Notepad and then build satellite assemblies on the commandline? Really? That is a horrible way to do it and not at all necessary. I’ve found a very simple and easy way to add these icons without all that hassle.
4 Feb 2010: I’m no longer working on this addin and cannot provide support for failed installations. I gave some information about possible causes for failed installations in this comment, you can see if that helps, or discuss with other users in the comments. There are unlikely to ever be new versions of this addin published by me, but Boris Sevo has forked the project and has a version with a newer zencoding library at http://zencoding.codeplex.com/. So go there for updates
The original blog post about the architecture of the addin is now completely out of date as 90% of the addin is now written in IronPython with just a tiny shim layer of C# to instantiate the IronPython classes. I’ll probably write a blog post about that architecture seperately (or generally about how to write addins for VS in IronPython). Those interested in the architecture can download the source and look at it.
A nice tutorial with screenshots on how to setup the keyboard mappings and use the addin has just been posted at http://www.netsi.dk/wordpress/index.php/2009/12/02/zen-coding-a-very-fast-way-of-generating-html-elements-in-your-editor/ so go there for your setup instructions. And there is now a dedicated rss feed for updates at http://tech.einaregilsson.com/zcupdates.aspx so subscribe to that to be notified of new versions. Eventually I’ll put an update check in the addin itself.
ZenCoding.VisualStudio v1.1.0.333
Recently I got a request in the mail from a user of one of my Firefox add-ons. He asked me if I could make an add-on that displayed the url of the current tab in the titlebar instead of the actual title of the page being shown. I’m not interested in creating more add-ons for Firefox or Thunderbird, they take up quite a lot of time with user requests, getting approved by the Mozilla addons site, etc. That is why I’ve discontinued 6 out of the 9 add-ons I’ve created. But anyway, I knew that it would be trivial to make this add-on so I decided to help this person out. (more…)
One of my non-programming related hobbies is playing guitar. I’ve used a lot of chord sheets and tablature from the internet and have often wanted to be able to print it out in a nicer format than plain ASCII. Chord definitions in online tablatures are usually written something like (xx0232) (a D chord), but I wanted to be able to get these nice chord diagrams like they have in the guitar magazines. So, I wrote my own little online chord image generator.
(more…)
The photo album software I use to store my photos on the web is ZenPhoto. It is a very nice photo gallery system, with themes, lots of plugins, nice administrative interface and plenty of other good stuff. The only problem I had with it was getting my photos uploaded. Sure, they offer a web interface, or you can upload a zip file, or use FTP but I usually need to preprocess my photos a bit. Rotate them, throw out the ones I don’t want to upload, and most of all I need to make them smaller, uploading them in the size I use on my camera takes forever. So, I decided to make a simple program to do these things for me.
(more…)
It’s been a while since I’ve written anything here, I’ve been working on my master project like crazy, have a 6 month old baby and so haven’t had much time for programming pet projects. Tonight I spent a half hour making perhaps the most useless application I’ll ever make. It’s based on the single-serving website http://instantrimshot.com which only has one huge red button, if you press it a rimshot sound is played. I thought it might be fun to have that available as a keyboard shortcut in windows, and then I started wondering how it could be done in C#.
I’ve blogged before about the excellent Coco/R parser generator. I’m using it a lot in my masters project and I’m happy with it but there were a few things I wished worked differently. The main thing was that I wanted better Visual Studio integration. I had set up a pre-build event that generated the parser and scanner before every build. However there is obviously no need to re-generate the files unless the grammar file has changed. Generating on every build also had the effect that Visual Studio kept prompting me about reloading changed files and I had to build to see if there were any errors in my grammar. So, I decided to create a Visual Studio plugin for Coco/R myself. (more…)
Lately I have been doing some COM automation stuff on Windows. I’ve been using JScript (Microsoft’s JavaScript implementation) since that’s available on all Windows machines, and the other option, VBScript, is horrible. Normally I would use Python and the win32com package, but I needed to make some scripts that could work on any box without installing Python first. JScript is a pretty nice language, but it doesn’t come with a REPL built in, which is very handy when you’re doing experimental stuff (REPL = Read-Execute-Print-Loop). Now, writing your own REPL in a dynamic language with an eval statement is pretty easy, so I did just that. It took about 30 lines, of which about 10 are just about printing evaluated expressions nicely. (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.