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. :)