Categories
Geeky/Programming

What's A GUID?

GUID – “GooID – not Gee You ID” – a unique identifier. There is often debate on the uniqueness of GUID’s. Microsoft uses them for a ton of things. CLSID’s in the registry, uniqueidentifer fields in SQL, and just anything unique. Microsoft isn’t the only one to use them, Oracle, Novell, etc use them.

As far as the uniqueness of GUID’s, here is what I found on Wikipedia:

“While each generated GUID is not guaranteed to be unique, the total number of unique keys (2128 or 3.40282366×1038) is so large that the probability of the same number being generated twice is very small. For an application using 10 billion random GUIDs, the probability of one or more overlaps is on the order of 1 in a quintillion.”

A quintillion is 1018

That is alot 🙂 since scientists estimate that there are about 70 sextillion stars in the sky, lets just say that the number of GUIDs is close to a duodecillion – which is more than the sextillion (if I have my large number names correct)

Those numbers alone should end any debate on duplicate GUID’s occurring in the wild, unless you are doing something really wacky to generate them. Some say that because in V1 of the algorithm, the MAC address was used as a basis for the last 4 digits, that you could get duplicates. I think that is still hard to believe that you would get dupes, since it was just the last 4 digits and it just didn’t use MAC address, it also uses time. So two computers with the same MAC address would have to create a GUID at the same nano-second. And even if that did happen, it would have to be a GUID used in the same application to have any adverse effects.

One problem with GUID’s, which usually happens because of sample code on the net, is that people use the sample code that has a GUID hard coded, and then reuse it in their application, which then can end up with duplicates on user’s computers. Browser Helper Objects, Explorer Shell Hooks, etc use GUID’s. Any DLL you want to register (COM for instance) is going to create a GUID when registered. It is always a good idea to create a new GUID when deploying any code that would use it. Visual Studio has a utility built right in on the tools menu to create GUID’s for you.

Basically, every developer should know what GUID’s are, and how they can be used, and how to created them. It is something that you should be able to talk about with colleagues and have no questions on the creation, use or uniqueness, or how to pronounce it 🙂

Categories
Geeky/Programming

VS2005 MFC Class Wizard Changes

If you ever used Visual Studio/C++ 6 (98), you would notice that the MFC Class Wizard allows you to set up messages as you create a class. Well, I’m not sure about VS2003, but VS2005, when you use the MFC Class Wizard, there are no options for setting up messages and events. Where did the options go?!?! Well, if you click on the class in class view, there are more little buttons on the properties window. If you click on the little icon next to the lightening bolt, you will see you can then set up messages for your class. Easy as 1-2-3!

Categories
Geeky/Programming

Ajax Impressions

Today I played around with doing some ASP.NET web forms in AJAX. Using Anthem.Net. First I’d have to say, Anthem is pretty easy to get started with, but their could be some better examples. One thing I found is that If you have to call some server side code from javascript and vice versa, it cant get a little tricky. I think for now for what I’m working on I will just stick to a non-AJAX route. It seems that with the way I have it in AJAX, you cant hit a button or cause an event to fire until the whole site is fully loaded, which maybe I have something wacked, but it isn’t going to work. I’ll probably dig more into it though.

Categories
Geeky/Programming

Top 10 Things To Become A Better Developer

1) Be Connected – Read RSS feeds. MySpace and Facebook aren’t RSS feeds – Scott Guthrie, Raymond Chen, Larry Osterman, CodeBetter.com, Coding Horror, You’ve been Haacked, etc. Don’t know who any of those blogs are? You should. Learn how RSS works, get a RSS Aggregator, subscribe, and read them daily or as time allows. Don’t let it get in the way of your work though. If you are brave enough, create your own blog and get feedback on things you blog about from a technical point of view.

2) Home Computer – what do you have on it? World of Warcraft? How about VS2005/SQL Express editions, or better yet, if you can get the full blown versions. Do you have IIS installed, do you know how to configure asp.net? All of these things are going to get you more into developing. Think to yourself, if I was a car mechanic, would I not have any tools in my garage at home?

3) Home Projects – now that you have your computer set up – come up with some ideas – anything, for a project. Write up the specs yourself. Figure out what you need to do to get it done, and do it.

If you make a windows app, you can get a domain and set up some html for 50$ a year, and put it out for people to download. If it is a web app, you can promote that too. Try to get people to use your app, make apps for friends, family, etc.

4) Become a Hacker – not in the sense of breaking into banks online, but just tinkering with code, programs, anything. think outside the box. become a “reverse engineer specialist”. If you can figure out how to reverse engineer someone else’s code or program, more than likely you are going to be able to easily write the program yourself.

5) Be Committed – you can’t just ride on your laurels. You need to practice and commit time to being a developer. You can’t expect to just do what is expected, you need to do extra effort+ to be great. You should love what you do. Lou Holtz (Notre Dame football coach) once said, the order of things should be this:  God, Family, Football. – just replace football with Developing.

6) Learn the Business – Developers that work for a business are going to thrive if they know as much about the business as possible. You can’t just expect to get a task list or requirement sheet and implement it without knowing why or what for. If you know the business, you can make decisions faster and you will actually be doing more things to help the business. In the end it’s all about the company you work for, not you. Just like a pro sports team – you can be the MVP like Kevin Garnett, but without a team championship, you are always missing something.

7) Work Hard, Play Hard – work your butt off. Make it a game. Tell yourself “no one is going to work harder than i am – ever” – but , when it comes time to play and be social, you need to do that too. The best business people will tell you, it’s not what you do, it’s who you know. You need to make yourself known to people. There is always time for fun, but you need to know where the balance is, and to be great, the scales should tip on the side of work.

8) Confidence – you need to have confidence in yourself. If you get a task that you know you can do, say you can. If you get a task that you can’t do, you need to say you can do it and have confidence you can figure out. Don’t ever say “i can’t”. This will build up your confidence in yourself, as well as the way other people see you. If people start seeing you as someone who always “cant” then they will stop asking you to do anything.

9) Initiative – you need to have drive. This sort of goes along with #3. At work you should see ways to improve things, and instead of just skipping over them, do it. It will help you learn more about the systems you work on, as well as show that you are driven to make things better. If for some reason you are stuck without any tasks, find something you can do, research something new. Twiddling your thumbs waiting for someone to tell you what to do isn’t going to get you anywhere.

10) Be Humble – no one likes someone who toots their own horn. You might be a genius, but if you are an a$$hole, no one will like you. There will always be someone out there better than you. This should give you a sense that you always need to improve. If you are good, people will compliment you and talk about anyways, so there isn’t any need to try to get attention or brag about yourself.

Categories
Geeky/Programming

Static Code Analysis in C/C++

If you ever need to run static code analysis on C/C++ files, you can use Vs2005, but if you are in Vs2003, here is what you can do:

c:Program FilesMicrosoft Visual Studio 8VC>cl /analyze “C:MyCodeFile.c” > c:MyCodeFileAnalysis.txt

Found this on MSDN

Categories
Geeky/Programming

VS2005 – Browser Helper Object (BHO) Tutorial

I have been dabbling with BHO’s for some time, way back with VB6, then tried in .NET, and with C++ as well. There are so many cool things you can do with them. Anyways, most of the documentation out there is sparse and old. I told myself the next time I have to make one, I am going to document it. Well, here it is in all its glory. Sorry if the code formatting is wacked, but you get the picture. I don’t claim to be an expert, but this should work 🙂
just in case, I uploaded it in txt format for better reading here

How to Create a Browser Helper Object in Visual Studio 2005 with C++
———————————————————————
1) Open Visual Studio 2005
2) File->New->Project
3) Visual C++
4) ATL
5) ATL Project
6) Name is whatever you want for this example I use “Company.Browser.Helper” without the quotes

7) The ATL Project Wizard Screen will appear, Hit Finish
8) Visual Studio will load up your project.
9) Right Click on The Company.Browser.Helper project, Add->Class
10) select ATL Simple Object, and click the Add button
11) fill in the ShortName – “BrowserHelper” without the quotes, the rest of the fields should fill in, hit next
12) IMPORTANT: Under Support: Check all boxes (ISupportErrorInfo, Connection points, IObjectWithSite (IE object Support)
13) Click Finish

Now on to the better stuff,

————————————————————–

In visual studio, Solution Explorer, Resource Files, you will see BrowserHelper.rgs, open it and add this to the bottom
(replace the GUID with the GUID that you see at the top of the file like CLSID = s ‘{GUID}’) in the other script code
This will register the BHO with IE when the DLL gets registered


HKLM
{
SOFTWARE
{
Microsoft
{
Windows
{
CurrentVersion
{
Explorer
{
'Browser Helper Objects'
{
{GUID}
}
}
}
}
}
}
}

above where it says ‘Browser Helper’ – you can change those names to be more descriptive, that will show in IE add on manager

————————————————————–

————————————————————–

Categories
Geeky/Programming

Unit Testing Verisign Payflow Pro with VS2005

When you set up payflow pro on a system, you usually are going to use it through the web, you usually dump the certs folder into the inetsrv folder and it works fine. Thing is, when you are using VS2005 Unit Testing, you arent on the web, you can even try setting an HttpContext, but that still doesnt work, you end up with:

Get error “RESULT=-31&RESPMSG=The certificate chain did not validate, no local certificate found, Cert Path = certs, Working Directory = C:ProjectsMyProjectTestResultsuser.name_COMPUTERNAME DateTimeOut”

before you make your request in your tests, do this:
System.Environment.SetEnvironmentVariable(“PFPRO_CERT_PATH”, “c:certs”, EnvironmentVariableTarget.Process);

Copy your certs directory to your C: drive, or you can set the path wherever – mostly likely you would want to add it to your test project, and then set the path when you setup your environment variable as releative to your project.

When you run your unit tests again, you should see a valid response and the request to Verisign should go through correctly.

Categories
Geeky/Programming

Caching got you down? Try an Object Lock

If you are using caching in ASP.net, and when your cache invalidates, you see some really bad performance or race conditions, you probably need to implement object locks.

Categories
Geeky/Programming

To Catch or Not To Catch

Earlier today, it came up in discussion, on when to catch exceptions. Really, you end up getting bitten if you just catch exceptions in your code. Basically what happens is that you are using exceptions as flow control, and not using if/end, etc. What usually ends up happening is an exception is getting eaten, but you didnt want it to, and you dont know how your program is reacting to use. ELMAH is great, you should set it up if you are using .NET programming. Also, and it is funny, but this always happens, Scott Hanselman blogged about almost the exact same topic today. And if you can avoid, dont catch a System.Exception – use a more specific exception. If you turn on Code Analysis or run FxCop, it will tell you about that as well.

Categories
Geeky/Programming

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Blah – I hate stupid error messages. Basically everywhere you look to see what causes this, it has something to do with cacading drop downs. I have ran into this error twice and the fix is – change a “=” to a “#”

if you have in your aspx page

it will throw that error if it is in a repeater or data control. Change it to

and viola! it works 🙂