8 Apr 2009

960 CSS FTW

I like this: http://960.gs/

Might make prototyping sites easier.

31 Mar 2009

Undocumented SQL Server Stored Procedures

This article documents some groovy system stored procs:

http://www.mssqlcity.com/Articles/Undoc/SQL2000UndocSP.htm

Sprocs include stuff like "FOR EACH DB/TABLE DO X" and "GET QUALIFIED OBJECT NAME".

Mucho useful. Now why the hell are they secret?

12 Mar 2009

Embed images in your web DLLs

You can embed all sorts of stuff into an assembly - javascript, css, pdf etc. Here I quickly detail how to embed an image file.

1. You have a solution with a web project and a separate class project
2. In Visual Studio, drag the image you want to embed into your class project
3. In the Properties window of the Image, select Build Action: Embedded Resource
4. Add a new class to the project, call it EmbeddedResources.cs for the sake of argument. Put the following code in it:

[assembly: WebResource("YourProjectAssemblyNamespace.YourPic.jpg", "image/jpeg")]

namespace YourProjectAssemblyNamespace
{
public class EmbeddedResources
{
}
}


5. Reference the image from your web project like so:

<img src="<%= Page.ClientScript.GetWebResourceUrl(typeof(YourProjectAssemblyNamespace.EmbeddedResources), "YourProjectAssemblyNamespace.YourPic.jpg") %>" />


Woop!

Resolve Virtual Path From Physical Path (ASP.NET)

Quick code snippet to help people who want to derive a Virtual (web) path from a Physical (file) path:

string strVirtualPath = VirtualPathUtility.ToAbsolute("~/" + strPhysicalPath.Replace(Request.PhysicalApplicationPath, "").Replace("\\", "/"));


VirtualPathUtility FTW!

5 Mar 2009

.NET Regular Expression Reminder

I must be dense - I *heart* regex but every time I need to use one in .NET, I spend about 5 minutes trying to remember

  • what the right grouping character is
  • whether I need to escape it or not
  • which Regex class to start with
  • what the right terminology is for getting the sub-matches out of the match etc.
Which is weird cos when I was king of perl I could do this stuff lickity split. So I guess MS just like making it confusing. Evidence 1 - the regex syntax in Visual Studio is totally different to that in .NET. Duh.

Anyway here's a handy reminder to myself:

string strServer = System.Text.RegularExpressions.Regex.Match(strCon,"Data Source=(.+?);").Groups[1].Value;


Note the (.+?);
The trailing ? forces the match not to be greedy and only match up to the first semi colon.

26 Jan 2009

Fun around Hogwarts

Last week Ruth and I drove oop north for a weekend in Northumberland.

We stayed at a "luxury" B&B called The Old School at Newton-on-the-Moor. It was cute, and Kath and Malcolm were great hosts. However we felt a bit restricted by the usual mom n' pop B&B issues like breakfast being available only for an hour in the morning, and being locked out of the place between 11 and 4 in the day. Also our room got chilly, there was no bath, and the shower never worked properly. I think they are in the middle of sorting out issues with their heating system so I'll let them off, but it makes us think about staying at a hotel next time. The breakfasts were excellent though :)

On Saturday, we went to the Holy Island of Lindisfarne, managing to drive across the causeway both ways without getting trapped by the rising tide. However we soon found that there is bugger all to do there during the winter months. The castle was sweet (albeit closed) and the landscape lovely, but the bitter wind soon drove us back to the car.

We then pootled down the road to Bamburgh with its amazing castle - also closed for winter. In fact the entire place seemed closed. We ventured into a coffee shop called The Copper Kettle and had really crappy service, hooray. God they were miserable. At least the beach was nice.

The saving grace of the day was Alnwick, where we completely avoided the Harry Potter freaks by spending almost FOUR HOURS in Barter Books, the funkiest (in a skillo kind of way) bookshop in the universe. If you're in Northumberland and you like books, you must visit. It's enormous and friendly and great. Nuff said.

On Sunday we went to Durham. It was like York, only not as good :) THAT IS ALL.

Oooh, apart from the food. Two things

  • The Linden Hall Hotel does lovely posh nosh for ~50 quid a head
  • The Cook and Barker pub in Newton-on-the-Moor does lovely unexpectedly posh nosh for ~25 quid a head.

There is good eatings to be had in the North! Yay!

6 Jan 2009

2008 Product Roundup

Hi Zootfans, and a happy new year to y'all!

Someone just left a comment on one of my posts saying it helped them out, so I feel satisfied enough to continue this most unrewarding job :)
So, a quick round up on some material stuff I bought, in case it helps anyone out:

Toshiba Regza 37" LCD Television (2007 model)

SUCKS. Do not buy. How does it suck? Let me count the ways. Rubbish remote control range - have to point right at the receiver too. SLOOOOOW channel hopping and menu response. Poor sound. Now also has a fault meaning the backlight doesn't fire up when you first turn the telly on. You have to turn it off and on again. Annoying. The telly has one saving grace - good picture quality. I won't buy Tosh again - I had one of their DVD players too and it was also crap.

Sony Bravia 32" LCD Television (2008 model)

IS GOOD. The remote control is responsive and bounces off walls, yay. Good sound, picture, menu system. Just the ticket.

Mazda RX-8 (2004 model)

This car is heaven and hell. Heavenly handling. Hellish fuel consumption - I averaged 21mpg!. Angelic practicality for a sports car - big boot and real adult seating in the rear. Demonic depreciation - I lost £5k in 9 months :p The wankel rotary engine is interesting and helps the 50:50 weight distribution, but has poor low-down torque, and also has a design fault: If you don't let the engine warm up before cutting the ignition, e.g. if you just need to move the car off the drive - when you come back to the car you'll find it won't start. You need to faff about removing the fuel pump relay and gunning the engine until it's spat all the unburnt fuel out that's accumulated at the bottom of the rotor chamber. You shouldn't have to do this in a modern car. Nor should you have to put a litre of oil in every month.

Overall I loved owning such an exotic piece of hardware for my day in the sun - on twisty roads on a summers day it was brilliant. But as winter closed in, petrol prices went up, and I found it was useless on cold roads, I wasn't sad to say goodbye. I'll remember it fondly though :)

Audi A4 Avant 2.0 TDI SE Multitronic (2005 B7 model)

I've only had it a month but I like it. Things that are good:

- Fuel consumption: Average 41mpg, not bad for an automatic.
- Loadspace: lots of it.
- Multitronic CVT transmission: Smooth and powerful.
- Bluetooth phone integration: works the moment you get into the car, phone in pocket. So much better than having an earpiece, and lets you browse your phonebook using the steering wheel controls.

Things that are less good:

- Headlight range isn't great (non-xenon).
- The auto-locking and single-door unlocking "features" are annoying (anyone with a VAG-COM can fix it though).
- The voice-command features for the phone don't work very well, always making mistakes.

DICE Ipod Integration for Audi (2008 model)

I have fitted this to my new Audi A4 (B7 model) and amazed myself with my mad engineering skillz ;) I had to buy stereo removal keys off ebay to pull the Concert stereo system out of the dash (tip: the keys go in pointy-side out, and are removed by pushing in the locator clips on the stereo). I also had to remove the glovebox, which is easy when you know how:

1. Remove side panel to the glovebox. Prise it carefully with a flat screwdriver wrapped in electrical tape. It's only held in by clips.
2. Use an 8mm socket to remove the 5 bolts that hold the glovebox in place. 3 bolts are on the top edge of the opened box. The other 2 bolts are underneath the box.

Voila, the box comes out. Don't forget to reattach the light connector when you put it back.

The DICE unit installation was dead easy really as you just piggy-back the old audio harness into the new DICE harness, and shove that in the back of the stereo. Then you put the ipod connector cable through the back of your glovebox - I cut out a pre-formed square that Audi have thoughtfully left for you there. I didn't have to unplug the car battery during the install, and I didn't have to re-input the stereo code afterwards either.

And finally - how well does it work? Works ok. The ipod charges in the glovebox and you can skip track / change volume from the main car and steering wheel controls. Playlist and track navigation is poor because the Audi Concert stereo can't display tracknames. So I'm just going to create a few playlists and leave it on shuffle. It has one other nice feature - a separate aux-in cable so you can attach non-ipod sources too. Sound quality is good. Overall - a vast improvement over my old FM transmitter.

Asus Eee 901 netbook computer (1Gb RAM, 20Gb SSD model)

This has to be my most satisfying purchase this year! It took ages to get my hands on the 20 gig solid-state-drive linux model because they were out of stock everywhere. I played with the custom linux interface for a while and decided it wasn't for me. Seemed to have a few bugs that Asus weren't interested in fixing, and a few of my favourite apps and emulators weren't available for linux. Crucially, the flash player seemed to make videos jerk which was really annoying as I'm a YouTube / BBC iPlayer junkie.

So I installed XP instead. I used nlite to shrink down the install footprint, and installed off an 8gb memory stick. That was the major pain in the bum, XP just wasn't built with USB installs in mind. I had to jump through a hell of a lot of hoops to do it, and tried a lot of different methods that didn't work for me (e.g. BartPE). In the end I did it using USB_Multiboot_10 : http://www.msfn.org/board/index.php?s=962f023b64ec36301f9ea200d4ea3ed8&showtopic=111406&st=0&p=737643&#entry737643

Anyways, the Eee 901 with XP kicks ass. Lasts over 5 hours without recharging. Quiet - no moving hard drive parts, just a little fan that kicks in when you do something intensive, like amiga emulation :) Performs brilliantly for its specs. You can surf comfortably in bed. I love it!

Roland TD-3KW V-Drums

I've decided to learn to drum, so V-Drums are a great choice cos they don't annoy the hell out of everyone else in the neighbourhood. I'm just getting started really, but they sound good with my new AudioTechnica MTH50 headphones, and were easy to set up.

And with a crash-boom-bang, that wraps up this entry! Byeeeee

9 Apr 2008

Bunscrape

I have the only google-recorded usage of the word Bunscrape, which describes the activity of taking an uncooperative rabbit for a walk on a lead. Contrast this with a Bunwhirl, which is the alternative activity of twirling said rabbit around in the air on the end of the lead in a manner reminiscent of the film Kes. If somebody could commit a Bunwhirl to video, including a successful bid for the bunny from a passing Kestrel, I humbly submit that this would be the best YouTube vid EVAR.

In other news:

1. The Sony NW-A818 is the best MP3 player in the world
2. The iStuff FM Transmitter is the worst FM Transmitter in the world

THAT IS ALL

11 Dec 2007

Callbackia - The land before Ajax

Okay maybe I'm wilfully ignorant but did you know that ASP.NET 2 had asynchronous client-server callbacks afore this AJAX lark began to make our lives so... rich and fulfilling? And from what I've used of them, they are a lot more practicable than the ginger stepchild Ajax.Net PageMethods that I covered previously.

So in essence, here's the gen.

1. Any Asp.Net Page or Control can expose itself to AJAX-style client-side calls and easily perform some server logic before returning some value or other.
2. You just have to implement the System.Web.UI.ICallbackEventHandler interface. This requires two methods, RaiseCallbackEvent(string eventArgument), which receives a request from client-side, and GetCallbackResult() which returns a string to the client.
3. You need to call a special client-script registration method in your ASP.NET code. This example explains it better than I can be bothered to:



string strClientCallbackAutoGubbins = Page.ClientScript.GetCallbackEventReference(this, "RequestArg", "ServerCallResponse", "OptionalContext", true);
string strClientCallbackFunctionCode = "function ServerCall(RequestArg, OptionalContext)" + "{ " + strClientCallbackAutoGubbins + ";}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ServerCall", strClientCallbackFunctionCode, true);


4. Then you just need to implement client script to call the ServerCall client function and get the response back in the
ServerCallResponse client function.

5. The format and purpose of the string argument passed to ServerCall, and the format of the response string returned to
ServerCallResponse is up to you. You could use JSON, XML or any other bloated WEB2.0ism of your choice - or you could do wot i dun and just pass a bog standard querystring along.

ViewState Mayhem

I made a portal app that had little draggable, dynamically loaded ASP.NET webcontrols that you could move around a dashboard. All was fine and dandy until I needed to handle control events in these draggable controls. See, when I moved a control, the viewstate got all munged up and controls started restoring each other's data. WHY WAS THIS SO?

Turns out that by default, ViewState is maintained NOT by an index of ClientIDs but by offset indexes to the parent control. So if you dynamically change the order of controls loaded in a container between first view and postback, ViewState will go boom.

The elusive, and not very satisfactory solution, is the mysterious ViewStateModeById custom attribute. When adorning a class, it ensures the object will have its ViewState keyed by ID instead of by index. Huzzah. Only prob is you need to wrap everything you want to maintain this way in a thin wrapper in order to implement the custom attribute. Oh joy.

Anyway for this and other sexy CustomAttributes you may have missed, check dis:
If I helped you out today, you can buy me a beer below. Cheers!