Saturday, June 19, 2010

Fixing N95 8GB keypad and save yourself money!

Problem: My N95 8GB keypad stopped working and just broke into pieces, cost for some one to fix it, £30-£40.

I'm a cheap bloke, so I decided to fix it, this is how I did it!

Firstly, I looked for a new case this is called "housing", so ebay time.


Ebay search for N95 8GB


It took about 3 weeks for the delivery and it was about £3.50 and from Hong Kong! (How do they make money?) I bought a White one to make it look sexy.

It should come with the Torx 4/5/6 tools, for you to dismantle your phone, i.e. the for the screws that look like stars.

This is probably the best video

http://www.youtube.com/watch?v=jc33lBQzVy8

I just did it myself, I then found I needed to get a new membrane for £8

Ebay search for N95 8GB Membrane

I then replaced it, so for under £15 I managed to fix my keypad, get a new case and learn how my phone goes together.

This post is shorter but it took me a while to find what I needed and get replacements and keep my phone working till I get my HTC Desire!!

Wednesday, June 16, 2010

Getting HTC Desire working with ADB

Got an HTC Desire, I tried installing the Drivers with the Android SDK, it wouldn't work, I first had to enable USB Debugging.


Settings -> Applications -> Development -> USB Debugging


Plugging it in, it wanted to install ADB (Android Debug Bridge)I first tried updating the .inf file


;HTC Desire
%SingleAdbInterface% = USB_Install, USB\VID_0BB4&PID_0C87
%CompositeAdbInterface% = USB_Install, USB\VID_0BB4&PID_0C87&MI_01



This made it install. Yay!
But, running adb devices in the tools folder of the SDK showed it wasn't working.

I then looked on HTC Site for Drivers and found the HTC Sync here:http://www.htc.com/www/support.aspx



Downloaded installed it and then removed the Device and added it again.
adb devices then showed it and Eclipse then saw it.
Yay!


Friday, June 04, 2010

Bitmap Serialize

So I've been tasked to fix a database full of pictures that weren't displayed, no matter what I tried, the Image (Stored as a byte array) was always invalid.

So I thought I'll save the file and see if I can get an image fixer on it, I just used a FileStream opened it and wrote to it


var fileStream = new FileStream("output.dat", System.IO.FileMode.Create);
fileStream.Write(bytes, 0, bytes.Length);
fileStream.Close();


Upon opening the file, I was expected to see something beginning with "Exif" or "JPG" or something, but what I saw was even better.


System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a


A, ha!! The actual Bitmap object was being saved, not the actual Image, therefore I put together a bit of code to get me the Image and put it back as the Image for my code to work correctly. In this case, I could fix it, but if I couldn't I'd have to have a bit of a legacy converter for it.



public static Bitmap BitmapObjectToBitmap(byte[] data)
{
using (var ms = new MemoryStream(data))
{
var bf = new BinaryFormatter();
Bitmap bitmap = (Bitmap)bf.Deserialize(ms);
return bitmap;
}
}


Then the working code for the Image to Byte Array



public static byte[] ImageToByteArray(Image image, ImageFormat format)
{
using (var ms = new MemoryStream())
{

var bm = new Bitmap(image);
bm.Save(ms, format);
return ms.ToArray();

}
}



Comments welcome!!

Transfer Data between two SQL Server's

Everyone probably knows this, but hey ho.

I needed some data from one of my tables in one server to be inserted into another, here is the simplez SQL to do it.




insert into Server1.Database.dbo.Table(Col1,Col2,Col3)
select Col1,Col2,Col3
from Server2.Database.dbo.Table



Edit:
thanks to @duncansmart just a bit more info, I'm running on 2008 R2, on previous systems you may need to run


Execute sp_addlinkedserver Server1


To link in the other Server

Monday, May 24, 2010

Facebook Privacy Checks

Here is a list of Facebook Privacy scanners I've found.

1.) Save Face by Untangle is an automated script that will go through your settings and disable them.

http://www3.untangle.com/saveface

All you have to do is drag it on to your Bookmark toolbar for later.

2.) Reclaim Privacy, which is a scanner which gives you a breakdown on which settings / info you are leaking to the internet, as 1.) you just need to drag the bookmark on to your bookmarks toolbar.

http://www.reclaimprivacy.org/

Now you should log in to Facebook and click number 1, it will automatically go through your settings. (Easier to turn on Info then turn it off in my books)

Now click number 2, then update any settings it tells you to. Some I leave public, such as "find me via search" and "send me a message" set to everyone.

Now once you've done that we have another link to click.

3.) Profile Watch, this will scan your profile as an external person could and will show you info you are still showing the world.

http://www.profilewatch.org

4.) Honourable mention is an Application, so this shows you what your Apps can see about you and send to people.

Privacy Check

http://www.rabidgremlin.com/fbprivacy/




Hopefully this helps everyone!

Wednesday, May 19, 2010

InvalidateRequerySuggested on GUI Thread

I've been having issues where buttons weren't getting enabled on my WPF application, only by clicking the form would they work.

I found that I need to force the refresh using CommandManager.InvalidateRequerySuggested but that didn't work, the reason being I wasn't on the GUI Thread, I was on another thread, so here is my little helper class to do it.


public static void RaiseInvalidateRequerySuggested()
{
Dispatcher dispatcher = null;

if (Application.Current != null)
{
dispatcher = Application.Current.Dispatcher;
}

if (dispatcher != null && !dispatcher.CheckAccess())
{
dispatcher.BeginInvoke(DispatcherPriority.Normal,(Action)CommandManager.InvalidateRequerySuggested);
}
}



This tries to get the application, then gets the dispatcher for the application, makes sure you have access, and then dispatches the Invalidate to that thread.

bingo.

Tuesday, May 18, 2010

Dieting for Programmer

Right,

I've decided to do a post on dieting, not exactly technical but very much of the, "Healthy body, Healthy mind" manta, so my history, I used to be nearly 16 stone so I'm not from the "always been thin, eat what you like" bunch of twats most diet people are.

So here is my diet plan / life plan thing.

Firstly, we need to work out our BMR (Basal Metabolic Rate) basically the amount of calories you'd burn by sitting still all day.

http://www.bmi-calculator.net/bmr-calculator/

So I'm going to take me as an example, I'd probably over weight currently due to being on a bulk, long story my figures.

Age: 24
Weight : 13 stone, 1 pounds
Height: 6 foot, 2 inches.

(Hint: 14 pounds in a stone for all you cool metric kids)

( 13 * 14) + 1 = 169 lbs

my BMR = 1895.47

Now we use Harris Benedict Equation to work out our calories

http://www.bmi-calculator.net/bmr-calculator/harris-benedict-equation/

Since we're programmers, * 1.2

My calories for a day should be 2274.564

Now, in order to lose weight, we need to create a deficit, so the recommended number I feel is 500 calories, anything more, your body thinks its being starved and will hold onto your fat and not let go. It think its in a field starving and needs to keep you warm till you find an animal to eat.


So our Dave's Daily Diet Allowance is.... 1774.564(we're going to round it up for ease of use.) 1800 calories.

Now if you get any good food you'll see your RDA (recommended daily allowance) of what to eat, the average man is 2500 calories and each woman is 2000 calories. so if I stuck to it, I'd be putting weight on if I sat around doing nothing all day.

Type Male Female
Calories 2500 2000
Protein 55g 45g
Carbs 300g 230g
Of those carbs sugar 120g 90g
Fat 95g 70g
of that fat, Saturate 30g 20g
Fibre 24g 24g


So here are your RDA off the side off a Cornflakes packet! :), so here we have our aim, since you are probably eating more than your need you need to try and curb a little bit off this list too. So just try and keep within your boundaries and just count calories for now.

Time for the diet. I know from before we have 1800 calories to play with over the course of the day, time to split it, you should refine this to how you live, but you always must eat something at the times



  • Breakfast - 8am - 500 calories

  • Snack - 11am - 100 calories

  • Lunch - 1pm - 400 calories

  • Snack - 4pm - 100 calories

  • Dinner - 7pm - 600 calories

  • Snack - 11pm - 100 calories



Now that is my breakdown for my calories, I've give myself the most calories for my main meals, your main meal of the day is your breakfast. Skipping this is the worst mistake for your diet, it starts your metabolism kicks it into gear!

Now a sample diet


  • Porridge - Main stay of dieters, keeps you full for longer, since its a complex carb (takes a while to breakdown, simple carbs is sugar which takes minutes rather than hours

  • Apple + Skips

  • Chicken Salad with lots of trimmings or Soup and bread or jacket potato

  • Handful of nuts, Almonds are meant to be the best, full of protein

  • Lamb chop and lots of vegs and mash

  • Cottage Cheese and ryhvitta, cottage cheese is a slow releasing protein, so makes your metabolism work while you sleep





So that's a sample day, now all you have to do is tailor the diet to your calories, the foods you like and your lifestyle.

Keep a food diary for a week See how many calories and such you are eating, doesn't have to be 100% accurate, but gives you an idea where you are eating the worse!

If you feel you are snacking and want more food, increase your calories. This diet is meant to be one you're on for the rest of your life, not a quick fad one.

You are allowed one cheat meal a week make yourself feel bad when you eat it, thinking of the calories etc! But enjoy it, know that its bad for you etc.


Regarding food things I've learnt.


  • Anything with Hydrogenerate Fat avoid like the plage, seriously.

  • Eat protein!! It fills you up and your body works harder to digest it

  • Omega 3 1000mg capsules are amazing, ASDA sells them, eat at least 5 a day

  • When hungry drink a pint of water and wait 20 minutes, then see if you are hungry

  • Any exercise is better than none, don't over do it, or you'll get pissed off and stop

  • Don't let anyone say, "you look good as you are"

  • Weightwatchers meals are pretty nice!





So that's it, any comments would be grateful and I'll update the post if I need to!

Hope I haven't rambled too much!

Monday, May 17, 2010

GPS Degrees, Minutes, Seconds to Decimals C#

I have been trying to connect to a device and get the GPS Data, I was using the library provided by Microsoft's Coding4Fun.
http://blogs.msdn.com/coding4fun/archive/2006/10/31/912287.aspx and written by Scott Hanselman... how can he be wrong!?

The issue I came across was the precision was out by quite a bit, so the parsing was incorrect, for my device. I'm not sure if NMEA standard is 100% standard, so I'm just posting this code here in case other people have issues.

ProcessGPRMC and ProcessGPGGA both need to be updated, I have created a method to do this.


private static double DDMMSSToDecimalDegrees(string data)
{
var ddmmss = (Convert.ToDouble(data) / 100);

var degrees = (int)ddmmss;

var minutesseconds = ( (ddmmss - degrees) * 100 ) / 60.0;

return degrees + minutesseconds;

}



There is also the issue to do with North, Southern, Western and Eastern Hemisphere where the value has go to be negated. :)


So the update methods needs to look like this


public void ProcessGPGGA(string data)
{
try
{


string[] fields = Regex.Split(data, ",");

//Time: Hour, Minute, Second
//Time is Zulu
GPGGA.Hour = Convert.ToInt32(fields[0].Substring(0, 2));
GPGGA.Minute = Convert.ToInt32(fields[0].Substring(2, 2));
GPGGA.Second = Convert.ToInt32(fields[0].Substring(4, 2));

//Latitude

GPGGA.Latitude = DDMMSSToDecimalDegrees(fields[1]);


if (fields[2] == "S")
GPGGA.LatitudeHemisphere = Cardinal.South;
else
GPGGA.LatitudeHemisphere = Cardinal.North;


if (GPGGA.LatitudeHemisphere == Cardinal.South)
GPGGA.Latitude = GPGGA.Latitude * -1;



//Longitude

GPGGA.Longitude = DDMMSSToDecimalDegrees(fields[3]);


if (fields[4] == "W")
GPGGA.LongitudeHemisphere = Cardinal.West;
else
GPGGA.LongitudeHemisphere = Cardinal.East;



if (GPGGA.LongitudeHemisphere == Cardinal.West)
GPGGA.Longitude = GPGGA.Longitude * -1;



//GPS Signal Quality
GPGGA.GPSQuality = (GPSQuality)Convert.ToUInt32( fields[5] );

//Satellites
GPGGA.NumberOfSatellitesInUse = Convert.ToInt32(fields[6]);

//HDOP
GPGGA.HDOP = Convert.ToDouble( fields[7] );

//Altitude
GPGGA.Altitude = Convert.ToDouble(fields[8]);

//increase message count
GPGGA.Count ++;
}
catch(Exception e)
{
System.Diagnostics.Trace.WriteLine("Chaos in ProcessGPGGA! " + e.ToString());
}
}




public void ProcessGPRMC(string data)
{
string[] fields = Regex.Split(data, ",");


//Time: Hour, Minute, Second
//Time is Zulu
GPRMC.Hour = Convert.ToInt32(fields[0].Substring(0, 2));
GPRMC.Minute = Convert.ToInt32(fields[0].Substring(2, 2));
GPRMC.Second = Convert.ToInt32(fields[0].Substring(4, 2));

GPRMC.Day = Convert.ToInt32(fields[8].Substring(0, 2));
GPRMC.Month = Convert.ToInt32(fields[8].Substring(2, 2));
GPRMC.Year = Convert.ToInt32(fields[8].Substring(4, 2));

GPRMC.DataValid = Convert.ToChar(fields[1]);

//Latitude

GPRMC.Latitude = DDMMSSToDecimalDegrees(fields[2]);


if (fields[3] == "S")
GPRMC.LatitudeHemisphere = Cardinal.South;
else
GPRMC.LatitudeHemisphere = Cardinal.North;


if (GPRMC.LatitudeHemisphere == Cardinal.South)
GPRMC.Latitude = GPRMC.Latitude * -1;



//Longitude

GPRMC.Longitude = DDMMSSToDecimalDegrees(fields[4]);


if (fields[5] == "W")
GPRMC.LongitudeHemisphere = Cardinal.West;
else
GPRMC.LongitudeHemisphere = Cardinal.East;



if (GPRMC.LongitudeHemisphere == Cardinal.West)
GPRMC.Longitude = GPRMC.Longitude * -1;



GPRMC.GroundSpeed = Convert.ToDouble(fields[6]);

//TODO: MagVar and Course
GPRMC.Count++;
}



That's it for now, I haven't implemented the rest of the project. I'll post all the updated code when I get somewhere, github maybe?

Friday, May 14, 2010

Get WhoIs Information from a domain name in C#

I needed to get the WhoIs information for a domain using the simplest way possible.

I could have used a WebService such as WebServiceX.net's http://www.webservicex.net/whois.asmx

But I decided to just talk to the whois servers directly, all I needed to do was open a socket send a request and then read from the socket.

I used the list from http://www.nirsoft.net/whois_servers_list.html then wrote some code, here is an example of how I did it for anyone that needs the information.




using System;
using System.Net.Sockets;
using System.IO;


namespace WHOISConsole
{
class Program
{
static void Main(string[] args)
{

string whoisServer = "whois.nic.uk";

string domainName = "bbc.co.uk";

Console.WriteLine(GetWHOIS(whoisServer,domainName));

Console.ReadKey();
}

///
/// Get the WHO IS Info for a domain name
///

/// The server to use, changes per domain
/// Domain we are looking up
///
public static string GetWHOIS(string whoisServer, string domainName)
{
// Port 43 is standard
using (var tcpClient = new TcpClient(whoisServer, 43))
{
// get the underlying stream
using (var networkStream = tcpClient.GetStream())
{
// we need to write to the stream
using (var streamWriter = new StreamWriter(networkStream))
{
// write the domain and a new line, CRLF
streamWriter.WriteLine(domainName);

// flush it to actually send it
streamWriter.Flush();
}

using (var streamReader = new StreamReader(networkStream))
{
// now read from the stream
return streamReader.ReadToEnd();
}

}
}

}
}
}





Any comments please post below. Thanks.

Remote Desktop Sharing Files

With remote desktop the way to share files is via the Local Resources tab, you can then select a drive.

This can be tiresome as you would have share a whole drive over the Internet / Network, the workaround I use, is to create a Mapped Drive to the folder I want to share.

I then share that mapped drive, this means I don't have to wait while all the data is sent, so it makes it very fast.

Not sure why MS can't just support single file send like VNC.

Edit: Thanks to smellyhippy from irc.freenode.net #c##, you can just use copy and paste, I was trying drag and drop.


I have also allowed anonymous comments. :)

Wednesday, April 28, 2010

Agent Killer - DirectX Game

This is a game I made for my final year of Uni, I'm releasing it cos its hilarious! I'm going to fix the code, make it run with XNA and OpenGL I think.



Download

You'll need a decent card I think to get it running, it *should* work.

Have fun!

Sunday, April 25, 2010

//TODO

Well here is a list of things on my to do list, of things I'm planning on doing or looking at, I will be updating this as I complete them

Books to read


  • Art of Unit Testing

  • DDD

  • Applying DDD with .net

  • Code Complete 2

  • Pragmatic Programmer

  • Working Effectively with Legacy Code

  • Passionate Programmer

  • Mythical Man Month



Things to Do


  • TASM Series

  • Ruby for the C# Programmer Series

  • Dissecting Malware

  • Design Patterns Series

  • Dieting for Programmers!



Projects


  • Finish Website sarkie.webhop.org -27-April-2010

  • Restart the blog-07-April-2010

  • WPF Auto Follow Friday

  • OpenRASTA site checker devserver.webhop.org - 16/05/2010

  • Ruby CD System

  • Virtua Tennis Savegame Editor

  • DirectX Game, rebuild and update

  • XNA Breakout Game

  • OpenGL Breakout Game

  • Abstracted Game using DirectX, XNA and OpenGL

  • UnrealScript Mod

  • Source Engine MOD, USEMP



That's it for now, I'm sure I'm forgetting loads! But that's enough to start me with, anything else I'm missing?

Saturday, April 24, 2010

Links, Precedence, Style-sheets, Oh my.

So I am currently developing my site and I wanted links to be different to my overall colour scheme for links. I therefore added a page style sheet to change them, no matter what I did, the overall one would take precedence instead of the page one.


a:link, a:visited,a:hover, a:active
{

text-decoration:underline;
color:#FFFFFF;
}



So I wanted to change it to just white underlined, this was first too over kill, since it was changing links in the footer. I then made it class based


.projectList a:link
{
text-decoration:underline;
color:#FFFFFF;
}


This still did not work for some reason, firebug showed my Site.css was winning now. (odd)

Thanks to ye-old faithfull W3Schools
I found :link pseudo classes http://www.w3schools.com/css/pr_pseudo_link.asp


This meant I could change it per link basis, (win) I now had.


a.downloadLink:visited
{
color:#FFFFFF;
}

and my link

Download



Now it bloody works!! :)

Friday, April 09, 2010

XML to PDF using NFOP, C# .NET

I was using this

http://www.codelathe.com/blog/index.php/2009/02/28/generate-pdf-from-cnet/

Don't download the 1.0 build version

Get the 2.0 version source

http://sourceforge.net/projects/nfop/files/nfop/nfop-v2.0.0/nfop_fw2-2.0.0.zip/download

and get the .dll out of the build dir, or you will get lots of manifest errors and such

Thursday, April 08, 2010

Chrome User Agent

Since I can't access my banking website with Chrome but I can with safari, this is how you change the User Agent easily

Make a .bat or .cmd file open with notepad and paste



start chrome --user-agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Version/3.1 Safari/525.1"

Wednesday, April 07, 2010

WMV C# Meta Information Update Example

I have recently downloaded all the www.dimecasts.net Videos, I then tried to play them on my Xbox, but they weren't in order, so made it quite hard to follow. I therefore created an App to edit the WMV titles, which the Xbox reads.

This code is "ok", I should really make the code into a wrapper library, but this is just a bit of a proof of concept really.

Firstly, you need to add the WMP.dll to the form using the Toolbox, which should appear as the Windows Media Player Control, it will then add two references

AxWMPLib
WMPLib

Then the main code for getting the Meta Data is



private string GetTitle(string filePath)
{
var mediaPlayer = new WindowsMediaPlayerClass();

IWMPMedia mediaItem = mediaPlayer.add(filePath);

return mediaItem.getItemInfo("Title");

}



I got all the attribute names running code like this



for (int i=0; i<mediaitem.attributeCount; i++) {
Console.WriteLine(mediaitem.getAttributeName(i) + " = " + mediaitem.getItemInfo(mediaitem.getAttributeName(i)) );
}



The code for setting it also very simple




private void SetTitle(string filePath, string title)
{
var mediaPlayer = new WindowsMediaPlayerClass();

IWMPMedia mediaItem = mediaPlayer.add(filePath);


mediaItem.setItemInfo("Title", title);
}




Here is the source code:
http://sarkie.webhop.org/Files/WindowsMediaEditor.zip

Tuesday, April 29, 2008

Famous?

After having a number of emails with Jeff Atwood last year, I hinted about having a book of Programming Books which most programmers have, I think I coined it a "programming porn pile".

Today Jeff has added it to his blog, so therefore I am famous on the Internet Tubes.

http://www.codinghorror.com/blog/archives/001108.html

Sunday, December 30, 2007

Internet Explorer 7 Problems

If after some recent updates December-07 the following errors occur.
  • User Accounts is not accessible : MSHTA / Script Errors
  • You cannot access HTTPS sites
  • Others probably
If these are the case, redownload Internet Explorer 7 redistributions and uninstall the current version and do a fresh reinstall, then get the single update from Windows Update, everything should be fixed. :)

Sarkie