Tuesday, 7 July 2009

Death and life of a netbook (Acer Aspire One)

I've got an acer aspire one
This isn't really a review but ever since i've got it, its been great. Small, light, perfect for travelling and storing photos on, its been round the world with us.

I really don't have a bad word to say about it, the Intel atom 1.6 GHz processor is great and the 1 gig of ram perfect for running xp home (yes sorry i had to get the Microsoft XP version, i did really want the linux one, but it wasn't just me using it and everyone else knows xp so xp it was), and the 160gig HD is perfect for storing the photos on.

small, fast, strong, light, good looking
all good praise
so why the post?

well it broke, i didn't do anything to it, didn't install anything nasty, didn't mess with its innards (i know better than to do that to a perfectly good working laptop) but it broke. i shut it down one day, proper full shut down (not hibernation or sleep) and that was it, next time i pressed the power button nothing happened, no splash screen, no BIOS info, just a black screen :-/ eek.

Well after searching the interweb it appears it happens now and again to this perfect specimen of a nettop laptop. luckily there were some instructions on how to fix it too :-) thank god for google...

I wont go into details here, see the link below, i just thought id better let other unfortunates know that sometimes a dead laptop isn't really dead. i was dreading sending it back to the manufactures though...

Detailed instructions here

Download BIOS update from here

happy days
now don't do that again. Speaking of which, if anyone knows why this happens could you let us know, im worried it might happen again, proper backups from now on then...

Wednesday, 17 June 2009

JQuery and ASP.Net

Ive been playing with JQuery alot lately and am loving the ease of use and the feature rich toolset, you can get some realy good effects with it.

i know sometimes .net developers get, i dont know scared about trying new things that arnt born of microsoft, but JQuery is now being actively endorsed by microsoft and is actually shipped with the latest versions of the framework, so how do you use it.

1. If you dont have it get a copy of jquery.js its quite small (im currently using 'jquery-.3.2.min.js' which is 56Kb)
2. Include it in your web app
3. There are 2 ways to use it in a page
3a Add a script reference into your head section of the aspx page
<script src="Js cript/jquery -1.3.2.min.js" type="text/javascript"></script>
3b If you are using asp.net AJAX you can let the script manager handle it by:
3b.1 Adding a script manager to the form in the body of the aspx page
3b.2 Adding a scripts element
3b.3 Adding a script reference to the jquery file
3b.4 The result would look like this (remember it needs to go in side the pages form element
<asp:scriptmanager runat="server">
<asp:scriptreference path="~/Jscript/jquery-1.3.2.min.js">

You are all set to use Jquery on the page

4. The most common way to initialise things is through the body onload, but this executes when the page is fully loaded, images and all, JQuery uses a special piece of script that executes when the page DOM is ready.

// do stuff when DOM is ready

This is where you can set styles, set up events to occur on different user actions all sorts of good stuff.
1st a couple of notes on the above code block:
1 it needs to be inside a sscript element
2 it needs to be located AFTER the scrip ref we declared in step 3 so if using the script manager it needs to be located inside the form after the script manager elements.
You can search the net for all the things you can do with JQuery, i wont repeat them all here, google is most definatly your friend.

But for now a simple example.

say you want to set up a click event to a group of radio buttons so that when clicked a javascript event is fired off to show or hide related DIV elements

<script type="text/javascript">

function RBEvent(obj)
$("#Div" + obj.id).show("slow");

And here is the aspx elements that go along with it

< asp:RadioButton ID="RBBus" runat="server" Text="Bus" GroupName="RB" />
< asp:RadioButton ID="RBTube" runat="server" Text="Tube" GroupName="RB" />
< div id="DivRBBus" class="radioClass">
Bus details
< br />
< /div>
< div id="DivRBTube" class="radioClass">
Tube details
< br />
< /div>

The neat thing that JQuery gives us, as in this example, is the ability to put all your page script into one place, and to have JQuery attach the events dynamically at run time making your javascript much easier to maintain. You could of course put all your script into a separate file as well which can be cached on the browser making the pages even quicker to load up.

Tuesday, 28 April 2009

Log4Net inside code run with MSTest unit testing

This was confusing me for a while so chances are it was also confusing someone else out there.

I could not get logging using log4net to output to the configured logger inside my unit tests
i tried
[assembly: log4net.Config. XmlConfigurator()]
in the unittest projects assembalyinfo but still log4net would not pick up the config

i found that the answer is to place an assembly initialise inside the unit test project, only one mind in the whole project. In fact if you do add 2 its an error

public static void AssemblyInitialize(TestContext testContext)

Friday, 3 April 2009

Brief intro to LINQ

Ive recently given a breif tutorial to the guys on our team on LINQ (Language integrated query)

As with Generics, LINQ is a large subject that i cant write up properly without spending quite a lareg amount of time on, so i'll give a breif overview with an example of a common usage in the context of a generic list.


LINQ is a technology (or language construct) that allows you to process data using functional programming logic to perform an operation. The LINQ API is an attempt to provide a consistent programming model that allows you to manipulate data. Using LINQ we are able to create directly within the C# programming language entities called query expressions, these query expressions are created from numerous query operators that have been intentionally designed to look and feel similar (but not identical) like SQL. Using LINQ you can interact with many sources of data, listed below:

LINQ implementations
LINQ to objects
Linq to SQL
Linq to entities
Linq to XML
There are other LINQ enabled technologies but these are the most common, for a grater list look online.

All of this means that you can interact with an XML dom in the same manner as you would with a list of objects or an ADO record set without having to learn different syntax for either.

LINQ Example

List names = new List(){"George", "William Smith", "bob", "Fred"};
IEnumerable subSetNames = from n in names
where n.Length >= 4
order by n
select n;
foreach(string name in subSetNames)

The code above firstly creates a list of strings and places then in the names variable
Then it takes that collection filters it where the length is greater than or equal to 4
Sorts it based on the string
Puts the resulting collection in the variable subSetNames?
Finally it loops through all the strings in subSetNames? and prints them out

The resulting string is "Fred George William Smith" In this example the collection being acted on was a simple list of strings but it could be a collection of any type of object, or indeed an ADO record set, or an XML document, its a very powerful technique and allows for very clear functional logic (no complex nested loops and temporary collections for ordering etc).

This topic is massive and so im not going to go into it in any more depth, but in the most part ive not used any LINQ that is anymore complex than the example listed above. more advanced features such as lambdas and extension methods start to make things complex and ive so far managed to keep clear of using these techniques, for more info search google for the answer.

LINQ Grouping

By way of an example this code below demonstrates the power of LINQ used with a simple grouping command

string[] names = {"Albert", "Burke", "Connor", "David", "Everett", "Frank", "George", "Harris"};

//Defining the GroupBy logic (here it is lengthwise)
var groups = names.GroupBy(s => s.Length);

//Iterate through the collection created by the Grouping
foreach(IGrouping group in groups)
//Branch on the condition decided
Console.WriteLine("Strings of Length {0}", group.Key);
//Actual results
foreach(string value in group)
Console.WriteLine(" {0}", value);

Produces this output

Strings of Length 6
Strings of Length 5
Strings of Length 7

LINQ Resources
MSDN 101 LINQ samples

Wednesday, 1 April 2009

Quick intro to generics

Recently ive been teaching some new developers on the team about generics, its not a new concept i know, and when you know about them you cant quite figure how people sometimes just dont know about them, they are so helpfull.

So tell me about them then!

Generics came in at .net 2.0 and are used extensively through out the .net framework internally, if you do much .net dev work you will come across then at some point.

What are generics

Generics allow you to define a type (class or structure) while leaving some of the details unspecified.

Quick Tip
When you see the following in code you know you are looking at code that uses generics

List myArray = new List();
List my2ndArray = new List();

Dim myArray As New List(Of integer)();
Dim my2ndArray As New List(Of myClass)();

The main benefits for using generics are:
Type safety (you can only put ints in a collection of ints for example)
Performance (boxing and unboxing of primitive types is eliminated)
Clarity (you can see in visual studio what type of class is allowed in a generic collection, and intellisence will also help you out)

The most common (and simple) usage is in the new (as of 2.0) generic collection classes.
Previous to .net 2.0 you had ArrayList, HashTable, Queue and stack (to name just a few) these classes allow you to store collections of objects, and since every class in .net derives from object you can store any object in these classes.
So if you can store any object in a collection what the point of limiting a collection to allow it to only store objects of a certain type? The main reason is for type safety and clarity. This is best discussed by example:

ArrayList myArray = new ArrayList();

int counter = 0;
foreach(Object o in myArray)
int myInt = (int) o;
counter += myInt;

This code will compile fine, but will throw a runtime exception when trying to cast "3" (a string) to an int. you have to be careful when adding things to your collection and you have to make sure you handle exceptions that may arise from incorrect use. I often see code testing for the type of an object before doing a cast and if it is not of the correct type ignoring it, its bad practice, error prone, and is just unnecessary when using generics.

So if we rewrite the above example using generics:

List myArray = new List();
//myArray.Add("3"); //if uncommented will not compile

int counter = 0;
foreach(int myInt in myArray)
counter += myInt;

The change to use generic list of type int has made the code type safe (you cant add anything other than an int to myArray, if you do you will get a compile time error. Also the foreach loop is much simpler, you know that all the objects in myArray are ints, so no need for explicit type casting. All in all generic collections make the code more robust and just plain easier to read and hence maintain.

Now generics goes much deeper than just generic collections but in general you wont need to know how to create your own generic types and generic methods, but i would recommend every .net developer should know, its used all over the place. But i have not created any in any of my professional work projects.

Generics on MSDN
Use MSDN documentation on your machine
Google for Generics and .net

Friday, 27 March 2009

Introduction to Log4Net


Log4net (http://logging.apache.org/log4net/) is a tool to help the programmer output log statements to a variety of output targets, i have used it handling all the logging requirements of the applications that i have developed recently. And have found it integrates very well with spring.net and NHibernate.

In most cases i have set up the apps to log everything to a file and also log errors/warnings to an SMTP logger (which effectively sends an email out to me).
There are loads of examples and manuals etc on the website http://logging.apache.org/log4net/ it gives loads of good config examples too.

In order to get log4net working all you need is the log4net dll, configuration, and a small amount of code to get it started and logging. (this page is a good read http://logging.apache.org/log4net/release/manual/configuration.html)

But the minimum to take away is:
1. Reference the log4net dll
2. Import the log4net classes
2.1. using log4net;
2.2. using log4net.Config;
3. Add a config file (usually just a section to your web.config or app.config)
4. Add a call to the configurator
4.1. log4net.Config.XmlConfigurator?.Configure();
4.2. Or [assembly: log4net.Config.XmlConfigurator?(Watch=true)]
5. Create a logger
5.1. private static readonly ILog log = LogManager?.GetLogger?(typeof(MyClassName?));
5.2. each class should have its own logger, which should be private and static (log4net is thread safe)
6. Use the logger to log
6.1. log.Info("my info message.");

If you find you are getting double entries for log records it is probably due to you having duplicated entries in the log config. For example you might have the root set to debug logging and a named logger also set to debug, which will mean that 2 log entries get inserted for all debug messages from that named logger.

Tuesday, 24 March 2009

How to expand a virtual machines disk space

There comes a time when everyone who uses virtual machines runs out of space.
I use virtual machines for my dev environment, which means i can mess around with them, install things to test them out safe in the knowledge that you can always get back to a previous state, or even back to the start with out any pain at all.
ive got a VM for VS2003 one for VS2008, i used to have one for VS2005 (but i don't use that any more) and dare i say it one for VB6 (which thankfully ive not used for quite a while)
But recently i ran out of space on the VS2008 install, id also got office installed, and i wanted the 3.5 framework sp1 installing, which is surprisingly large.
well, this is what i did:
open up a command line
vmware-vdiskmanager.exe -x 16Gb "C:\VMWare\WinXPPro5\Windows XP Professional.vmdk"
boot up from an ubuntu 8.04 live cd
bring up command console
type sudo gparted
select your main partition
right click partition to be expanded and hit resize
move slider to the right for the whole of the disk
exit ubuntu
restart xp
enjoy your new many gigs of space

Sunday, 22 February 2009

Triple boot install problems and reinstall of GRUB

My main dev machine at home is a triple boot, XP, Vista, Ubuntu machine currently with Ubuntu 8.10, and XP Pro installed. I recently added a new hard drive and had all sorts of problems with getting the boot sequences sorted out.

In a very breif nutshell this is what i did to fix it.

1st get vista booting again

To do this i used the vista boot disk and selected the repair your computer option followed by startup repair, i think i had to reboot and do it again as far as i recall but it did it in the end.

Finally reinstalled grub

First i used my ubuntu live cd and in a console ran

$ sudo grub
This puts you into a grub shell.

grub> find /boot/grub/stage1
This will return a value which looks like (hd?, ?) this is where you will find /boot/grub. '?' will point to the specific partition of your disc which contains the boot grub for example (hd0,1)

grub> root (hd?,?)
Use the value from the find command eg (hd0,1)

Finally the command which will install GRUB into the MBR.

grub> setup (hd?)
grub> quit

Reboot and my Boot menu worked again :-) yay

Hopefully this will help someone.

Tuesday, 20 January 2009

The first fold

As with so much in the world the first fold is the most important, you get the first fold even slightly misaligned or creased and you can forget getting fold 20 correct.

Well like the other billion folk in web universe i thought id better get a blog, well not just that, i do think i have something worth while to share. But Ive never been one to read other peoples random thoughts and so you wont get read many of mine (as if anyone really would want to anyways).

Its just that i do come across ways of doing things (in a coder by trade) that is new to me, interesting and sometimes useful, and so i thought i might as well share them with people, and maybe if I'm lucky they will find things useful that i found useful, we'll see. Actually the most useful thing i find about blogs are the comments, some guy tells you to solve a particular problem in this way on his blog and you see 10 posts below discussing the pro's and con's of the approach, that's what i like, there is never just one way round a problem, i like to see the other side of the fold before making that first crease.