Tuesday, November 15, 2011

Hello AWS!

So I was vegging out, thumbing through my twitter stream when @robconery linked to this interesting piece. While its always interesting to see people switch dev frameworks and the reaction it causes, I was intrigued by this comment:

biggestJohnson said...
simple solution - get yourself a free environment in AWS and do all your setup there. even can do spot images/backups of the entire server and clone as needed. (now don't get me wrong - I love my mac and it's my go-to dev platform). but now a days, you have connectivity to the net everywhere and therefore a connection into a safe and secure virtual server you can do what ever to in a *nix environment. I've been running over there for several months 4 micro server for a total of $6. Very very inexpensive platform for development.

This lead me to spend around an hour (a very comfortable hour, with plenty of distractions) to get up on AWS, and while I don't have a webserver up yet, I'm already in and coding! In an attempt to further motivate myself, I'm challenging myself to write this blogpost before my laptop battery dies in 5 minutes...

(Thanks 'biggestJohnson'! heh heh...)

AWS Setup For Mostly Animate Objects

Here were my steps:

1. Sign up with AWS & use the "Free Usage Tier", all outlined here:
- FYI: You have to provide a credit card and its a tad long of a process (phone verification etc.) so just be ready...
Make sure you generate & download the key pair when given the chance during setup, you can only download them once

2. Download putty (putty.zip, you'll need the keygen part)

3. Follow these steps to load the private key & create a ... .. .  .       .
(ok, this is where my laptop died, oh well! that means more screen shots for you!)
3. Follow these steps to convert / extract the private key & set the keypair in putty

4. Lookup your instance hostname by going here:
https://console.aws.amazon.com/ec2/ and clicking "instances",
select your instance and the hostname will be shown in the details pane below.

5. Fill in the session details as shown below

5. I created a simple batch file to launch my AWS session with one command
"C:\...\putty.exe" -load "PUT PUTTY SESSION NAME HERE"
Just copy that and save it in a .bat file in a conveninent place. Note that the putty path will have to map to your local one

6. Run that script and you should be prompted with a logon. 
Thanks to this comment on the above article, it seems the default username is ec2-user, logon and you're good to go!

Hello AWS

Now let's say hello, in a very anti-cloud way (if I may...)
1. Crank up vim
$ vim helloaws.c

2. Now just compile it & run it
$ gcc hellowaws.c
Ha, gotcha! you'll need to install it using the provided yup package manager!
$ sudo yum install gcc
then hit 'y' a few times and let the package manager have its way with your system...
now, compile that beautiful program again, then run it
$ gcc hellowaws.c 
$ ./a.out
I know I'm doing something dumb with that a.out path, something with the working directory, i dunno but...

So, yeah, I'm in the cloud now ;) That was great, I know that I don't have anything up now, but this will help me finally learn a bit of *nix, play with different webservers, and actually setup a public website (I know, is it 1998 already?)

For my next act, I'll setup a simple web server to start hosting a website on AWS, stay tuned!

Enjoy & Code it Already!

Thursday, July 14, 2011

C# : Direct type casting versus 'as' keyword

A quick post about type casting with ( ) versus the as keyword in C#. The main difference between the two casting method is mainly the way it behaves when casting fails.

An example of direct casting with ( ):

void Fun(object obj)
  Foo f = (Foo) obj;

When you cast this way, if obj fails to cast to type Foo it will throw an InvalidCastException.You should always have a try-catch around this to catch exceptions.

Here's an example of casting with as:

void Fun(object obj)
  Foo f = obj as Foo;

In this case, if obj fails to cast to type Foo, f is assigned to null. This also means you should always write code to check/handle the null case after casting with as. Otherwise, it might later bubble up as a generic-hard-to-debug NullReferenceException (which is not as obvious as a InvalidCastException from direct casting). Another note, because it has to be able to assign null to the final object, this type of casting cannot be applied to basic types (e.g. int, byte, bool).

In most cases, if you know the type that obj should be cast to and don't expect the casting to fail, direct casting is preferred. This makes the problem more obvious whereas casting with as keyword may swallow your mistakes and make problems harder to debug later. This being said, as long as you handle the null case then it is ok to cast with as

Happy coding!

Tuesday, May 17, 2011

The State Mono : Enter Xamarin

Ok, so you remember mono right? 

They're the open source project that provides binary compatible .net framework implementations on Linux, Android, iPhone etc. that allows us to easily port our .net applications to other non-Microsoft platforms as well as supporting non MS implementations of Silverlight under the moonlight project along with all sorts of other projects.

Mono was sponsored by Novell, makers of SUSE Linux among other products, and they employed the core Mono engineers.  Notice I say was sponsored...

Attachmate acquired Novell last year and people were wondering what the fate of Mono was to be.  Things looked pretty bleak, and it was believed that many or even the entire mono team was to be laid off.

The fearless leader & founder of mono, Miguel de Icaza, stayed pretty mum on the subject on his twitter/blog until yesterday.

He announced that the mono team was going to become a startup called Xamarin.

Here's some facts I've gathered:

  • Mono will still be open source
  • Attachmate is still currently selling the MonoTouch/MonoDroid mobile development products, but since they laid off the entire mono team, they are most likely incapable of properly maintaining them.
  • Xamarian claims they will have initial versions of the MonoTouch/MonoDroid products ready for testing in 3-6 months
  • They also claim that it will be compatible with the MonoTouch/MonoDroid product currently offered by Attachmate.

Looking forward, I would venture to guess that the mono team will innovate better and faster now, they have lots of community support and loyal followers who will invest in them.  But this will revive the talks of Microsoft's role in the mono-sphere, and if they would ever consider suing Xamarin over any of the patents they hold on the .net framework.

Interesting when software & business collide right?

Enjoy, T.J.

Thursday, August 19, 2010

Keyboarding: VS2010 Navigate To Inside-Out

Keyboarding is a series of blog posts related to programming productivity sometimes including looking at ways to keep your fingers on the keyboard and away from that mouse!

The Chase: The Navigate To Dialog in VS2010 lets you navigate to files, classes, properties etc. in your current project simply by hitting CTRL+, then typing a portion of the entity’s name. Hit enter to go to the 1st entry or use arrows to navigate through the results.



Mo' Tips

Pascal-Case enhanced search

Navigate To a Path

Filter By Extension

Explicitly Specify Class Scope


Main Commands

Search Filters

Closing Notes


We all love windows 7 right? Don’t you love being able to hit WIN + part of the filename you’re looking for and see it pop up in the desktop search? Microsoft really did a great job there. But then, why would MS hang their developers out to dry when it comes to visual studio? In the pre-VS2010 era developers were relegated to use the solution explorer to find files and open them. This required expanding and contracting folders, sometimes several levels deep, to get to the file you want. It’s even worse if you hide the solution explorer pane for more screen real estate. Long story short, good type-ahead search in windows and on the web has spoiled us for good keyboard-friendly search in our code too!

Thus, Visual Studio 2010 came to the rescue! VS2010 includes the new “Navigate To” dialog which is easily invoked when you have a project open by typing CTRL+,. We’ll grep the MVCMusicStore example app by John Galloway since it has a rich set of file types to show off some of the “Navigate To” dialog’s hidden features. Anyway, it’s always a good exercise to read other people’s code.


Here I am, a beautiful blank Visual Studio with the MvcMusicStore solution open, how do I get started? Well, those familiar with ASP.net MVC know that the core of most applications is in the controllers, let’s look for some controllers!


Wunderbar! I’m already presented with a list of related classes, methods and files with the word controller in them. This is a “LIKE” search so anything that contains your search term will be included in short:


Fact: The Navigate To Dialog will return results including:

  • Classes
  • Methods
  • Properties
  • Member Variables (public and private)
  • Files

Fact: if you hit ENTER while typing in the Navigate To dialog it will (he he!) Navigate To the 1st result, if you arrow up or down it will naturally go to whatever entity you select.

For fun let’s try something like Album, since that’s one of the common domain objects in this project (a music store)


You’ll notice this returns a more diverse (and larger) set of results including code and markup files, very handy for when you simply want to open a file.

Of course if you type in something more specific the results will be filtered thusly:


(Side note: ALT+N+SC is a neat keyboard shortcut to bring up the insert screenshot menu in Word 2010)

So now when I want to start developing I can just do WIN, solution file name, ENTER then CTRL+, then the filename ENTER and BAM! Off you go!

Now this is just the basics of course, but here are a few extra tips that aren’t as well known:

Mo’ Tips

Pascal-Case enhanced search:

Just like the new and improved intellisense in VS2010, the Navigate To dialog can save you keystrokes by using the PascalCasingConvention.


Simply type AMS for AccountMembershipService. This tip is pretty well known; hopefully the following ones will show you something new

Navigate To a Path

For the command line enthusiasts out there, you can type your way through a path much quicker than you can click through a set of folders, so if you have a specific path or file you want to open up via the Navigate To dialog, you can just prefix your search with a \ and it will filter your search by the subsequent paths you type in see:





A few things to notice here:

- Use lowercase when you want to do path/file exclusive searches, once you start with casing it invokes its intellisense-ish camel-case search.

- Typing \ will list all files in your project

- If your search ends with a \ it will filter by the path preceding it, whereas if you have {path}\{filter} it will filter all files under the path according to the specified filter (see the last two images). This is useful in MVC projects where you may have many files with the same name, say “Details.aspx” but you may want to jump to one in a specific folder “\views\store\details.aspx”

Filter By Extension

While the Navigate-To dialog doesn’t support wildcards, you can easily filter for a specific type of file by simply typing the appropriate extension




Obviously it’s not perfect ; )


Explicitly Specify Class Scope

You can specify a class scope by specifying the {class name}::{filter}. As far as I can tell this feature is C++ only, which is a shame and also perplexing.



See how it brought up all my Photon related methods? This code is from a ray tracer I wrote for a school project =)

I hope these tips have been helpful, here’s a handy reference


Main Commands

CTRL + , : Open the Navigate To Dialog

ENTER : Opens the 1st item in the list or whichever item was selected using the up/down keys or mouse

ESC : Close the dialog

Search Filters




Example Results




Classes, Methods, Properties, Members, and files containing *{filter}*

Cart [class]

CartCount [property]

CartSummary.ascx [file]

AddToCart(int) [method]


{Uppercase Member Initials}


Members that match the Camel Case expansion of this

AccoutMemberShipService [class]

AccoutMemberShipService() [method]

AccoutMemberShipService(…) [method]

Use uppercase letters



List of files matching the search filter under the path \{dir1}\{dir2}\...

Browse.aspx (\Views\Store)

Create.aspx (\Views\StoreManager)

GenreMenu.aspx (\Views\Store)

Index.aspx (\Views\Store)

Always use lowercase letters to invoke path search instead of PascalCaseSearch.

Typing \ will list all files in your project.

If you end your path with a \ it will list all the files in the path preceeding the slash.



List of files with provided extension




Doesn’t completely work, but in general it gets the job done.

{Class or Namespace}::{filter}


Lists all members within the prefixing class or namespace




Seems to be C++ only

You can filter namespaces/classes recursively NS1::NS2::Class etc.

Closing Notes

All in all, Navigate To is a great way to navigate between files and classes and other entities in your project easily from your keyboard. If you like staying on the keyboard it’s even quicker than switching to another tab in some cases and is a big improvement over navigating the solution explorer. You can even navigate through your project’s file structure by typing out paths in the search box.  This can be real handy in day to day coding or in a pinch when you’re looking for a specific method/file etc. like when you’re in a code review.   Some nice additions would be autocomplete of class names / folders when navigating through deep structures and allowing the same type of namespace/class scoping that the C++ navigate to dialog offers.

Thanks for reading! Know any more ninja-tips for the Navigate-To dialog or have any questions? Leave them in the comments! We love feedback!

- T.J.B.

Welcome to Code It Already!

We’re two software developers from a mid-sized group in a big-sized company in Southern California. We eat, drink and sleep .net technologies at work, and frankly we quite like them.  That said, we're interested in all kinds of programming and everything that goes on around it.  We’re starting this blog as a way of documenting the things we learn through our experiences and also encouraging ourselves to learn something new on a day to day basis…and hopefully somewhere along the way we will end up helping other developers around the world solve problems, discover new solutions or just contribute something valuable to the software development community.  A big shout out to bloggers like Jeff Atwood, Joel Spolsky, Scott Hanselman and the likes for inspiring us to get up sit down and start writing! We'll be talking about programming, productivity, and other applicable tech topics.  Anyway, we’re looking forward to sharing what we have learned and sharing our excitement for this ever growing software industry.  Watch here for some (hopefully) interesting articles and maybe some lively discussion as well, but for now

Code it Already!

Here’s a little more details about ourselves:

Annie Tsai


  • UCSD, Computer Science, 2005
Programming pet-peeves
  • In terms of code -misspelling of variable name.
  • In terms of behavior - when other developers touch my monitor with their oily fingers.
Favorite programming fuel
  • Starbucks caramel macchiato.
Other loves
  • Photography, you might catch me blogging about this every now and then.

T.J. Barbour

sunglasses head




  • SDSU, Computer Engineering, 2006
  • UCSD Computer Science 2007 - ???
Programming pet-peeves
  • Wet code (you know, when its not DRY?)
  • Slow computers
  • And any IDE that doesn't start with Visual and end with Studio.
Favorite programming fuel
  • Freezing ice cold water, like too cold, ouch, my teeth... 
  • Will also accept iced coffee.
Other loves
  • PIXAR, for their continued success, and
  • San Diego Sports for their continued stress
Our Code Heroes

Thanx! – Code It Already