msgbartop
A site for my programming pet projects
msgbarbottom

16 Dec 09 Module initializers in C#

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…)

20 Nov 09 Easy way to have custom icons in Visual Studio AddIn

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.

(more…)

12 Nov 09 ZenCoding Visual Studio AddIn

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

DOWNLOAD ADD-IN || DOWNLOAD SOURCE

(more…)

23 Jul 09 Chord Image Generator

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…)

20 Jul 09 ZenPhoto Uploader

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…)

20 Jun 09 Instant Rimshot

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#.

(more…)

20 Mar 09 Coco/R plugin for Visual Studio

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…)

29 Jan 09 Coco/R for Boo

I’m currently doing my masters thesis, and as part of it I needed to implement a simple compiler for the .NET runtime, the CLR. I just recently started playing around with the Boo language, which is a statically typed .NET language with very similar syntax to Python and many of its features, while still being statically typed and offering some nice extra features such as regular expression literals and string interpolation. I wanted to try the language out on a small project so I decided to use it to write my little compiler. The only problem was that as far as I could tell there were no available parser generators for Boo. (There might well be some, I must admit I didn’t really look very hard). The only parser generator I’m used to using is Coco/R, which is nice and simple to use, and available for many languages, although not for Boo. It is however available for C# so I decided to modify it myself to make it output Boo code.

(more…)

06 Nov 08 Extensionless urls in ASP.NET MVC on IIS 6

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…)

15 Jan 08 Developing ASP.NET 1.1 in Visual Studio 2008

I have an old ASP.NET 1.1 application that I have to maintain and which for reasons beyond my control can’t be updated to a later .net version. I hadn’t touched it in a few months but recently I had to make some small changes and realized I didn’t even have Visual Studio 2003 anymore. I got a new computer a few months ago and I have Visual Studio 2008 and IIS 7 on it but no VS 2003. I didn’t really want to install it, it’s pretty old at this point and not very well supported in Vista, and like most programmers I like to play with the shiny new toys, not the old obsolete ones. So I decided to try to maintain this application in Visual Studio 2008. Now, VS 2008 can target different versions of the .NET framework, but only 2.0, 3.0 and 3.5 so I was out of luck. But, thanks to a nice article I found by Jomo Fisher on compiling .NET 1.1 in VS2005 and some extra hacking I got it working pretty well. My setup was IIS 7 on Windows Vista, IIS 6 on Windows XP is pretty much the same although some of the options I point to may be located in different places. So, here’s what you need to do to develop ASP.NET 1.1 in Visual Studio 2008:
(more…)