Saturday, April 25, 2009

Bill Hicks "Lost" Segment from Letterman

Well, I always mourned the fact that I didn't recognise Bill when he was on The Word, that I never got a chance to see him play or that I returned a CD, received by accident, to Amazon of his live show. Apparently, David Letterman regrets things too; And well he should, as this piece is truly amazing, though much will have been re-used elsewhere - Lettermen finally decided to show Bill's set from his controversially cut show in October, 1993.

I really have never had respect for Letterman, but this raises the bar, though I can never quite get rid of the creeping discomfort I always feel when I see him interview someone, as though his inate Americanism is half a step away from massive, embarressing faux par.

Check Bill's site out here: http://www.billhicks.com/index.html


Rest In Piece and fucking Rock On Bill.

Friday, April 24, 2009

A very cool list...

This little flickr entry lists some amazing uses of google maps and earth, I just had to blog:

Latest LifeHacker Links

Some really awesome links here from LifeHacker today:

Oh God The Horror

What do you do when the virus breaks out and zombies start munching your friend's head? Damned if I know, but fortunately, big brains have been working on the issue - presumably to keep themselves at thir respectable size...
All found via:

Thursday, April 23, 2009

Friday, April 17, 2009

Workstation UnLock

For a long time now, I've been looking for a way to unlock a Windows computer programmatically. I'd like to be able to write a service, for example, which can unlock the machine and log in a user, rather than a session (which has no visible affect on the running screen), but simply logging back in the current user would suffice. Frankly, anything would do. There are many uses for this type of code, but my initial thrust was to develop a bluetooth app for my Windows Mobile device which would log me back into my machine when I walk back into range - a simple device detection app on the host machine; doesn't even have to communicate.

So far, I have been greeted with false starts, low-level C++ code (which, for me, never developed to full-fledged Windows coding) and basically tonnes of code which never claimed to work properly.

So, here I am going to log my efforts and record links to resources which might, probably won't, but might prove useful at some point:

Small Post About MVC

Looks like there's some movement in the ASP.NET MVC market, finally, so lets get some links up:
Some MVC resources:

Friday, April 10, 2009

P2P What I/You Need To Know

Ok, first off: If articles like this http://lifehacker.com/371653/caught-downloading-copyrighted-materialnow-what or this http://gizmodo.com/5066280/almost-half-of-net-traffic-is-not+so+legal-p2p-and-itll-really-take-off-soon scare you, you should probably stop right here, uninstall whatever P2P software you have and signup for online Blockbuster or something (there are better services, not to mention the online ones!) because actually downloading potentially illegal files will scare the socks off you. That's not to say it's scary, difficult or even illegal - if done RIGHT.

Secondly, I'm not advocating sharing illegal files. I pretty much subscribe to this 'manifesto', if you will: http://i.gizmodo.com/5202399/a-pirates-code-of-conduct-for-bittorrent. Personally, I do not intend to break copyright laws, rip-off artists or content producers and I certainly intend to actively help struggling industries, like the British movie industry, because I want movie makers like Simon Pegg and Ricky Gervais to keep me entertained. If the niche, intelligent and truly original creators are supported we will be kept wallowing in Shakespearian quality media for a long time to come!

Having read recently the following articles on LifeHacker and Gizmodo:
I thought it would be appropriate to bone up on some P2P security and best practices. Not that I do P2P, of course. Having said that, it would be nice if the content providers out there were to realise that if they provide customers (ie: potential customers/file-sharers) with what they want they would instantly become loved and extremely rich and probably immediately end the global crisis (new jobs, lots of new customers, new shows - all would be possible tomorrow.)

For starters, on the subject of P2P file sharing, there is the whole security thing, which LifeHacker and Gizmodo have neatly covered in a reader friendly way:
Amongst those articles, you'll find useful links for things such as:
And finally, good information comes in all forms, and on the internet this means the best way to find up-to-date links. I like tagged articles on well circulated sites, for example:

Wednesday, April 01, 2009

More Augmented Reality

Found these links and just need to make sure I can find them again. Some C# code for augmented reality projects, most based on C++ though...

Online File Storage Services

I've been looking for online file storage sites. I intend to expand on this, but for now, here is what I've found:

Big name assumed reliable sites (multi-discipline):

More Gizmodo Favourites

Just some more favourites design to entertain, enlighten and enjoy...
First, the best of the best:
And now the favourites:

Tuesday, March 31, 2009

Friday, March 27, 2009

PC Upgrade Update

So this morning I finally got around to installing the 2GB RAM to replace the two 512MB sticks in my DELL Vostro. Everything seems to be running fine, no problems booting back up and the Crucial memory scanner seems to be telling me the RAM is installed just fine. One problem, XP Pro is only showing 3.25GB in System Properties. It's ok, though, I knew this would happen as XP can only recognise 3-3.5GB.

This I might have to step up to Vista ... ulp.

[EDIT:30/02/2009] Prompted by an anonymous comment on this post, I felt it wise to expand on my endevours, or at least provide some more information. Anon is indeed correct that 32 bit OS's are limited (as far as Windows goes) in accessing RAM...

Thursday, March 26, 2009

Wednesday, March 25, 2009

The Browser Wars Rage On

http://www.dearie6.com/

Yep, a lot of people hate IE6. I do too, but I don't have to work with it - that's for front-enders, or the "UX team". For those who are interested, the current browser usage:


Scary, eh? It was only September 2007 that IE6 was knocked off the top spot , but it's still hanging strong in third place. Why? Well, there are a lot of opinions and statistics will only get you so far. My opinion being that too many people are comfortable with it and don't know what a Web Browser actually is. Sounds crazy, but I often run into people asking how to use (insert website name here) as a product, as if it's installed on their computer - totally unaware that it isn't. The most common assumption (in my experience) that web-based email is only available on the home computer.

The issue there is lack of understanding driven by interest. As time passes this will dissipate and the general awareness of internet-based, or cloud-based, technology improves.

Another favourite statistic of mine is screen resolutions. A lot of managers request and designers still work to 800x600. I do not understand this. At all. Everyone, for years now, has been obsessed with bigger and better: TV's, cars, monitors, memory, money, etc. But...


So lets cater to the majority people, it's not hard, in fact it's easier. And the next time I see a page design where the content you actually wanted only takes a 1/4 column and 1/3 height of the page I swear I'll throw the machine out the window.

For developers out there, here's a interesting statistic:


I'm a C#'er, so it's encouraging and depressing in equal measure for me!

Rube Goldberg. I'm just going a little crazy this morning.




Monday, March 23, 2009

Sports drinks and regular exercise

I've joined a gym and in an effort to discover what really is good for me, in an of Average Joe kind of way, I looked up 'electrolyte'. This is something I've heard a lot of people mention is important in the body, something you lose when exercising and in 2010 the astronauts hated the taste of the eletrolyte replenishment drink. Anyway...

Links:
  • Electrolytes are solutions of acids or salts
  • They help the body conduct motor control electrical signals
  • Electrolytes are gradually lost during exercise
  • Only intense and extended exercise requires extra electrolyte replishment
  • Extreme exercise without replishment may result in overhydration
Ok, so lesson 1 here is that when you go to the gym or dojo (as is my preference) you won't need anything other than water, simply because your body is not losing enough electrolyte solution to need something like lucosade or gatorade. They are overkill and the extra sugar you're getting might be doing your teeth more damage than your body will otherwise gains in benefits elsewhere.

If you are involved, for example, in an Iron Man, Ultramarathon or even (as I will be) the London To Brighton Bike Ride for The British Heart Foundation you will need supplement drinks. If, however, you are simply "down the gym during lunch" (as I will be, also) you won't need anything more than water.

Saturday, March 21, 2009

Buying PC parts

Situation.

I now need new parts. I have a fairly decent PC mini tower from Euro PC where they sell reduced price DELL machines. Got a very good deal a year or so ago and it's treating me well. It has 3GB of RAM so I thought I'd put a bit more juice in as Crucial is offering 2x1GB sticks of compatible memory for only £22 all in. Good deal, I thought, so I got 'em.

Also, the monitor (as with the other monitor - I have two) is a fairly old CRT by MicroScan. It (they) was (were) the daddy(s) in it's (their) day (awesome image quality and a built in mic), but one has now pretty much shutdown (goes horribly blurry after a minute of use) and the second seems on the way out. The behaviour to note here is the occasional twitch of the screen, as if there is a power surge, causing irregular distortions on the screen, making it look like a mobile phone nearby is receiving a txt message, when there isn't.

So, having ordered the RAM (at silly-o-clock this morning) thought I'd do some proper research into monitors (and can have it verified later by my brother, who is up on his monitor KB, by virtue of his profession) and post some links here for buying and, more importantly, decoding the jargon around the tech specs.

I'm going for a big monitor because I think one large one is better for viewing quality than two smaller one's. This is born out by the fact that the seperation between the two monitors makes split screen movie watching cruddy, to say the least. I'm not going for a projector, because this is a PC I develop code on and I'm not mental.

Some useful links:
Places to buy:
Notes.

It's worth knowing that a high contrast ratio is good and a low one, obviously, is bad. This is because (if you look up the word contrast) the contrast ratio in monitors is the difference between the opposite ends of the colour spectrum. Meaning that if black is 1 and white is 20,000 then you have a contrast ratio of 20000:1 and it is better than 8000:1.

This only differs when you have a monitor with a dynamic range, usually printed as 8000:1 (dynamic). This simply means that the power output, and thus the brightness, of the pixels can be lowered, and thus dimmed, to give the impression of a darker colour. This makes sense because no lightbulb in existence can actually output "black". (American's are wrong when they refer to ultra-violet as "black light" - it's not black!) This can be a problem when a bright colour is near a dynamically dimmed colour, because the light edges will bleed into the darker areas.

It's also worth knowing that DSUB is the type of connector that monitors use, though this is not accounting for the number of pins. Therefore, if a monitor has a DSUB connector you can assume it is a standard VGA monitor connector.

Just for reference, here's what I decided to buy this morning...

Memory:

Obviously, this is not what everyone will need, as everyone's system is different, but I plumbed for 2 x CT763270 1GB, 240-pin DIMM Upgrade for a Dell Vostro 400 Mini Tower System from Crucial's UK branch.

Monitor:

I finally (verrrrry long decision process) settled on the Samsung SM-2433BW Cream 24" Widescreen LCD Monitor - Glossy Black by Novatech. Decent size, decent inputs and decent quality. Any less money and it would have started to be a bad monitor with a limited life. I believe the sweet spot for monitors of this size is £250+, though I think £500 is way too much, unless you're a graphics person (I ain't!)

Thursday, March 19, 2009

Getting the correct month, no matter the country

Recently I posted about localisation and today need to have a page work out a given month's index value (ie: 1-12) from a string. Because I'm developing the code in the UK and hosting it in the US, the localisation was mucking about with the handling of the DateTime.Parse() interpretation of the date string. I needed the code to handle the parsing as if it was in the UK, no matter where it's hosted.

In short, the answer is from a MSDN article: http://msdn.microsoft.com/en-us/library/bz9tc508.aspx

There are two methods, both easy, to use. The first is in the page's page tag (at the top), where the 'GB' forces things like datetime to use Great Britain formatting:

<%@ Page ... Culture="en-GB" ... %>

The second is in the web.config, again it's the GB:

<system.web>
<globalization uiCulture="en" culture="en-GB" />
...
</system.web>

Now, my code will render properly:

DateTime.Parse("01/" + Int32.Parse(month) + "/2009").ToString("MMMM")

Don't ask why I'm doing that, it's just necessary, is all.

I'm preferring the web.config approach, but it's perfectly valid for the page - just be sure to remember which pages use the setting. Obviously, this can all be set dynamically, but you'll have to read the MSDN pages for how to do that - this is just a reminder for myself and anyone who might run across my pages.

How to be productive...

A good question with some nice, simple, straightforward answers, which don't just apply to developers: http://stackoverflow.com/questions/645237/as-a-programmer-what-single-discovery-has-given-you-the-greatest-boost-in-product

I have lived this.

Wednesday, March 18, 2009

Totally Awesome - Real Digital Paper!

http://i.gizmodo.com/5173069/super-thin-flexible-oled-lights-to-be-available-in-2011

Looks like it's finally here! Digital Paper, or OLED sheets capable of displaying images like any monitor, but any a few millimetres thick.

Sunday, March 15, 2009

Microsoft links I have yet to read, but really should...

How Do I: Create a Breakpoint
Using Conditions?

How Do I: Create a Breakpoint Using Hit Count?

How Do I; Learn Tips and Tricks for Debugging in Visual Studio?

Office Development with Visual Studio Developer
Center Just Launched!

Microsoft Cloud Computing Tools

How Do I: Add Tool Windows to the Visual Studio IDE?

How Do I: Add a New Tool Window to Visual Studio?

How Do I: Integrate With the Error List?

How Do I: Create a Basic Language Service Using the Managed Babel System?

How Do I: Create Custom
Project Templates Using Visual Studio 2008?

How Do I: Create an Item Template Using Visual Studio 2008?

How Do I: Write to the Output Window?

Explore the New Features of Visual Studio 2008

How Do I: Create a Debugger Visualizer?

How Do I: Place My Commands Into Different Kinds of Visual Studio Menus?

How Do I: Add Commands
and Controls Into the Visual Studio IDE?

How Do I: Get Started with the VisualStudio Domain Specific Languages?

Heroes Happen Here
DotNetNuke® and Visual Studio 2008

Visual Studio Tip of the Day

How Do I: Add AJAX Functionality to an Existing ASP.NET Page?

How Do I: Debug a Windows Presentation Foundation Application in Visual Studio 2008?

How Do I: Use the LINQ-Enabled
XML API in Visual Studio 2008?

Some bluetooth resources. Rage.

Just some links to various useful sites for bluetooth...


There does seem to be a lot of niche interest in bluetooth, but MicroSoft are letting developers down by not providing a bluetooth API for Windows and Windows Mobile.  How beautiful it would be to create a solution with a couple of Win Forms and Mobile Forms app projects and use the same API in both to communicate over bluetooth, serial even IR.  But no.  There are even videos available on Channel9 where MS devs talk about the amazing work they've done using the MicroSoft C# bluetooth API but simply don't make any of the useful information available.  What's going on MS?  Is it because you know BT is destined for the bin?  And no, I don't consider the above link to Channel9 a productive one.  Is that really the best MS can for us?  Anil Dhawan's link is broken!

Gizmodo, gadgets and fun in the news...

Just browsing about today, I thought I'd post this as it's a bit of a laugh...


Photo info for creating high dynamic range images...


Mars!

Friday, March 13, 2009

Tips 'n' Tricks - Null Coalescing Operator

We all like the null coalescing operator (http://msdn.microsoft.com/en-us/library/ms173224.aspx), but it’s frustrating when we need to set the variable we’re returning rather than just returning it.

Really we just want to do this:

public class Something
{
private string falafel;

public string GetInfo()
{
return falafel ?? "tabbouleh";
}
}

But then falafel doesn’t get set.

This feels inelegant:

if (falafel == null)
falafel = "tabbouleh";
return falafel;

Luckily, there’s a solution:

return falafel ?? (falafel = "tabbouleh");

This first sets the value of falafel and then returns it.

Wednesday, March 11, 2009

Fun With GridView...

[EDIT: This is being posted now, but was started back in 2006, so might be a little out of date. My aim is to have no draft posts and this was too useful to delete.]

So I've been playing with databinding controls etc and trying to do things the easy way, I've discovered CodeSmith: http://www.codesmithtools.com/. Used in conjunction with NetTiers2: http://www.nettiers.com/ is a very powerful data access layer code generator.

Anwyay, todays subject, minor though it is, is GridView commands...
...I wanted to have a grid with a couple of buttons: Up and Down, as link buttons, to re-order my content without an edit button.

The solution is simple enough:
  1. Add a Button column to your GridView
  2. Set it's 'button type' to Link (this is optional really)
  3. In the GridView's events panel, double-click RowCommand
  4. In the generated event handler you can place:
    switch (e.CommandName) { .... }

Simple really.

Lastly, here's some resources I've been looking at recently:

  1. http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx
  2. http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx
  3. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASPNETProvMod_Prt5.asp
  4. http://www.ondotnet.com/pub/a/dotnet/2005/01/10/liberty.html
  5. http://www.odetocode.com/Articles/440.aspx
  6. http://www.asp.net/QuickStart/aspnet/doc/profile/default.aspx
  7. http://www.theserverside.net/tt/articles/showarticle.tss?id=CreatingProfileProvider
  8. http://flimflan.com/blog/ProfileView.aspx
  9. http://weblogs.asp.net/scottgu/archive/2006/01/10/435038.aspx
  10. http://www.asp.net/sandbox/samp_profiles.aspx?tabindex=0&tabid=1
  11. http://msdn2.microsoft.com/en-us/library/83y98ckk.aspx
  12. http://www.google.com/search?hl=en&lr=&q=aspnet_regsql+command-line+utility+&btnG=Search
  13. http://www.learnvisualstudio.net/
  14. http://www.asp.net/learn/absolute/default.aspx?tabid=63
  15. http://www.microsoft.com/uk/msdn/security/link_library.mspx
  16. http://weblogs.asp.net/scottgu/archive/2006/04/13/Source-Code-for-the-Built_2D00_in-ASP.NET-2.0-Providers-Now-Available-for-Download.aspx
  17. http://weblogs.asp.net/scottgu/archive/2006/02/24/438953.aspx

Caching and Url Mapping

Caching.

If you look at the line <%@ OutputCache... in the .aspx files you will see that it is configured to cache the output of that whole page for the value in the Duration attribute. The VaryByParam value indicates that any url parameter will cause the page to be re-generated and cached. Replace the "*" with "none" and the caching will ignore the url params and that page will be cached once for the duration.
The OutputCache can be used in individual user controls as well, however, if the page has a duration of 20 and the control within it has a duration of 10 both will be cached for 20. Reverse those numbers and the page will be cached for 10 but the control will be cached for 20.

Be careful that you don't try to reference in your code a control which may have been cached, as it will come back with a null reference, possibly causing an exception!
One other method of caching is substitution mapping, the drawback being that you can only point this at .net controls, not user controls.

Url Mapping.

Now, go to IIS, create a virtual directory under Default Web Site, point it at the Test solution's directory. Open the Properties panel for the virtual dir. Do the following:
Disable directory browsing.
Under Documents, enable default document and have only 1 default document called default.aspx.
Go back to Virtual Directory, click Configuration, click Add and enter:
1. Executable: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
2. Extension: .*
3. All Verbs
4. Script Engine ticked
5. Check that file exists NOT ticked
6. Click Ok, Click Ok.
Go to ASP.NET tab and ensure the ASP.NET version is 2.0.50727
Click Ok.
Now, when you browse to http://localhost/test/lose/ or http://localhost/test/win/ you should see the page come up which is actually /test/win.aspx or /test/lose.aspx. Hit refresh and you will see the time has not changed, because the page has been cached. The page appears, even though you have entered a directory name, because IIS is automatically adding default.aspx to any requested directory listing and redirecting all file requests to the .net framework. The .net framework is redirecting from ~/win/ or ~/lose/ to ~/win.aspx or ~/lose.aspx because in the web.config you have a UrlMapping block! Easy.

The only problem with this is that you can't use regular expressions to have, for example, ~/search/ipod/ re-mapped to ~/search.aspx?query=ipod which is annoying, but only because the next server version from microsoft will have a fully operational url mapper and they didn't have time to put it into the current release.

Links:

Caching: http://msdn2.microsoft.com/en-us/library/xsbfdd8c.aspx
Substitution mapping: http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.substitution(VS.80).aspx
Url Mapping: http://www.developer.com/net/asp/article.php/3581326
MS Blog: http://weblogs.asp.net/scottgu/archive/2005/11/14/430493.aspx

Tuesday, March 10, 2009

Tools List

Here's a list of tools which I use on a regular basis and would be a fixture of a Windows image, if I ever create one...
I had a slightly different list previously: http://springboardpillow.blogspot.com/2009/03/tools-list.html

Rubberduck Debugging

Got this from our work email, if you like "intra-mail"...

We called it the Rubber Duck method of debugging.  It goes like this:
1) Beg, borrow, steal, buy, fabricate or otherwise obtain a rubber duck    (bathtub variety)
2) Place rubber duck on desk and inform it you are just going to go over    some code with it, if that's all right.
3) Explain to the duck what you code is supposed to do, and then go into    detail and explain things line by line
4) At some point you will tell the duck what you are doing next and then    realise that that is not in fact what you are actually doing.
The duck    will sit there serenely, happy in the knowledge that it has helped you    on your way.  Works every time.  Actually, if you don't have a rubber duck you could at a pinch ask a fellow programmer or engineer to sit in.

A university in Canada I was told about many moons ago actually had a teddy bear sitting in the student admin's office. When a student wished to book in with a lecturer to discuss a problem they were asked if they'd explained their problem to the teddy bear. If they hadn't, they were told to do that first. This cut something like 80% of lecturer meeting requests from students.

Monday, March 09, 2009

ASP.NET Life Cycle Diagram

Just a quicky...  It's often nice to know what the steps are in the ASP.NET life cycle, as we all forget this (probably) easily and often, especially if we stop using it for a while...

So here is a link providing some good life cycle diagrams:

My favourites:

And one general use link:

He he he!

Creating a certificate in IIS

This is an easy one and really specific to developers who need to do this and only this, but essentially I found the answers by googling "SelfSSL" and "IIS certificate"...
You will need to do this if you want a website hosted in your local IIS which uses HTTPS.

[EDIT: 21/04/2009] If you need a network certificate from an online (or your company's domain) authority, you should Request a Certificate. Microsoft provide fairly easy instructions for this here: http://support.microsoft.com/kb/228821

If you can't locate SelfSSL.exe on your own machine, I've a compressed version you can download here: http://home.freeuk.com/eudoxus/selfssl.rar

[EDIT:01/04/2009] I've just located the download page for this, along with some helpful articles:
For a site I setup recently, I used the following line:
selfssl.exe /N:CN=mytestsite /K:1024 /V:1000 /S:30412573 /P:443 /T

Broken down thus:
selfssl.exe
/N:CN=(sitename - doesn't have to match anything)
/K:(certificate size in bytes)
/V:(expiration period in days)
/S:(site id, found by selecting 'Web Sites' in IIS and checking the 'Identifier' field on the right)
/P:(https port number, leave it at 443)
/T (adds the certificate to the trusted sites list)

Once this is finished, open the Properties panel for the website you've just added a certificate to and go to: Web Site -> Advanced -> Multiple SSL identities for this Web site

In this area you should see that the IP address is 'Default' and the SSL port is '443'. Double click this row (or select and click Edit) and replace the 'Default' IP address entry with the IP address of the web site you created.

This last piece means that when the browser goes to the site looking for a secure page IIS will direct it towards the same site, ie the same IP address, rather than the default (the machine address.) You could create two sites, under different IP's, one secure and one not, but that will make your site building harder as you'll have to cater for this in various ways (that I won't go into.)

Have fun.

[EDIT:18/03/2009] It is my experience (Windows 2003 Server R2, IIS 5.2) that occasionally IIS will need the certificate recreating. I don't know why, but I'll try to document it here if I find out.

[EDIT:01/04/2009] Just been sent this: http://support.microsoft.com/kb/260096
The issue being wrestled with here is that (since version 5.0) when IIS starts up it begins listening for all sites on ports 80 and 443 (standard web and SSL) for incoming connections. This is known as socket pooling. This means that only the first site with SSL (ie: the last site to have a certificate registered) will receive requests on HTTPS. This can be turned off by following the link in the second section (of the above page), which you can also find here: http://support.microsoft.com/kb/259349/EN-US/ Please read both these pages to be fully informed, but for brevity, here are the steps to disable socket pooling:
  • At a command prompt, switch to the "C:\InetPub\AdminScripts" folder.
  • Type the following command:
    CSCRIPT ADSUTIL.VBS SET W3SVC/DisableSocketPooling TRUE
You can also read more about this at: http://support.microsoft.com/kb/238131/EN-US/

Just for reference, I've switched off socket pooling on my machine using the article above and it looked something like this:
C:\>cd Inetpub

C:\Inetpub>cd AdminScripts

C:\Inetpub\AdminScripts>CSCRIPT ADSUTIL.VBS SET W3SVC/DisableSocketPooling TRUE
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

DisableSocketPooling : (BOOLEAN) True

C:\Inetpub\AdminScripts>

Augmented Reality in CSharp

My mind was completely blown away last night when I discovered a blog post by a guy called Casey providing wrapped C++ code for a simple augmented reality project in C#:
http://www.mperfect.net/wpfAugReal/

This is a first step, but it provides a source code solution in .NET to render 3D objects over a live webcam video feed.

To get it running just make sure you have a webcam with a clean image, .NET 2.0 and Visual Studio, the WPF (Windows Presentation Foundation) installed, and DirectShowLib. These are all linked from the above link.

I really hope this can be expanded on and that Casey does not mind me referencing his code because the more interest there is in this, the faster/more practical it will grow and become. We don't see really exciting creations like this in everyday life very often, but hopefully this will establish itself.

Btw, one I've not checked out properly: http://sites.google.com/site/augmentedrealitytestingsite/

Resources:

Thursday, March 05, 2009

ASP.NET Globalization, Culture, Localization and the Resource tag

So here's a couple of useful links that involve setting the appropriate properties of websites in ASP.NET that every .NET coder should be aware of.  Also, something I only recently discovered proper is the tag.  Looks like I've some reading to do, may well expand this entry another time...

ASP.NET Globalization and Localization:

Basic Instincts-Resources and Localization in ASP.NET 2.0: http://msdn.microsoft.com/en-us/magazine/cc163566.aspx


Extract:

In addition to programmatic access, ASP.NET 2.0 also introduces declarative syntax you can use to bind a named string to a property of a page or control. The syntax involves using the dollar sign ($) followed by the Resources namespace, the name of the resource file and the name of the string:

Wednesday, March 04, 2009

Tweet tweet tweet...

Yes, I now twitter...

:)

Commerce Server, Afraid to ask?

Finally getting into Microsoft Commerce Server for work and have been looking around for useful articles to break me in gently.  Some good posts from Max Akbar right here:

http://blogs.msdn.com/maxakbar/search.aspx?q=pipeline+afraid&p=1

The initial thrust of my exploration is Pipelines, hence the first 4 articles in the above search, but the rest is good reading.

gacutil exited with error 9009

Ok, this isn't one for me, right now, but I noticed this occuring in some code I'm working on. Now, I don't mess about with the gac (global assembly cache) in .NET - I'm a straight shooter - but I also like to note down issues with resolutions that might crop up later.

Henceforth, here is a blog post with a useful link:

And the article with the solution (original link):

Essentially, it's useful to be aware that VS does not take into account environment variables when compiling code unless executed with the right options, so best to use the full pathname of assemblies.

Tuesday, March 03, 2009

Quake? Online? In a browser window? Nice(?)

Ok, so I just noticed this little beauty on my Google homepage:
http://www.hanselman.com/blog/QuakeLiveReviewAndRantWhyIsThisInteresting.aspx

However, hmm, looks like it'll be a disappointment.  Better stick with Unreal 3 ;)

Thursday, February 19, 2009

Convert byte[] to String

I was going to make one big entry containing lots of little bits of code, then realised I only had one to put in, because I keep forgetting it...

Converting a byte[] (array) into a String:

string outStr = System.Text.Encoding.UTF8.GetString(inByteArr);

Thursday, February 12, 2009

More useful links...

I have posted many links on this blog, for many reasons. I'll now be posting even more. These are useful .NET coding resources which I simply don't want to forget.

TRULY UNDERSTANDING VIEWSTATE:
http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx
TRULY UNDERSTANDING DYNAMIC CONTROLS (PART 1):
http://weblogs.asp.net/infinitiesloop/archive/2006/08/25/TRULY-Understanding-Dynamic-Controls-_2800_Part-1_2900_.aspx
Building Templated Custom ASP.NET Server Controls:
http://msdn.microsoft.com/en-us/library/aa478964.aspx
Developing Custom ASP.NET Server Controls:
http://msdn.microsoft.com/en-us/library/zt27tfhy.aspx
Introducing Commerce Server 2007:
http://www.microsoft.com/commerceserver/default.mspx
Max akbar - For the hardcore Commerce Server Developer... and demystify the product:
http://blogs.msdn.com/maxakbar/
Getting Started with Windows Communication Foundation (WCF):
http://msdn.microsoft.com/en-us/netframework/aa663324.aspx
Windows Presentation Foundation:
http://en.wikipedia.org/wiki/Windows_Presentation_Foundation
Using Bluetooth in .NET:
http://dotnet.org.za/rudi/archive/2007/09/28/using-bluetooth-in-net.aspx
Search JQuery from inside Spotlight:
http://www.appelsiini.net/2009/2/search-jquery-api-docs-from-spotlight
Mozilla's new cloud-based HTML editor:
http://www.readwriteweb.com/archives/bespin_html_editor_cloud.php
Simon Edwards' blog:
http://www.transceiver.co.uk/
Adobe Photoshop Express:
https://www.photoshop.com/express/landing.html
CoolIris media viewer (see top of page):
http://www.cooliris.com/
What annoys you about Windows?:
http://www.annoyances.org/
YouTube tools:
http://www.quickonlinetips.com/archives/2006/10/the-amazing-youtube-tools-collection/

Friday, January 23, 2009

More Embedded Resource fun

If you're new to embedded resources please read this entry first: http://springboardpillow.blogspot.com/2009/01/embedded-resources-and-having-fun-with.html

Now we'll use the same image, from my previous blog entry, from within the project we created earlier. For this we will need a...

Custom Web Control

To make this, either use the default ServerControl1.cs, or right click the control project and select: Add -> New Item -> Web -> ASP.NET Server Control. By default this should give us:

WebCustomControl1.cs

To get in the habit, first...

Compile the Control Project

Select: Build -> Rebuild [project name]

This will recompile the custom web control project, including the new (empty) control and place it's DLL into the web project. This is because we previously referenced the control project from the web project. Now, we are going to...

Add a reference to the Embedded Resource to the Custom Control

In the new custom control, find the RenderContents(...) method and replace it's content with:

output.Write(
"<img src='"+
Page.ClientScript.GetWebResourceUrl(typeof(EmbeddedCtrls.ServerControl1),"EmbeddedCtrls.cartman.jpg")+
"' />"
);

You should be able to see that this is essentially just manually writing out the same code as was in the previous web page, however this time we are inside the custom control and so the reference to it can essentially be 'this.GetType()'.

Now, rebuild the custom control project as before (Build -> Rebuild [project name]) and the updated DLL will be copied to the web project. All we need to do is...

Drop the Custom Control onto a Web Page

So, create a new ASPX in the web project and open it's design view. If the custom web control project compiled correctly, you should have a new toolbox group called '[project name] Components'.

Grab the custom control from within the toolbox group and drop it onto the designer. Save everything and run the page.

You should now have the same output as in the previous blog entry!

Easy, eh?

Two things to Note are...

That dropping the custom control on your web page add a Register directive to the top (just as any ASP.NET toolbox control does)

And that you will have a <span> tag surrounding your <img> tag. To remove this, simply override RenderBeginTag and RenderEndTag, like so:

public override void RenderBeginTag(HtmlTextWriter writer)
{
// removed one line of default code!
}
public override void RenderEndTag(HtmlTextWriter writer)
{
// removed one line of default code!
}

Listing the Known Embedded Resource

If you want to place a stop point in your code and list the embedded resource files that are available to you, paste the following line just before your stop point:

object a = GetType().Assembly.GetManifestResourceNames();

Upon stopping here, the 'a' object will be a list of embedded resources.

As Before...

The entire demo solution can be found here.

Resources:

http://support.microsoft.com/kb/910442
http://www.codeproject.com/KB/aspnet/MyWebResourceProj.aspx
http://aspnet.4guysfromrolla.com/articles/080906-1.aspx
http://aspalliance.com/726
http://msdn.microsoft.com/en-us/library/yhzc935f.aspx

Embedded Resources and having fun with them

Ok, so, having gotten back from 2 months round the world and almost 3 months not coding at all, I'm feeling rusty. Opening Visual Studio came as quite a shock, simply because "All Those Buttons Can't Possibly Do What I Remember!!!"

Anyway, back in the saddle (I hope) and getting some new code under my belt: This time in the form of...

Embedded Resources

What are those? Well, when you drop, say, a GridView control or something, anything from the toolbox onto your page and it already has, lets say, stylesheets, images, javascript etc, that you think would be better provided as separate files... they probably are. How? Well, when building the code as separate files the non-C# files are placed into an...

ASP.NET Server Control project

This project then needs to be referenced by the web project, so that it's DLL is placed in the website's \bin directory, thus placing any (correctly compiling) custom web controls [because that's what this project type is for] into the toolbox (when ASPX/ASCX 's are in design mode.)

So, lets...

Create a Custom Web Control with images and stylesheets in a DLL

So, open Visual Studio and create a new solution (File -> New -> Project -> Visual C#|Basic -> ASP.NET Web Application) This will give us a website as well.

Now, to this solution, add an ASP.NET Server Control project (File -> Add -> New Project -> Visual C#|Basic -> Web -> ASP.NET Server Control) This gives us a project we can create custom web controls in. This is also the project where the embedded files will be placed.

Ok, so the quickstart to adding and using an embedded resource is...

Add an Embedded Resource and call GetWebResourceUrl

First we need something to use. So lets add an image to the control project - not the web project!

In order to make the image embedded select it in the solution explorer and in the properties panel change it's Build Action to Embedded Resource.

Now make the image usable by expanding the control project's Properties item (in the solution explorer) and edit the AssemblyInfo.cs. Add the following lines to the using declarations at the top:

using System.Web.UI;

And the following to them bottom:

[assembly: WebResource("EmbeddedCtrls.cartman.jpg","image/jpg")]

Where the format is:

[assembly: WebResource("[assembly name].[directory names].[filename]","[filetype]")]

For an image called "cartman.jpg" stored in the root directory of the control project.

Bear in mind that the first part is the assembly name (select the project in solution explorer and click properties) and not the namespace. Also, that rather than being a typical absolute path, the path separators are '.' and not '/'.

We now have a project with an image which can be referenced as an embedded resource, both by code within the control project and any project which references it's DLL's, eg: the web project we created at the start.

Important: One major stumbling block I found was that if the above line of code, in the AssemblyInfo.cs, does not get recognised by Visual Studio, it means something has gone when creating the project. Just delete it and create a new "ASP.NET Control Project". It should appear as so:

[assembly: WebResource("EmbeddedCtrls.cartman.jpg","image/gif")]

Or something close to that, assuming you haven't adjusted your editor styling.

Now, to actually use this image somewhere, we need to...

Add a reference to the Control Project and Compile It.

So, in the web project, right click the References and add the control project as a reference. Then, select the control project in the solution explorer and click Build -> Build [project name]

This will compile the control project and copy it's DLL into the web project's \bin directory. Nearly there. Finally, we need to use it by...

Adding a reference in a web page

Either add an ASPX or open the default one. Paste the following line into the <div></div> statement in the HTML of the page:

<img src='<%= Page.ClientScript.GetWebResourceUrl(typeof(EmbeddedCtrls.ServerControl1),"EmbeddedCtrls.cartman.jpg") %>' />

And run the web page. If everything goes to plan, you should have a page with a single img tag which displays your embedded image.

If WebResource.axd is not found, check the highlighting of the assembly: webresource statement as described above. Also, check that the image file Build Action is set to Embedded Resource, in the properties panel. If the image simply fails to appear, just go through and check that you are providing the correct file name, assembly name, etc.

If you get a web resource exception, it's because you are not registering the embedded resources correctly. If you get a webresource.axd?d=... URL but it shows nothing, it's because the image file is not being referenced in your code properly. The GetWebResourceUrl call and the AssemblyInfo.cs entries must match.

Failing the above, ensure that each time you change the contents of the control project that you rebuild the project and refresh the web page. Simply recompiling the web project will not do it (unless you've configured your solution especially - this is not the default in VS.)

Wasn't that fun? You can download the complete solution here. That is also the same download for the next blog entry, where I will deal with referencing the image from within the control project.

Resources:

http://support.microsoft.com/kb/910442
http://www.codeproject.com/KB/aspnet/MyWebResourceProj.aspx
http://aspnet.4guysfromrolla.com/articles/080906-1.aspx
http://aspalliance.com/726
http://msdn.microsoft.com/en-us/library/yhzc935f.aspx