Home Contact

Matt Roberts

Rails and .NET

News




Twitter












Archives

Post Categories

BlogRoll

Entropy

Syndication:

Apps for Macs

I own a mac, I'm a fan of macs, but I'm not a mac-fanboy. I think they're bloody great machines, and that OSX is by far the best OS out there, but I appreciate they're not for everyone. Even osx has (cue dramatic pause) .. flaws. Copy a folder somewhere in OSX, and if the folder already exists on the destination it will prompt you to entirely replace that folder - WOT NO MERGE?! Anyway, apart from that minor niggle, OSX is awesome, especially for web development (in rails).

So where am I going with this? Recently a colleague at work has also taken the mac plunge and joined the collective, and so I thought it would be good for me to list the top (free) tools and applications that I couldn't live without on the mac. So, here they are:-

1) Firefox 3 and Safari 4
http://www.apple.com/safari/
http://www.mozilla.com/en-US/
I can't decide between these, so I use both. Firefox rules for its extensions, while Safari is very fast and slick.
 
2) Adium
http://adium.im/
Adium is a very nice IM client for the mac. Its light, simple, free of crappy adverts and other such bilge, and best of all, its a green duck. Nuff said.

3) iStat Menus
http://www.islayer.com/apps/istatmenus/
This is a really good system monitoring tool, that sits un-obtrusively in the apple menu, um, thing. Its seriously useful and very configurable, and gives me a reasuring insight into whats happening in the mac

4) Google notifier for mac
http://toolbar.google.com/gmail-helper/notifier_mac.html
Its a mail / calendar notifier for the mac. From google. Nice.

5) Quicksilver
http://thenextweb.com/2009/05/04/quicksilver-mac-greatest-app-time/
Ah, the swiss army knife of the mac world. This tool rocks. The blog above is a great write up on Quicksilver, and how to use it.

6) VLC
http://www.videolan.org/vlc/
Quicktime player is OK, pretty good for .MOV files, but well not that good for other formats. VLC on the other hand is one of those "just works" apps. it plays videos of most formats. It plays them well, and rarely complains. Nice.

7) Tweetie
http://www.atebits.com/tweetie-mac/
My mac twitter client of choice. Its a shame is ad-supported, but it really is a nice client, does everything I need, and has a good clean UI.

8) Growl.
http://growl.info/
I can't believe growl isn't actually built into OSX. Its a simple un-obtrusive notification system, that I first heard of when doing automated testing in rails. Turns out a lot of apps support growl notifications. Or maybe growl is just hooking into some central osx notifcation event broker. I dunno, but its very nice, and must be installed.

9) TextMate (or MacVim)
http://macromates.com/
Damn it. This one isn't free. But, its very cheap, and for your money you get a very very nice text editor. If you know about rails, you already know about this. If you don't want to pay, I also recommend macvim (http://code.google.com/p/macvim/). Its a mac port of VIM, done very nicely, and VIM is very nice, as long as you're prepared to master it. And theres some good rails stuff out there for VIM (http://www.akitaonrails.com/2009/1/4/rails-on-vim-in-english)

10) Transmission
http://www.transmissionbt.com/
I used this bittorrent client while I was waiting for uTorrent to be available for the mac. I liked it so much I stayed with it. Its simple, effective, pretty much does what it says on the tin.

Thats it :) By sheer co-incidence it came to 10 applications. I hope you find this list at least marginally useful, and i

Get Database rollback powers in your NUnit Tests!

Ok - no credit to me for any of this good stuff. All I'm doing here is posting on how to get database rollback working in your Nunit tests.

Roy Osherove created something called XtUnit - "An Unofficial Unit Testing Extensibility Framework - Add new attributes to NUnit or MbUnit easily" - http://weblogs.asp.net/rosherove/archive/2004/10/05/238201.aspx

His blog talks you through all the cool stuff that you can do with this framework, like implementing your own attributes to do cool things pre and post method execution. But the thing I wanted more than anything was to add rollback powers to existing NUNit tests, I didn't want to switch to MbUnit to do this, I just wanted to be able to do it with my existing tests.

It was pretty simple to get working, but the documentation is a tiny bit in-complete, so this is what you need to do.

I'm in Visual Studio 2008, using LLBLGenPro to talk to the database (obviously you don't need to use LLBLGen Pro, but why the hell not!)

  1. Download the binaries. You could download the source but you'll need to migrate it to 2008, and I didn't need the src.
  2. Reference the binary file that is downloaded in your test project.
  3. Make sure that your test fixture class derives from ExtensibleFixture
  4. Add the DataRollBack attribute to your test method

Done!

Here's the code for completion. My example as basically adding a row to a table called "GlobalSearch", in case the LLBLGen stuff looks confusing to you.

   1: [TestFixture]
   2: public class Class1 : ExtensibleFixture
   3: {
   4:     [Test, DataRollBack]
   5:     public void TestDataRollBack()
   6:     {
   7:         var adapter = new DataAccessAdapter("connection string here", false, CatalogNameUsage.ForceName, "");
   8:         // Create a new GlobalSearchEntity, save it, then rollback
   9:         var g = new GlobalSearchQueueEntity();
  10:         g.RecordId = 100;
  11:         g.ToolCode = "TOOLCODE";
  12:         adapter.SaveEntity(g);
  13:     }
  14: }

How to make a "protected" method available for "partial" mocking using RhinoMocks

There are 2 cool things I want to share here...

Partial Mocking

This is a very cool and useful feature of RhinoMocks, which allows you to test part of a class, but have some of it act normally. Its explained very well here: http://ayende.com/Wiki/(S(gvtu2q45soph42vfyhig2j55))/Rhino+Mocks+Partial+Mocks.ashx

Making "protected" methods available for mocking.

Partial mocks are great, but what do you do when you need to "mock" out a method that isn't visible to your test class - i.e. its private or protected. Well, it turns out you can use a nifty little attribute called InternalsVisibleTo to make any internal methods visible to other assemblies (i.e. your testing assembly). So, in my code, I had a method called GetRecord, which was protected. I changed this to make it protected internal virtual, and added this to my AssemblyInfo.cs file:

   1: [assembly: InternalsVisibleTo("NUnitTests")] 
   2: [assembly: InternalsVisibleTo(RhinoMocks.NormalName)] 
   3: [assembly: InternalsVisibleTo(RhinoMocks.StrongName)] 

NUnitTests is the name of my assembly that contains the tests for my project. Once this is done and compiled, intellisense lets me mock that protected method. Just for completeness, here is the code that sets up my partial mock:

   1: var mocks = new MockRepository(); 
   2: var globalSearchServiceBase = mocks.PartialMock<ClassToMock>(); 
   3: Expect.Call(globalSearchServiceBase.GetRecord(1)).IgnoreArguments().Return(GetFakeData()); 
   4: mocks.ReplayAll(); 

Thats it. Hope that was at least marginally useful to someone :)


CouchDB (with rails)

I've been playing with CouchDB a little recently. Its a "schema-free document-oriented database", which sounds pretty weird when all you've ever known is relational databases. At work, we're considering what architecture we want to go with for a new product that needs to be very flexible - the users need to be able to add fields, remove fields, and do all sorts of crazy things with the application.

One of the options we have, is to use something like CouchDB to be able to create an uber-flexible database that can evolve over time, and be very scalable. because our new product will be a SaaS one. Its pretty clear to see why CouchDB fits the bill.

Anyway, its pretty cool, and I wanted to see if I could get started creating a little application in Rails using CouchDB on the back end... It was pretty slow going until I came across this fantastic PeepCode Screencast This screencast goes through the basics of CouchDB, and then goes on to build a nifty notes-esque web application using a CouchDB gem called CouchRest.

Its a quality peepcode, and the CouchRest gem looks like its really going to help me :)

It'll be interesting to see what kind of take up CouchDB or other schema-free cloud computing databases get in the .NET world, I don't see much happening out there at the moment.

Anyway, watch out for my killer CouchDB-based rails application, coming soon (yeah right!)

Get your (old) COM-based or "ASP.NET with Interop" web app working in Windows Server 2003 R2 64 Bit !

AKA: "Why am I getting 'ActiveX can't create component' when I try to access my COM DLL's"
AKA: "Why am I getting 'Service Unavailable' when I've set IIS to run in 32 bit compatibility mode.
AKA "Why do I get 404 errors when I browse to my ASPX pages"

Man that's a long title :)

So, I recently had to spend some time looking into getting my companies web application working in 64 Bit Windows (2003 R2 to be exact). I eventually got this working, but found the information scattered and incomplete on the interweb, so this little guide should see you through. I hope someone out there finds it useful.

Starting Point.

You have windows 2003 R2 64 bit SP1. You have the 64bit version of the .NET framework (V2 or higher) installed. No other changes have been made to IIS - it seems to run just fine for serving .NET and HTML. You install your web application that includes COM, try to run it, and BANG...

Microsoft VBScript runtime error '800a01ad'
ActiveX component can't create object

The cause? Its because those COM objects are 32 bit components, and by default IIS won't work with 32 components. You need to tell IIS to run in 32 bit compatibility mode (WOW64). To do this, you need to configure IIS to run in 32 bit compatibility mode, as explained by this link.

But wait! Its not quite that easy! If you do this, then you're telling IIS to run in 32 bit mode, but then you've already got the 64 bit ASP.NET DLL's registered with IIS, so the first time you hit your app, you'll probably see a big fat "Service Unavailable" Error message. If you look in the event log, you'll see your application pools are crashing with this error:

A process serving application pool 'DefaultAppPool' reported a failure.
The process id was '4156'. The data field contains the error number.

So, you need to register the 32 bit ASP.NET DLL's with IIS. But wait! You can't do that before you un-register the existing 64 bit ones.

Enough waffling. Here's the step-by-step :-

  1. Un-register the 64 bit ASP.NET DLL's. In a command prompt, navigate to C:\Windows\Framework64\v2.0.50727\ and from there run "aspnet_regiis -u"
  2. Set IIS to work in 32 bit compatibility (WOW64) mode:
    cscript c:\inetpub\AdminScripts\adsutil.vbs set w3svc/AppPools/Enable32BitAppOnWin64 1
  3. Register the 32-Bit ASP.NET DLL's. Navigate to C:\Windows\Framework\v2.0.50727\ and from there run "aspnet_regiis -i"
  4. Finally, in IIS, Navigate to "Web Service Extensions", and make sure that ASP.NET is "allowed".

You're done!


Categories in Rails

Rails makes such a nice change from coding in .NET. I mean, I do like .NET and C#, but sometimes its very bloated and can be quite cumbersome to do things.

Rails, on the other hand, isn't big. Or cumbersome. In fact, its downright lean and to-the-point, unlike my blog posts (what there are of them!).

Anyway, today we're talking category trees, surely one of the most exciting concepts that there is to talk about. One thing that made me smile recently was the need to list all the categories that a company was tagged to. So, this happens with code that looks like this :-

<%for cat in @Categories %>
    <%= cat.name + "<br>" %>
<% end %>

.. Where @Categories is a collection of categories from the controller, and is generated like this:

@Categories = Company.find(params["id"]).Category.find(:all)

So, this noddy code just lists all cats that the company was tagged to. After deploying this, I was asked to change it so that the full hierarchy of categories was displayed. So instead of "Cat 1", the user wants to see "Root -> Services -> Cat 1". Hmmm, I thought, perhaps I need to write a little recursive method to go and get the parent nodes of each selected category... Turns out that because I was using acts_as_tree in the model (google it!), I was able to solve this with a really simple bit of code added to the category model :-

    def fullcategoryname
        self.ancestors().each() { |parent| fullname += parent.name + " / " }
        fullname += self.name
  end

Thats nice! :) Gotta like Ruby.


COM Interop is OK, but a bit crap..

Our software has been around for a long time. It started life as an ASP application, with all the database logic tucked away in VB6 components, and lots and lots of ASP pages.

Because we invested so much into these VB6 components and also the ASP UI infrastructure, we're still using it today - so we have ASP pages that call VB6 components. Obviously, as we move more and more of the code into .NET, we are relying on Interop more and more to allow us to make use of "new" stuff from existing ASP pages... It was all working well until recently we needed to implement new features that rely on getting data out of the application config file... thats where it all goes bad :(

If you interop from unmanaged code to .NET, .NET will look for an app config that matches the executing process's filename + ".config".

.. which sucks for us. We implemented a cool new permissions checking infrastructure in .NET, and as part of this I wanted to use the SQL Cache Dependency to be able to auto-remove cache data when the underlying data changes. But...SQL Cache dependency relies on configuration data being set in the app config, so when we call through from a VB6 app - it aint gonna work! If called from COM like our .NET code is, the .NET assembly you execute is being executed from the process DLLHOST.exe, which lives in the System32 folder. Therefore the CLR looks for a config file called "DLLHost.Exe.Config" - try pursuading your clients to create that :)
 
This is a real shame and it stops us from using the SQL Cache Dependency stuff and some other things that are configured using the app config. We can get round it for simple settings like the connection strings, because we create our own classes to process the web.config that we actually do want to use, and that works, but for a lot of stuff that relies heavily on config setup, we can't use it... its a bummer!

Test Post from Windows Live Writer

Testing from Windows live writer :)


Ruby ruby ruby ruby! (on rails)

I recently decided to play around a bit with Ruby on Rails, its had so much hype so I thought it would be interesting to see how it fares up against ASP.NET programming!

Anyway, I'm only just starting out, but first impressions are very very good indeed! Ruby seems to be a very intuitive language, although I wouldn't say I preferred it to C#. However, the rails framework that deals with all the agile web framework side of things seems awesome!! Really easy to use and get a reasonably complex web site up and running.

I'm going to waffle on a bit more about this in the future, but in the meantime if you're interested in giving it a go on a windows box, its ridiculously easy - you don't even have to "install" any software!! Just do this:

1) Download "InstantRails". http://instantrails.rubyforge.org/wiki/wiki.pl
From the website: Instant Rails is a one-stop Rails runtime solution containing Ruby, Rails, Apache, and MySQL, all pre-configured and ready to run. No installer, you simply drop it into the directory of your choice and run it. It does not modify your system environment.
2) Get a "development environment setup"
If you're used to being spoilt/abused by Visual Studio and want something all nice and integrated, then you need to get RadRails. RadRails is a free plugin for the excellent-if-sometimes-a-little-too-slow-for-me Eclipse devenv from Sun. It needs the java runtime to work. Anyway, get it from www.radrails.org
Alternatively, use VIM with ruby plugins, or something else :)
3) Follow some tutorials.
Start here....
instantrails.rubyforge.org/tutorial/index.html
Then here....
www.digitalmediaminute.com/article/1816/top-ruby-on-rails-tutorials

You know its going to be a long day when...

Installing the Visual Studio 2005 Service Pack and you get this.....


Happy New Year!

Well, its another new year (did I mention that?) I'm going to make a big attempt to update my blog more often than I did towards the end of last year, that was pitiful to be honest.

So, what better way to start the new year than installing some free software to make your development/computing life that bit easier.... Here's my top 5 list of "Stuff I always install when I rebuild my machine":

  1. Notepad2. Its my fave notepad replacement, with all the usual syntax highlighting and cool features. Check it out: http://www.flos-freeware.ch/notepad2.html
  2. TaskSwitchXP. Its a fantastic Alt-Tab replacement with loads of cool features. http://www.ntwind.com/software/taskswitchxp.html
  3. Firefox with extensions. The best browser gets even better when you start playing with extensions. There's so many good ones, but AdBlock and AllInOneSideBar always make my list. For web developers, check out FireBug (http://www.getfirebug.com/)
  4. Omea Reader. Its a free RSS reader and much more. I only use it for RSS feeds, and I really like it for that. I used to use SharpReader until I paid attention to the amount of memory it was consuming! http://www.jetbrains.com/omea/reader/
  5. Foxit Reader. For the love of God don't use that horrible piece of bloated tat known as Adobe Reader. There is a better way, and its here: http://www.foxitsoftware.com/pdf/rd_intro.php


I could go on for another 20 entries here, but these are probably my top ones... Oh, and "Query Express" (http://www.albahari.com/queryexpress.html)... oh and LLBLGen, but thats not free!

"Touching Base"

I'm just "touching base" with my blog, which basically means if you convert the management speak crap to normal, that I have nothing in particular to say of interest to the world in general.

What I will say is that I'm happily on Firefox 2 now. It seems to boot a lot faster in windows, and I like the subtle changes to the UI (improved tabs etc). I also think that the improved RSS support is pretty cool, those Live Bookmarks are damn useful!

I'm just waiting for the next release of Ubuntu (6.10) to be released, then I'll boot back into Linux and get FF2 installed in that too.

Cool Javascript/CSS Sidebar reference

Almost forgot to mention it, check this cool AJAX powered sidebar refernence for CSS/JScript (and MySQL/PHP too if you're that way inclined)

http://ql.aonic.net/info.php


Learnnig To Tpye Agian :-)

After years and years of my reasoably fast but error prone self-taught four-six fingered typing, I've decided that I really should learn to type properly (i.e. touch type).

Its driving me mad though!! I think it would be much much easier if i hadn't already programmed my brain to use certain fingers for certain keys - I'm loads faster "old stylee" and still very slow (and error prone) new style... I've been at this for a few weeks now and its getting no easier :(

Programming is the worst, just when you get your fingers in the "starting blocks" you have to reach over for the arrow keys or hit some whacky key combination that you can only do by moving your hands somewhere else....

Fingers crossed (or not ;))


Testing from Windows Live Writer....

Greetings all. I'm testing out windows live writer as an alternative to w.bloggar for creating blog posts...

First impressions are good... I like the way that it gives me a proper preview as it will look in the web. I also like the UI (very Word-esque), and the fact that I can save drafts etc...

I think I'll be using this from now on! :)


Adventures in Ubuntu - Opinions of a Windows user

I've been a windows user since the days of windows 3.1... windows at college and Amiga Workbench at home :) Windows 95 was a big improvement, and XP another big step. But I always wondered how life was as a Linux user. I've also been plagued with XP annoyances recently - spyware, anti-virus software and all the security add-ons have been driving me mad! So, recently I "took the plunge", and discovered how much linux has progressed recently. This post is basically just me waffling about my Linux experience.

So....Ubuntu?

Ubuntu is a linux distribution. Its become a very popular one recently - and I like it too! Wikipeadi will tell you more: WikiPedia link
I googled for a while to find the distribution that sounded good to me, and this one stood out to me - loads of people were raving about it, it had a nice firendly website, and just looked pretty cool. So...on to the installation...

Installation.

I was pretty scared about installing Ubuntu. I have an XP system and I wanted to keep hold of it, and I was worried that I would do something badly wrong and lose my xp partition! I prepared my hard disk by freeing up some space and creating an unformatted partition (40 gig) ready for a linux install. I used windows software to do this, but have since discovered a cool tool called GParted, which can be downloaded as a live CD and used to help you resize your partitions without losing data! All I did was to resize my windows partition to leave to "spare room" on the disk.... sorted.

Anyway, once I had that sorted, I downloaded an ISO of Ubuntu, booted into it, and clicked the icon to install it properly. Thats pretty much all I had to do! The scariest thing was when it asked me where to put the installation, its default suggestion if I remember correctly was to delete the entire hard disk. However I simply told it to use the free space, and off it went. It didn't ask me if I wanted to install a boot loader to allow me to boot windows or linux - this worried me, but it turns out that it did it anyway, I guess linux is always going to be more aware of windows because theres a high chance that windows will be on the system already !! OK, so installation done, I booted into Ubuntu to see what worked..... this is the best bit....

Everything worked!

Yep, I had sound (XP wont find my sound card without drivers), I had the right resolution, I had USB support (insert a memory stick and voila!), I had CD/DVD burning support, l ife was good :) Well apart from my printer, but apparently I can blame Canon for releasing very bad drivers (shame on you!).

The UI, and XGL/Compiz

Something I had heard loads about recently was XGL and compiz in linux. I've watched some video's showing off xgl/compiz effects, and thought that it looked incredibly cool and potentally useful, so I was looking to find out more. If you have no idea what I am talking about, check out this video and then you'll see what I mean. Google video link Anyway, I followed the "howto" guide on compiz.net but theres a lot of guides floating around on this now (e.g. Link)... To cut a long story short, I struggled at first but soon got the problem sorted and now have very fun (I'm not yet decided how productive) 3d effects on my desktop that frankly make Vista look a bit lame :) The only problem is that my ATI card struggles a bit but thats because ATI have very poor drivers for linux. I'm hoping that will change soon since AMD bought ATI.

Using It

I like using Ubuntu - I can get lost quite quickly but its nice to experience a different operating system. I think if I wasn't computer savvy it would have been a hell of a struggle - you can get to a point where things can get difficult to set up and need to delve into forums for help - even installing some software can be a challenge, when all I want to do is download something and make it install! That said, any packages (software) that are in the "repositories" are very easy to install - you can use a UI front-end to browse all available software in the repositoriesand then choose what you want - and theres loads of cool stuff in there... For example I found a media player called amaroK, which IMHO is better than even the latest beta of media player in windows - it just works and does everyhting I want really nicely :) Its just less "popular" stuff that might not be in the repository that can get difficult. Luckilly theres a really popular and helpful forum called UbuntuForums.org which will pretty much sort you out or head you in the right direction.

Programming in Ubuntu is an interesting experience. I installed Mono and MonoDevelop for developing in .NET in linux. To be fair to them its incredible what they have accomplished and what you can do, but I'm coming from a background of Visual Studio 2005 here, and to be honest once you get used to the tools and features of that IDE its hard to get excited about other ones. Anyway, I quickly got bored of that and am currently toying with the idea of playing with "Ruby On Rails" a little......who knows what will happen with that.

Anyway, I waffled on too long now. In summary I think I can safely say I'm quite impressed with Ubuntu. I'm using a fair bit at home and as I get more familiar I might even start to use it more than windows for non .NET tasks... .but I'm not about to jump ship on Windows... at least not yet :-)