Code Snippets

Over the years as a Web Developer, I've learnt a lot and written many lines of code. Not every line is unique though, thanks to code re-use and the adaptability of websites.

I've accumulated a small pile of code snippets, in the form of text files, bookmarks and scraps of paper. However, finding that method for checking NULL values in C# or the syntax for a cursor in SQL can prove to be time consuming - resorting to a Google Search yet again.

So, I decided to finally put all of the snippets in the one place, for referencing during my day to day work as a Developer. Behold: snippets.slickhouse.com

There's already a few on there in various languages that I've dealt with in the past (and continue to). The site is also powered by SlickCMS - with several adaptions to fit the style, such as simplified Post listings and custom URLs to allow for the same named snippet, but differing Languages.

The style is also inspired by the excellent stackoverflow.com - itself a vital source of information for a Developer. I did plan to make the site open to the public, so that you too could add your own snippets - but I felt that you'd either prefer to roll your own (go ahead and download SlickCMS to get yourself started) - or to use an established service, such as snipplr.

Let me know what you think as always - and feel free to keep checking the snippets site, as I'll be adding many more over the next few days.

comments Posted: Wednesday 6th October 2010, 05:37pm
Categories: SlickCMS
Tags: slickhouse

Star Wars in 250kb

For those that haven't yet seen Star Wars, or at least these animated GIFs:

Star Wars Episode IV, A New Hope

Star Wars Episode V, The Empire Strikes Back

Originally brought to my attention by my Father, a little digging shows that they're several years old and the original creator says there's The Return Of The Jedi lying around the Internets somewhere - let me know if you find it!

comments Posted: Tuesday 13th July 2010, 05:37pm
Categories: Video
Tags: star-wars

SlickCMS roadmap

SlickCMS has been released for a few months now and several live sites are powered by it without any major issues. However, since its public release I've not received any outside feedback and indeed, haven't spent much more time continuing with development.

I partly blame my lack of blog updates, as once the development was out of the way and slickhouse itself was running on SlickCMS - I planned to spend more time blogging and actually using SlickCMS from an end-user point of view. Also, I've not actively marketed it to the public, even though Google has ranked it well since its inception.

The current release is version 2.6.147 and 2.7 is progressing steadily. Currently, there are 9 open bugs and 41 features. 2.7's goal is to improve existing features and fix any outstanding bugs. 3.0's goal is to implement new features, with 4.0 being a port to ASP.NET 4.0

However, Classic ASP/VB6 has been around for over 10 years and has been overshadowed by it's .NET sibling. At work, I'd say 90% of the code I write is now VB/C# .NET and I'm learning new techniques each day.

So I've decided to amend the SlickCMS roadmap slightly.

There will be releases in between those major milestones, but it allows me to focus on getting the existing Classic ASP version of SlickCMS 100% bug free and bulletproof - with the code being downloadable for all. Then I'll work on a port to ASP.NET, using properly defined classes in an object orientated way, rather than making do with Classic ASP's flawed implementation of OO. Once that's working well, it'll be onto new features to give SlickCMS the edge.

Once 3.0 is here, I will focus on spreading the word and making it known to others - hopefully gathering some support and even other contributors to the project. I've been contemplating a site like SourceForge/Codeplex/Google Code for hosting the project itself.

If you'd like to keep up to date with the current progress and what's in the pipeline, make a visit to the SlickCMS roadmap - powered by Redmine.

comments Posted: Wednesday 30th June 2010, 05:37pm
Categories: SlickCMS
Tags: slickcms

Hyper-V Server 2008 R2

For the past few years (longer than I can remember) I've been running Microsoft's Virtual Server 2005 R2, an application that installs on their Server operating systems, to allow you to host multiple Virtual Machines on the one Physical Server. So for Slickhouse, the mail; web; database; and domain controller servers are all located on the one physical box.

However, Virtual Server 2005 does have its drawbacks - it's not a pure Virtualisation platform, as it installs on top of an operating system layer. It also doesn't perform as well as other solutions on the market - namely VMWare. Microsoft released Hyper-V as an add-on to Server 2008 and as a free standalone hypervisor - Hyper-V Server 2008 R2. The compatability with Virtual Server is there, but it is a better competitor to VMWare's ESX platform.

Hyper-V does have a few advantages compared to VMWare's ESX/ESXi platform, which I was also looking into. Firstly, the hardware requirements are a lot less strict and you'll find that Hyper-V runs on many modern 64-bit servers that Server 2008 successfully installs on. There are specific CPU requirements, but most AMD/Intel CPUs on the market now support Virtualisation at a hardware level. Secondly, it fits into an existing Microsoft network very well and supports migration from Virtual Server 2005.

I chose to upgrade my main server to Hyper-V at the same time as consolodating the storage for the network. Previously, I had the virtual servers housed on one box, with 4 x 250GB drives in a RAID array within another, acting as a NAS. As with most computer technology, the price of storage has decreased as the capacity has increased over the years. Whereas back in 2005 the 250GB drives cost ~£50 each (~£200 per TB), in 2010 I've purchased a 2TB drive for ~£100 (~£50 per TB), so it made sense to drop the NAS for 24/7 use and put the 2TB drive on the server housing the virtual machines.

I opted for another Samsung Spinpoint HDD, as I've had 9 running smoothly for a few years now, so it made sense to add a tenth. Their 2TB F3 Eco Green drive runs at a slower 5400rpm speed, but I'd say it performs as well as the older generation 250GB SATA Spinpoints, running at 7200rpm. A copy of around 630GB of data (various file sizes) took hours rather than days over a gigabit connection from the original NAS.

The 2TB drive itself is purely for holding all of the data served via the NAS. I was originally intending to connect it to the host and setup shares on it, but Hyper-V Server 2008 R2 only offers Hyper-V, no other Windows Server Services (hence the free price). Server Fault's community suggested that I setup a VM as a NAS and that I wouldn't notice any performance hits.

As for Hyper-V, the installation is very straight forward - much the same as their Server 2008/Vista/Windows 7 installation process, with all the prompts located at the start, rather than strewn throughout during previous Windows installations. Once the install is complete, you can configure the server using the command line interface once the server completes a reboot. This screen remains the same throughout use of Hyper-V Server 2008 R2 with the actual management occuring on a client machine via the Hyper-V Management snap-in.

Hyper-V Management GUI
Hyper-V Management GUI

In usual setups, managing Hyper-V should be fairly straight forward. Install the Remote Administration Tools for Windows 7, then connect to the Hyper-V Server and away you go. However, as all my main servers are now virtualised, including the domain controller - I could only run the Hyper-V Server in Workgroup mode, not as part of the Active Directory domain. As my Windows 7 machines are part of the domain, it meant that I spent 3 evenings back-to-back pulling my hair out to try and get it all working. Virtual PC Guy has a great tool, HVRemote that cuts out many of the headaches involved with the initial setup. I finally managed to successfully connect to the host after plugging in the 2nd NIC, which picked up a dynamic IP via DHCP - so it appears to have been a DNS/routing issue.

Once Hyper-V Server 2008 R2 has been installed and configured, it's a case of either migrating VMs across, or building new ones. Migrating from Virtual Server 2005 proved to be a fairly easy procedure with Server 2003 VMs - uninstall the Virtual Server additions and shutdown the VM before copying the VHD across to the Hyper-V host and creating a new machine (using the copied VHD). When it came to migrating my Server 2008 Web Server across though, things were a little different. The Integration Services wouldn't fully install and a quick check of Device Manager warned me that the Virtual Machine Bus could not find enough resources. As with 99% of IT related problems though, Google netted me a solution.

Hyper-V Console
Hyper-V Server 2008 R2 console view

Once all the virtual machines had been migrated across, full network connectivity and services were restored. Performance appears to have improved from the upgrade: VMs are a lot more responsive after booting or logging on; the sites also appear to load much quicker and SQL Server queries are instant - though I don't have raw figures to back up my claims, but if you have a Virtual Server host, Hyper-V is definately worth looking into, especially if your existing server supports it.

comments Posted: Monday 31st May 2010, 05:37pm
Categories: Computers and Technology, Slickhouse
Tags: hyper-v, microsoft

slckit, a url shortener

In the Web 2.0 era of the Internet, there's a lot more social interaction and exchanging of information. Sites like Facebook and Twitter allow users to interact with each other and share links to the rest of the Web.

However, there's a common problem that's been solved by several services. Take the following Url as an example:

http://serverfault.com/questions/34465/what-are-your-favorite-open-source-tools-that-is-not-very-famous/

It's ideal for SEO purposes - search engines will index it well, as it's keyword rich. It's also very readable to us Humans, but can prove to be hard to remember or exchange with others, particularly with Twitter's 140 character limit.

Then there's Urls such as the following:

http://www.amazon.co.uk/gp/product/0470097825/ref=s9_wishx_gw_ir03?ie=UTF8&coliid=I3U7JRBR10ENKF&colid=3KM21255W1DIA&pf_rd_m=A3P5ROKL5A1OLE&pf_rd_s=center-2&pf_rd_r=1NA1EHC6QE95D007YYER&pf_rd_t=101&pf_rd_p=467128533&pf_rd_i=468294

Not only is it awkward for search engines to crawl, as it contains no useful information - it's merely Amazon specific codes. But, it's also completely useless for us to read and share to others. Sure, you can highlight the string, then copy/paste it - or click it if it's a clickable anchor link. But what if you're on the phone to a friend and suggesting they look at this great product you've found? Do you start reading out forward-slash g-p forward-slash product forward-slash 0, 4, 7...?

Obviously, the first Url is the preferred SEO/Human friendly option, but it's not ideal. So sites like bit.ly and tinyurl.com have cropped up over the past few years to overcome this and provide users with short, easy to remember, easy to use Urls.

Take the first example, in it's bit.ly format: http://bit.ly/9EJLFT

Now take the second: http://bit.ly/a411nG

Regardless of where the Url actually takes you, the bit.ly version is perfect for exchanging over the 'net. That phone call is not only shorter (saving you money) but also isn't prone to misspellings, resulting in a 404. Twitter will thank you for providing it with a short Url and will let you type a further 120 characters. Your memory might actually be able to remember that short 6 character key if needed and you'd easily be able to write it down quickly if required.

So I wanted to have a go and roll my own Url shortening/redirection service: alt text

Behold: slck.it, a url shortener. Simply paste your long, ugly, unfriendly Url into the box and click the button slck.it - my previous examples then become: http://slck.it/m6ITl8 - What are your favorite open source tools? and http://slck.it/l52Skw - Professional IIS 7 (Programmer to Programmer): Amazon.co.uk: Kenneth Schaefer, Jeff Cochran, Scott Forsyth, Rob Baugh, Mike Everest, Dennis Glendenning: Books

In much the same way bit.ly et al work, slck.it takes your long Url and shortens it into a memorable and succint version. Each time someone clicks on your shorter version, they are 301 redirected to the original. Simple.

I'll be using slck.it myself from now on, to shorten my Urls as I contribute on the Internet - feel free to do the same!

Oh, and if you were wondering, the domain slck.it is a hack of slick in slickhouse using an Italian extension. Slck.it itself is also going to be released in the near future for others to roll their own - and it's my first ASP.NET 4.0 application, built in Visual Studio 2010.

comments Posted: Thursday 29th April 2010, 05:37pm
Categories: Slickhouse
Tags: twitter