Head.SmackOnTable();

Contains Nuts.

Output all properties for any object

without comments


private void outputValues(object inputObject)
{
List<PropertyInfo> propertyInfos = new List<PropertyInfo>(inputObject.GetType().GetProperties());

foreach (PropertyInfo info in propertyInfos)
{
try
{
object obj = info.GetValue(inputObject, null);
if (obj == null)
{
continue;
}
Console.WriteLine("[{0}]:{1}", info.Name, obj.ToString());

}
catch (Exception)
{
continue;
}

}

}

Replace the Console.WriteLine with whatever you want, log4net,  Debug, trace, etc, and it works!

Written by Monty

July 22nd, 2009 at 9:51 am

Posted in Code Snippet

Tagged with ,

Clearing FK’s and tables from database

without comments

SELECT 'ALTER TABLE ' +  OBJECT_NAME(f.parent_object_id) + ' DROP CONSTRAINT [' + f.name + ']' FROM sys.foreign_keys AS f INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id
union all
SELECT 'DROP TABLE '+ name FROM dbo.sysobjects WHERE (type = 'u') and name != 'sysdiagrams'

Written by Monty

July 14th, 2009 at 4:45 pm

Posted in Misc

Curiosity

without comments

Iv recently come across this rather … strange custom in the US navy, where an aircraft would land at the wrong aircraft carrier during a war – either because it got disoriented, or because it ran out of fuel (or, the pilot is a moron), with some hilarious affects:

(Click for larger images)

^ is rather … worrying, im not sure what other ships will think if they see the Russian hammer and sickle on the tail?

The sheer amount of effort and work that went on this plane is just hilarious – “Must be airforce”, I wonder what would happened when this pilot got back to his own ship ?

Written by Monty

June 28th, 2009 at 2:15 am

Posted in Image Post, Misc

Tagged with

Politics and expenses

with one comment

I don’t normally write about politics, because its usually such a controversial topic, and I tend to piss people off easily enough anyway, but the whole current expenses row really gets my goat.

They are elected by the public, to serve the public, but unfortunately, they do not see it this way. They see them selves as the elite, they see them selves above us “dirty commoners”, they are better than us. They believe there is one law for them, and another law for us. The whole expenses row has proved this to be correct.

Take the last Home Secretary, someone who was in charge of Anti terror legislation. She admitted to smoking cannabis in the 80’s, and warns people that they shouldn’t smoke cannabis because it will lead to mental health issues, this the day after she was appointed  as the head of the govt review of the UK Drugs strategy.

Smoking cannabis is a CRIME in the UK, so our (former) beloved Home Secretary is a *CRIMINAL*. She has committed a  CRIMINAL OFFENCE (And no, the Misuse of Drugs Act has no statute of limitations)

One of the anti terror strategies was to link, basically everything to terrorism. They have linked photographers to terrorists, something that would be done under the Home Secretary. Another thing that they have linked to terrorism was the fact that drugs will fund terrorists. So, Jacqui Smith has supported terrorism, and should be arrested under her very own Anti Terrorism Act, and held for 42 days without -food-charge.

She has stated :

“If you can’t live by the rules that we live by, the standards and the values that we live by, we should exclude you from this country and, what’s more, now we will make public those people that we have excluded”

Well, CLEARLY, by smoking a Class B drug, you have committed an offence under the Misuse of Drugs Act,  which the penalties lie from 3 months to 5 years in prison – why has she not been prosecuted, or arrested for this offence? I say prosecute her, throw her in jail, then deport her. Good luck finding a country to take the old hag though.

Then there’s the whole fiasco with the ID cards, no one wants them, it WILL NOT PREVENT TERRORIST ACTS (Madrid bombings – they had ID cards then) – and the govt make ridiculous claims such as “Its a SECURE form of identity” – Oh really? Like the countless MOD laptops “forgotten” on trains or left in pub car parks, details for 25 MILLION child benefit claimants’, 3 million learner driver’s details also “misplaced”, on top of that, 45,000 peoples names, dates of birth, and national insurance numbers of people claiming benefits in York, which also has been “misappropriated”.

And lately, the whole expenses row’s – our beloved Jacqui Spliff was caught watching pornography, not once, but twice, and tried to claim it on our expenses, which come out of my and your taxes. That’s great, does that mean I too can watch pornography, and it come out of tax payer expenses? No? That’s not fair!

And lets not forget the DNA debacle – 17 senior judges across Europe have ruled that keeping DNA after not being charged is ILLEGAL, and HAS TO STOP, and the -Nazi Government-British Government has agreed to keep DNA and fingerprints for 6 years.

Do you really trust this government, who have, repeatedly, over and over again, shown disregard for the law, and everyone’s rights, and only look out for themselves, and try to screw everyone over?

Written by Monty

June 18th, 2009 at 10:00 pm

Posted in Misc

Evolution of communications

without comments

Iv been asked this question a few times when being interviewed about what I like about the internet – and one of the main things I respond with is the evolution of communications. Long gone are the days where you have to wait weeks to hear back from a friend on the other side of the world, where you have to carefully plan the time zone differences and risk calling someone on another continent when they might be asleep / waking up / not at home.

Nowerdays with RSS Feeds, twitter, Facebook, Myspace etc, you can keep up to date with all the latest goings on, while your at work, while you walk down to the shops, while you travel across the country on a train. Online communications has revolutionised the way news is broadcast across the world – no longer do certain news publishers say they have “exclusive” information – like the Mumbai terrorist attacks – updates were sent, on average, every 5 seconds regarding the attacks.

Twitter seems to have attracted a bunch of celebrities, from Alan Carr (@AlanCarr), to BoJo (@MayorOfLondon) – which breaks down another barrier when following your favourite celebrity, which in my case is Lance Armstrong – I no longer have to scour the net, seeing if he has appeared anywhere, I no long have to stay up till 3am watching Eurosport 3 reruns of the Giro d’Italia to see if he won it and where he placed, I can simply read his Twitter stream, and watch a few of his pre race video’s. I can get (near to) live updates on what he’s upto, and a bunch of other people I follow.

The social media phenomenon also breaks down a few other barriers – I no longer look at Paramedics with fascination and wonder “What is their job REALLY like?” – I read a bunch of medical blogs, from Random Acts of Reality (Tom, if your reading this, you are my hero <3 ) to NeeNaw – and its such a great insight into something that everyone takes for granted. I have alot more admiration and respect for the public services, after reading the amount of crap they have to deal with, especially from drunk / drugged up members of the public.

There are down sides to this evolution of communications though – I am now less “pro active” when it comes to communicating with friends, to see what’s going on with their life. For the friends I have on Facebook, I just load up the Facebook homepage, and see what’s the latest goings on with them. I no longer need to write to my friends (who are on FB at least) and ask them how they are doing, and what iv been upto lately – its all on my stream, in pretty much as real time as I care to update it.

I still love this evolution of communications though. Everything is interlinked, everything is in the now.

Written by Monty

June 2nd, 2009 at 12:41 am

Posted in Misc

Tagged with

My dev setup

with 5 comments

Well iv seen hundreds of posts such as “This is my Firefox setup” and “This is my Visual Studio Setup”, but not many that is, well basically, everything…

First off, this is my desk. Its a cheapo Ikea corner table, that fits. Iv got a bog standard mesh chair, from Ebuyer, for about 60 quid.

My hardware / desk setup:

  • Custom built Monster:
    • Quad Core Processors
    • 8gb of the fastest DDR2 ram that was out
    • Dual 500gb HDDs
    • Dual DVD writers
    • 2 monitors – one 20″ widescreen, one 19″ bog stanard, both Iiyama’s (I know i have 3 on my desk, the 3rd one is hooked up to a temp pc)
  • Sennheiser HD 465 Headphones – very comfortable, fairly cheap, I wear them for hours a day with no problems
  • A small “localised” lamp from Homebase, useful for looking at small things
  • MS Natural Keyboard
  • Microsoft Laser Gaming Mouse 6000 – Its a lightweight mouse, the last thing you want is a big heavy mouse to move around all day.
  • A speaker / subwoofer setup, from Ebuyer, for about 10 quid – for when headphones arnt good enough (probably not recommended for offices!)
  • At the bottom of the picture is a fan, for when I get hot, yeah baby! ;)
  • Im not sure why my laptop was sitting on my desk…ignore that.

My “misc” software setup:

  • Running Vista  SP1 – im tempted to run Windows 7, but not anytime soon, im just getting used to Vista!
    • UAC is disabled on Vista – its the FIRST thing i do when installing vista on a box!
    • IIS7 and management tools installed.
  • Hostsman – easy editing of your hosts file for testing
  • Winamp – for music! You cant code without music!
  • Windows Clippings – easier to use than other screen grabbing software, very lightweight, very very good, deffo worth the $18! Has useful features like timers and ability to send to clipboard etc…
  • MSN Messenger / Skype – I know some companies dont like it when their staff play around on IM, so dont abuse it – its saved my skin a few times when iv had trouble, and its less intrusive in the office than annoying someone
  • WinSCP – freeware FTP / SFTP/ FTP over SSH client – covers pretty much any server you need to connect to, its free, and it just beats all other FTP clients hands down.
  • Ultramon – you get a 2nd taskbar for your 2nd monitor, so basically only the stuff that is running on that monitor is on the taskbar.
  • Microsoft Outlook – I have outlook running for my email – its easy to use, very straight forward, and quite cool with exchange.
  • Daemon Tools Lite – when you have to mount ISOs without burning them, useful for .iso files downloaded from microsoft / off network shares.
  • Microsoft Virtual PC 2004 SP1 – free software from MS, basically allows you to run virtual pc’s – useful for running XP off a virtual machine (Crappy versions of IE, anyone?) – although I had problems installing debian on it, so im looking into running VirtualBox
  • Firefox – better than IE by MILES. Have loads of plugins, such as Web Dev toolbar, firebug, greasemonkey, firephp, Fission (cool loading bar thing), IE Tab, Its All Text (You get a cool little “Edit” button on text area’s that load it up in notepad), ShowIP (Shows ip address of server), AdBlock (blocks 99.99% of crappy ads), ColorZilla (picks colours out from page), Download Statusbar, Extended Statusbar (tells you pagesize, how long it took to load, etc).
  • Opera – because someone will complain that it dosent work in this browser
  • FeedDemon / Newsgator – Free software that sync’s with their free website, so you can still check your favourite feeds away from home. By far the cleanest, easiest to use, and best RSS reader there is.
  • Hamachi – Free VPN software that works behind firewalls, very very useful, esp when you have less tech savvy friends.

My dev setup:

  • Visual Studio 2008 Pro – Pro because you need at least that for integrated unit tests and Pex to run.
  • Codesmith Generator, with my own custom version of Nettiers code generator – WHY on earth would you want to write CRUD (Create, Read, Update, Delete) for your DB/objects over and over? Point this baby at it, and go baby go!
  • Resharper – Solution wide error highlighting BEFORE you hit the big compile button. Instant solution for alot of errors. Advanced intellisense. Advanced unit testing tools. Code clean up, inline code generation. Even does cool stuff like close your speach marks and brackets for you!
  • A White text on dark background colour theme like the image below – the last thing you want to do is look at retina scortching white screen for hours on end, it will do your eyes in, it really will.
    windowclipping-214
  • I tend to have Microsoft SQL Server installed on a virtual PC, so I can mimic the server environment – you can use the Microsoft Loopback Adapter to create your own private network – a hint, the 1.* ip address network (same for 2. all the way upto 9) is non routable, so feel free to use them for your virtual machines – i.e. my vps start off at 1.1.1.2 etc)
  • Not sure if this should go in Misc or not, but NotePad++ – iv replaced notepad.exe in window with this, and it works ACE!

Im sure I have forgotten something, so when I remember, ill add to this post. If you have any great ideas, lets hear them!

Written by Monty

May 21st, 2009 at 2:10 am

Posted in Misc

Tagged with

LAB: Image Detection, Part 3

without comments

After writing some comparison code, we have the following output, thanks to log4net (I love log4net):

output-3

Source


Target

.

X:79 Y:156 W:17 H:23 X:73 Y:149 W:17 H:23

.

X:337 Y:176 W:27 H:50 X:331 Y:169 W:27 H:49

.

X:158 Y:249 W:32 H:31 X:152 Y:242 W:32 H:32

.

X:446 Y:286 W:28 H:32 X:440 Y:279 W:27 H:32

.

X:398 Y:339 W:18 H:26 X:392 Y:334 W:16 H:24

.

X:244 Y:349 W:47 H:52 X:238 Y:342 W:47 H:52

.

X:38 Y:374 W:16 H:15 X:31 Y:366 W:17 H:16

.

X:34 Y:388 W:16 H:17 X:148 Y:423 W:27 H:24

.

X:154 Y:430 W:27 H:24 X:459 Y:435 W:24 H:22

.

X:465 Y:442 W:25 H:22 X:119 Y:450 W:30 H:46

.

X:126 Y:457 W:29 H:46 X:221 Y:465 W:17 H:19

.

X:227 Y:472 W:17 H:19 X:250 Y:594 W:17 H:18

.

X:256 Y:601 W:17 H:18



Comparison
S[X: 79, Y: 156, Width: 17, Height: 23] matched to T[X: 73, Y: 149, Width: 17, Height: 23]
S[X: 158, Y: 249, Width: 32, Height: 31] matched to T[X: 152, Y: 242, Width: 32, Height: 32]
S[X: 398, Y: 339, Width: 18, Height: 26] matched to T[X: 392, Y: 334, Width: 16, Height: 24]
S[X: 38, Y: 374, Width: 16, Height: 15] matched to T[X: 31, Y: 366, Width: 17, Height: 16]
S[X: 154, Y: 430, Width: 27, Height: 24] matched to T[X: 392, Y: 334, Width: 16, Height: 24]
S[X: 126, Y: 457, Width: 29, Height: 46] matched to T[X: 31, Y: 366, Width: 17, Height: 16]
S[X: 256, Y: 601, Width: 17, Height: 18] matched to T[X: 31, Y: 366, Width: 17, Height: 16]
Non matched
S[X: 34, Y: 388, Width: 16, Height: 17]
S[X: 154, Y: 430, Width: 27, Height: 24]
S[X: 465, Y: 442, Width: 25, Height: 22]
S[X: 126, Y: 457, Width: 29, Height: 46]
S[X: 227, Y: 472, Width: 17, Height: 19]
S[X: 256, Y: 601, Width: 17, Height: 18]
T[X: 148, Y: 423, Width: 27, Height: 24]
T[X: 459, Y: 435, Width: 24, Height: 22]
T[X: 119, Y: 450, Width: 30, Height: 46]
T[X: 221, Y: 465, Width: 17, Height: 19]
T[X: 250, Y: 594, Width: 17, Height: 18]

I know its not perfect, I know its only matching about 50% of the blobs, but im working on it. I have a plan up my sleeve for this :)

Written by Monty

May 8th, 2009 at 1:19 am

Posted in .NET, R&D Lab

Tagged with , , ,

var – Considered harmful

without comments

There seems to be a new phenomenon in the c#.net 3.5 world, where people are using the “var” keyword, because, well I’m guessing they are lazy. Take this example, what is MORE READABLE:

var sourceRect = new ComparisonRectangleContainer();

OR

ComparisonRectangleContainer sourceRect = new ComparisonRectangleContainer();

Now, I know that will be straight forward, you can see what the new type is, it will be a ComparisonRectangleContainer, but what happens when you use var when getting a response from a method, like the following:

var parallelCombiner = FirstPass();

Now, what does FirstPass return? Is it an IList<String>? No, I have to mouseover to find out:

image

Ok, so it turns out it returns an ImageParallelCombiner, the first bit of code does not make it clear.

You should always write code for HUMANS, not the compiler

The following is PERFECTLY valid c#.net code, but is it good code?

var @this = new @class();

@base.@stackalloc(delegate(@if @event)

{

if (!@return.@bool(@event)) return;

@is.@const(“S[" +@event + "] matched T[" + @return.@override(@event) + "]“ );

@this.@implicit(@event);

});

Note – you can prefix variable names with @ if you want to use a keyword – i.e. @class is a valid variable name, so is _ (underscore) – perfect if you want to make things as hard as possible for people to read it, like the “var” keyword.

Written by Monty

May 8th, 2009 at 12:58 am

Posted in .NET, Spleen Vent

LAB: Image Detection, Part 2

without comments

Warning – this post will be heavy on images, so if you are on a low bandwidth connection, well sucks to be you then.

With a few minor improvements to the code, here we have the Source image:

image

Here is the target image’s blobs:

image

As you can see, it has found both blobs, and here is the raw output for the blob data:

image image

They are very similar, only a few pixels out! Now to compare the images somehow…

Written by Monty

May 4th, 2009 at 1:25 pm

Posted in .NET, R&D Lab

Tagged with ,

Code Snippets – Text on images

without comments

Two code snippets for you:

private void drawTextWithBackground (string Text, Font font, Graphics grpaphics, Brush backgroundBrush, Brush foregroundBrush, int x, int y)

{

SizeF size = grpaphics.MeasureString(Text, font);

grpaphics.FillRectangle(backgroundBrush, x,y,size.Width, size.Height);

grpaphics.DrawString(Text,font,foregroundBrush,x+1,y+1);

}

private void drawTextAtBottom (String Text, Font font, Graphics graphics, Image sourceImage, Brush backgroundBrush, Brush foregroundBrush)

{

SizeF size = graphics.MeasureString(Text, font);

int y = (int) (sourceImage.Height – size.Height);

drawTextWithBackground(Text,font,graphics,backgroundBrush,foregroundBrush,1,y);

}

Does exactly what it says on the tin!

Written by Monty

May 4th, 2009 at 1:13 pm

Posted in .NET, Code Snippet, R&D Lab

Tagged with ,