Regex for U.S and Canadian Zip Codes

for my future references, below is a regular expression for validating U.S and Canadian zip codes.

^\d{5}(?:-\d{4})?$|^[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d$

more details on the format of Canadian zip codes

How to type a unicode character under MS Windows

  1. Press and hold down the Alt key.
  2. Press the + (plus) key on the numeric keypad.
  3. Type the hexadecimal Unicode value.
  4. Release the Alt key.

Note that this method will only work if you have the following registry key set to the correct value..
under HKEY_Current_User/Control Panel/Input Method, set EnableHexNumpad to 1

Use the Character Map to find the hexadecimal Unicode values for different characters.

Also, it’s worth noting that if you are using MS Word you can simply type in the Unicode hex value first and then press Alt+x. The hex number will be replaced by it’s equivalent Unicode character automagically.

C# Numeric Literals Suffixes

The suffixes in the table below are useful because they tell the compiler what type a numeric literal is and how it should be treated. The default type of a numeric literal is integer (int) of course, but if you want to specify decimal or long, how would you do that? (please don’t cast it, it’s ugly)

Consider having an overloaded method, one overload takes a parameter of type long, another of type int, now if you want to pass in the number ‘15′ for example, these suffixes will help you choose which overload to actually invoke by appending a letter (or two) to the numeric literal.

Type   Suffix   Example
  uint   U or u   100U
  long   L or l   100L
  ulong   UL or ul   100UL
  float   F or f   123.45F
  decimal   M or m   123.45M

Note that the suffixes are case-insensitive.

DateTime & Number Format String Cheat Sheet

I don’t know why I haven’t spent the time to create something handy like this!

If you are a .net developer (specially an asp.net one) you certainly will see the benefit of this DateTime formatting cheat-sheet. Personally I have wasted my time before trying to format an integer to print in a certain way and of course i didn’t have the correct format-specifier right off the top of my head so i had to hunt down the information on Microsoft’s slow-and-poorly-searchable msdn which is certainly something i try to avoid!

reference: Scott Gutherie’s blog

Consolas – A font for programmers!

I stumbled upon this font called Consolas which is recommended and created by Microsoft to use with Visual Studio 2005 (I’m not sure why just 2005), It’s a very good font for writing scripts, code, HTML, etc..

  • It’s monospaced (i.e. fixed width)
  • The characters ‘0′ and ‘o’ are very distinguishable (which helps avoid a common mistake)
  • It’s compact, compared to Courier New
  • It looks very pleasant

Make sure you have the ClearType effect turned on (Control Panel->Display->Appearance->Effects)

I’m glad I found this font, and that’s why I’m sharing it, It’s way better than Courier New which used to be my favorite actually.

Subsonic DAL

Subsonic is my favorite library for creating data access layers in asp.net.

  • It creates properties to the related entities/tables in the database, some people like to call this feature Deep Properties!
  • no need to create CRUD stored procedures for every table in the db
  • you can do queries on the fly, WHERE clauses, ORDER BY clauses and aggregate functions
  • It’s open-source and free
  • the classes are generated using a tool, no more tedious DAL writing
  • for your convenience you get “Scaffolding forms”.
  • it uses parameterized dynamic sql, which makes all those great features above possible
  • It has providers for MS Sql Server and MySQL

If you are an asp.net developer you should give it a try, or at least check it out, it’ll be worth your while.