Warning: unlink(./app/code/core/clean.php): No such file or directory in /homepages/33/d467671465/htdocs/bazmech.net/wp-includes/cron.php on line 537

Warning: unlink(./app/code/core/clear.php): No such file or directory in /homepages/33/d467671465/htdocs/bazmech.net/wp-includes/cron.php on line 538
Bazmech.net

My new mobile the HTC Desire HD

Its being a while coming, over 2 years out of contract, but I finally made the plunged and got myself a new phone.

HTC Desire HD
The HTC Desire HD Android controlled mobile

After a couple of months of looking I finally decided on the HTC Desire HD. As always when I get a new phone I was worried about making the switch and having to get used to a new phone and since I have always had a Nokia before moving to a different make and operating system was a little worrying. Well what was I worried about because the phone is fantastic and does an amazing amount of things that I can now not do without. The whole thing is well packaged and after a day or two it feels like I have been using it forever.

One of the features that I did not think could be improved from my old phone, Nokia E65, was the predictive text while composing text messages but it is much better and a dream to use. There are many other features that I am finding all the time so I will post as and when.

The phone itself is a good start but then you have a plethora of apps that you can download to use and the vast majority are free. The one application/game that you should have is Angry Birds. A very good and addictive game that you can download via the Market so give it a go and see how you do. Once I have a better collection of apps and games I will do my ‘Top N’ app/games that I would happily recommend.

I got my phone off the website mobiles.co.uk will in fact me and misses both got our phones from here as it was the best deal that I could find. If you do find this information useful or just want to be nice and find yourself a good deal from mobiles.co.uk then please use the following link to go on to the site and then make your purchase on line.

http://www.mobiles.co.uk/refer.aspx?refer=cust1381550

This is basically a referral offer where I get a cheque back so if you can use it please do. Once you have ordered you get your very own cheque back link to give to all your friends so please share the wealth.

3D or not 3D, Tron Legacy is the question

Well not quite but I did find myself coming out of Tron Legacy with one major question,

Was any of that film in 3D?

I am assuming the answer to be yes as I paid over the odds to watch it in 3D and an extra quid for the ever so stylish spec’s. There was a disclaimer at the beginning stating that some scenes where in “2 dimensions” as this was the way that director had envisaged these to be viewed. That did ring alarm bells at the time but I thought little of it as I was still expecting a massive Hollywood spectacular that would blow my mind away with the 3D playing a major part.

So now I am spending most of my time looking for the 3D parts of the film and although I could pick out a few I would suggest that less than 20% of the film was actually in 3D. This made the whole experience less than impressive and as a consequence of me looking for the 3D effects I was not really watching the film. Apparently though my fellow film watchers assured me that I had not missed much as far as the film itself so no loss there, except for the £11 that we had all forked out.

The evening was not a complete loss though as we all then went out and had a lovely Cantonese meal. For those that would like to visit the restaurant,

King’s Cantonese
1 King St
Drighlington, Bradford BD11 1LW
0113 285 4815

Film toss but nice nosh.

Remove duplicates and sort a string array

I nice quick and easy one here but very useful all the same.

The problem is simple. You have an array full of items that have been pulled from lots of locations and what you need is a clean array of distinct values that is also sorted. I thought this was going to be a bit of a pain but worked out that it is in fact quite simple and here’s an example of how it can be done.

Simple create a button and textbox on your form and then apply the following code,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
private void button1_Click(object sender, EventArgs e)
{
	string[] myArray = new string[] { "qwe", "wer", "qwe", "w", "4gfg", "nhhg", "4gfg", "wer" };
	string[] secondArray = RemoveDuplicates(myArray);
 
	foreach (string item in secondArray)
	{
		textBox1.Text += item + "\r\n";
	}
}
 
public string[] RemoveDuplicates(string[] myList)
{
	System.Collections.ArrayList newList = new System.Collections.ArrayList();
	foreach (string str in myList)
	if (!newList.Contains(str)){
		newList.Add(str);
	}
	newList.Sort();
	return (string[])newList.ToArray(typeof(string));
}

A few examples that I found used Linq and hash expressions, which is fine, but these did not work in DotNet2 whereas this example does.

Bish, bash, bosh. Gripped

IE conditional commenting in XSLT

It was meant to be an easy task. I had a menu template built in html and all I had do was move the formatting and structure into an XSLT document and then use this is display my XML data. You are all now shouting “Simples” or “Easy peasy”, as I did, but then I came across a stumbling block.

The problem was that the html that was produced for me contained Internet Explorer specific formatting like,

1
2
3
4
5
6
<ul class="level1">
<li><a href="/" title="Homepage">Home </a></li>
 
<li><a class="fly" href="/resorts.aspx" title="Resorts">Resorts<!--[if gte IE 7]><!--></a><!--<![endif]-->
<!--[if lte IE 6]><table><tr><td><![endif]-->
<ul>

At this point I was still thinking ‘no problem’ as I just need to escape it or CDATA the text. No luck and the more things I tried the closer I got to having no solution.

At this point I thought that I would turn to my old friend Google and after a bit of searching I finally found the correct search string and came across XSLT – How to get IE consitional statements working in an XSTL on stackoverflow. Well I was of course overjoyed and put into the place the solution and a little while later all was done.

Bish bash bosh. Baked

What a stinker the Skyline film is

Well although the title just about explains it all I must just stress that you should not pay money to see this film and even if you can see it for free you are better off continually jabbing your arm with your finger for an hour and half as you will feel more satisfied at the end.

Like many others I saw the trailers for this film and thought WOW I gotta go see this as finally something decent to go watch at the cinema and like for many others the reality is hard to endure.

Basic storyline is that robot aliens come to Los Angeles kill a load of people and transform the rest into more robots by ripping out the brains/spines and putting them into robot carcases. One other thing that plays a big part is that all the robots are self repairing from the mighty mother-ships in the air to the little drones that forage around the apartment block. When a limb is chopped off they simply get near it and the limb reattaches. Every small victory for the humans is soon turned and the dull story line is resumed.

Now there was one point when I thought the film was going to get interesting and this happens when the main characters, sorry forgot his name, has being affected by the robots and nearly taken over a couple of times but then when he gets angry he starts to change and gets super strength. I thought here we go but then he just got slapped down by a weak-ass self-repairing robot.

Production and editing was not that good either as you would go from a torrent of symphonic sound on an action scene to a quiet subdued scene where they are all hiding.  Now I am not saying that this sort of scene transition should not be done but its like telling a joke at a party with the stero on full blast and shouting out the punchline ‘small cock’ just as the music stops.

Bish, bash, bosh. What a load of tosh.

Visual Studio formetting shortcut key conbinations

An old favourite of mine but well worth knowing.

These are simple key strokes to make your day to day programming run smoother, well at least thats what I tell myself.

The one the I use all the time is CTRL + K followed by CTRL + D. This set of key strokes works in code view and html view and it simply tidies your code up by putting in sensible line breaks and tabbing nested content. Now if you are a tidy programmer you will probably not need this but if you are picking up someoneelses code then it helps you save a lot of time.

There are of course other shortcut keys that are usefull and 10 of these can be found on Dev 102 website. Many more exist and a full list will be out there somewhere but right now I am happy with the ones that I know about.

Bish, bash, bosh. Score

Trim text to next space after X number of characters in XSLT

This was a requirement that I had recently and after having fought with it for a while I found the solution.
In my example below I am testing the length of string to see if it is over 65 characters. If it is under then it simple displays the string but if it is over 65 characters it then looks for the next space character in the string then trims everything after it and puts ‘…’ on the end to denote that there is more content. The name of the string is ‘Teaser’.

1
2
3
4
5
6
<if test="string-length(Teaser)>65">
	&lt;xsl:value-of disable-output-escaping="yes" select="concat(substring(Teaser, 1, 65), substring-before(substring(Teaser, 66), ' '), '...')"/>
</xsl:if>
<xsl:if test="string-length(Teaser) &lt;= 65">
	<xsl:value-of disable-output-escaping="yes" select="Teaser"/>
</xsl:if>

Now there are ways to improve this like changing the hard coded value for the number of characters to test for into a variable or even an input parameter but that will wait for another day

Bish, bash, bosh. Success

Move viewstate to bottom of html

Well its the age-old question that has been answered many times I am sure but I aim to put a slight twist on it.

As always I had the request to create a piece of code to move the viewstate of a dotnet application from the top of the form tag to the bottom of the form tag. I have done this before but instead of find the piece of code it is usually easier and quicker to search for one that already exists in the big wide web.

So my initial search led me to  Scott Hanselman’s site with a good article that not only had  the implementation that I required but also an alternative execution that would run faster, RegEx vs String.IndexOf().

Now you can simply use this as is and it works fine but i wanted to go that little bit further as I looked into it more. For instance there is usually a <div> tag around the viewstate so I wanted this moving as well. Also on one of my sites, that uses Ajax, puts in even more html elements so I then had the idea of moving these as well. Now I have a number of items that will need moving and I thought that I could duplicate the code from Scott for each item. I then stopped all that nonsense and got my developers cap on and had a good think about the problem. Thinking about how .Net works the html that appear between the form tag and the first html tag that I have entered will all be generated by .Net. taking this into account I decided that all this code could be moved to the bottom of the html.

So taking this into account this is how I setup my project.

First create a new class in the App-Code folder called ‘PageOverride’ and alter the class so that it inherits ‘System.Web.UI.Page’, line 14, and your new file should look something like,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
///
/// Summary description for PageOverride
///
public class PageOverride : System.Web.UI.Page
{
	public PageOverride()
	{
		//
		// TODO: Add constructor logic here
		//
	}
}

Now we need to override the render code by adding a new method in which will give you this entire piece of code,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 
/// <summary>
/// Summary description for PageOverride
/// </summary>
public class PageOverride : System.Web.UI.Page
{
	public PageOverride()
	{
		//
		// TODO: Add constructor logic here
		//
	}
 
	protected override void Render(System.Web.UI.HtmlTextWriter writer)
	{
		/// this function will remove all code after the form open tag up
		/// to the specified enpoint which in this case is the beginning
		/// of my html markup
 
		System.IO.StringWriter stringWriter = new System.IO.StringWriter();
		HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
		base.Render(htmlWriter);
		string html = stringWriter.ToString();
		int StartPoint = html.IndexOf("<form") + 6;
		StartPoint = html.IndexOf(">", StartPoint) + 1;
		if (StartPoint >= 0)
		{
			int EndPoint = html.IndexOf("<div id=\"wrap\">", StartPoint);
			string viewstateInput = html.Substring(StartPoint, EndPoint - StartPoint);
			html = html.Remove(StartPoint, EndPoint - StartPoint);
			int FormEndStart = html.IndexOf("</form>") - 1;
			if (FormEndStart >= 0)
			{
				html = html.Insert(FormEndStart, viewstateInput);
			}
		}
		writer.Write(html);
	}
}

The important line to look at inthe final piece of code is 37 as this is the line that looks for my first piece of html code. In this case it is looking for a div tag with id of ‘wrap’ i.e. ‘<div id=\”wrap\”>’. As you can see I have had to escape the double quotes with a backslash.

The final piece to the puzzel is changing your page to inherit this class which is done inside the code-behind,

1
public partial class MyPage : PageOverride

Now I know that there better ways to implement the code to make it automatically sort itself out by building it within a DLL and then implementing it within the web.config, but for what I do and it is highly possible that I may want to alter it at some point so its best being accessible at this point.

Line breaks are removed in posts made in plain text format in Outlook

Now this is a problem that I am sure most people using outlook would have seen from time to time and the official explanation can be looked into and the resolutions. The other side to this is if you are a systems administrator that is creating automatic email signatures in Microsoft Exchange and this problem is occurring where you are simply listing off some company details as shown

Company Name
Address 1
Address 2
Address 3
Telephone Number
Website URL

This could potentially come out like

Company Name Address 1 Address 2 Address 3 Telephone Number Website URL

Now from what I have worked out the reason for this is that Outlook is thinking that the pieces have been split up on to separate lines by accident and is trying to re-construct the line. Taking all this into account the idea that a full stop at the end may help Outlook to realise that these are multiple lines and not one that has been split up. Sure enough this seems to have done the trick so you now end up with a signature that looks like

Company Name.
Address 1.
Address 2.
Address 3.
Telephone Number.
Website URL.

Now although this is not ideal and makes some text look funny it does solve the problem. Not all lines are affected with this problem so use sparingly and you may find that only a couple of lines need fixing and it will not look too bad.

Bish, bash, bosh. Done

Add more images to Header Image list in Twenty Ten WordPress theme

Well what better way to start off then an issue that i had while setting up this new site.

I like the twenty ten theme that comes with the version 3 of WordPress and the features that it incorporates but one thing that I wanted to do was add another image to the list of selectable header images.

Firstly I thought that it would be as simple as adding the full size image and thumb image within the ‘images/headers/’ directory, assuming that once the two images where introduced into the folder the system would automatically pick them up and hay presto they would be selectable. This unfortunately was not the case so I started digging round the files within the the theme directory and the functions.php file was thankfully my first port of call.

The functions.php file contains lots of the custom hooks and stuff that the Twenty Ten theme introduces so this is what you need to do to add more images to the listing.

Open the functions.php file and locate the line that starts,

register_default_headers

Once you have this you need to replicate the chunk of code that creates each individual image. For mine I was adding an Autumn image so I added the following code into the top position so that the images appeared alphbetically,

'autumn' => array(
    'url' => '%s/images/headers/autumn.jpg',
    'thumbnail_url' => '%s/images/headers/autumn-thumbnail.jpg',
    /* translators: header image description */
    'description' => __( 'autumn', 'twentyten' )
),

My images where already in the correct directory from my first attempt but that’s basically it and thankfully, for me, easy to do.

Bish, bash, bosh. Sorted.