Friday, August 28, 2009

Health: Another Protein Shake Recipe

Today I tried mixing 1 scoop of vanilla protein mix, 1 cup milk, and 1/4 can of frozen orange juice for an Orange Julius flavored drink.  The first drink was pretty good, but by the time I was half way through I really had to force myself to finish it.  Maybe I'll try banana plus orange juice concentrate tomorrow.

Thursday, August 27, 2009

Health: Mix a Banana with Vanilla Protein shake

I recently started the P90X workout series, and as expected, have been making my muscles very sore.  I purchased a 5 lb bag of EAS Whey Protein in vanilla flavor.  The taste is OK by itself, but suffers from the same chalky taste that is also present in every other whey protein mix I’ve ever tried (although not as much).  Yesterday I mixed a scoop with some frozen strawberries, and it wasn’t bad, but this morning I threw in half a banana, a cup of milk, and one scoop of mix and was very happy with the taste.  There are 23 grams of protein per scoop of mix and another 8 in the milk for over 30 grams per serving.  I think this will become my routine morning drink.  I may also mix up a double batch and take half to work for an afternoon snack.

Friday, August 21, 2009

Construction: Mix Cement With a Drill

I was doing cement work last weekend in my basement and was breaking my back trying to mix cement in a 5 gallon bucket.  I knew there had to be a better way to do this.  So I went to my dad's and borrowed a large drill bit he bought to mix paint.  It was metal so I didn't think it would break from my use, and in fact I think it was probably made to mix mortar (as seen in the picture above).  The bit worked great.  It basically looks like a larger version of the same utensils you use with a kitchen mixer.  Since all of the force is horizontal the cement won't splash out (unless you get really crazy).  My 18V cordless drill was strong enough to do the job on the low gear setting, however I wore through the batteries much faster than I could recharge them.  So I used an electrical drill and it worked much better as it had a handle on it for my left hand to hold.  It seemed to work best if I put the water in first and then added cement gradually to get the right mixture.

Code: TSQL Select unique data

SELECT   Top(5) *
FROM [Reports].[Reporting].[ReportTracking]
WHERE ReportTrackingId IN
SELECT MAX(ReportTrackingId)
FROM [Reports].[Reporting].[ReportTracking]
WHERE UserId = 41603
GROUP BY ReportName
ORDER BY ReportTrackingId DESC

The SQL above can be used as a basis when you need to select data from your database that needs to contain only unique values for a particular column.  The inner query will retrieve the newest primary keys based on your unique column and the outer query grabs the entire row for that primary key.

Thursday, August 20, 2009

Code: 'Type' was not expected. Use the XmlInclude or SoapInclude attribute

I received the following error today while developing a web service:

System.InvalidOperationException: The type <CLASSNAME> was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically. 

This error was thrown because I was attempting to return an inherited class as a web service response.  There are a couple ways around this issue.

1. (My fix) Return the base class instead of the inherited class (obviously not always an option)
2. Add XmlInclude attributes to your BASE class as such:

3.  Write your own serialization code.

Wednesday, August 19, 2009

Code: jQuery $ is not defined

If you're using jQuery and you encounter an error that says $ is not defined it means that you are attempting to call a jQuery method before the jQuery .js file has been referenced. Make sure that your <script src=".."> reference tags are BEFORE any jQuery methods. This can also occur if your url to the .js file is incorrect or if the file can't be accessed due to security permissions.

Tuesday, August 18, 2009

Code: Enabling 32 bit builds in IIS 7 64 bit

I ran into a new error today:

Could not load file or assembly 'ClientPortal' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Turns out it was caused by referencing a 3rd party assembly built for 32 bit, on my 64 bit machine.  The fix was easy once I found it.  Just need to open IIS Manager, right click on the application pool that is hosting the web site, and click Advanced Settings.  Then change "Enable 32-Bit Applications" to True.


Monday, August 17, 2009

Code: Use CSS to hide items instead of jQuery's ready method

if you are using $(document).ready() to hide items, it can cause the items you hide in that method to be shown for a short time before the method is executed, causing a flicker on the users screen.  To avoid this use style="display: none;" to make your item hidden.  Using visiblity:none won't work, when you call .show() jQuery won't override the style.  If you need to call a JavaScript method to determine if the item should be visible or not, set the display to hidden and then call your JavaScript method.  Its better for items to be hidden and then pop in than to have them display and pop out.

Friday, August 14, 2009

Code: Use Firebug to Fix CSS Issues

Firebug came in handy today when I couldn't figure out why Firefox wasn't honoring my table padding markup, luckily the culprit was easy to track down with Firebug.  Just click the element selector button (highlighted in red in the picture), and click on your item.  All of the CSS classes that are currently being applied to it show up in the right column and you can scroll through and find the style sheet and class that is causing your issues.

List: Top Movies of All Time

Our favorite movies have typically been a source of great discussion at work, so today we decided there needed to be a list. What's on yours?
1 Airplane
2 Forest Gump
3 Gladiator
The Shawshank Redemption
Forest Gump
Fight Club
Groundhog Day
Kill Bill V2
L.A. Story
1 Matrix
2 Star Wars
3 Short Circuit
The Matrix (I)
Return of the Jedi
The Fifth Element
The Fifth Element
Dark City
Fifth Element
12 Monkeys
1 Forest Gump
2 Shawshank Redemption
3 American History X
The Shawshank Redemption
Forest Gump
Saving Private Ryan
Good Will Hunting
American Beauty
Pulp Fiction
Being John Mal
LA confidental
1 Airplane
2 Back to the Future
3 The Hangover
Back to the Future (I)
European Vacation
Christmas Vacation
Back to the Future
Groundhog Day
1 The Rock
2 Fight Club
3 Bourne Identity
The Bourne Identity
Raiders of the Lost Ark
Terminator II
Fight Club
The Bourne Identity
Kill Bill
Batman Begins
1 Se7en
2 Saw
3 The Shining
The Shining
The Exorcist
Night of the Living Dead
1 Gladiator
2 Lord of the Rings
3 Braveheart
LOTR - Return of the King
the Last Crusade
Lord Of The Rings
Lord of the Rings 1
Lord of the Rings 3
Lord of the Rings 2
1 Usual Suspects
2 Memento
3 Sixth Sense
The Usual Suspects
The Manchurian Candidate
Silence of the Lambs
Usual Suspects
Silence of the Lambs
Sixth Sense
Sixth Sense
1 Princess Bride
2 Meet the Parents
3 Wedding Singer
Princess Bride
Wedding Singer
Groundhog Day
Notting Hill
Princess Bride
Groundhog Day
L.A. Story
State and Main

1 Toy Story
2 Shrek
3 Monsters Inc

Toy Story
Monsters Inc.

Finding Nemo
Toy Story
Monsters Inc

Monsters Inc

Thursday, August 13, 2009

Code: SQL Dynamic Where Clause

Select ProductID, Name, Color, Size
From Production.Product
Where (Color = Coalesce(@Color, Color) or (@Color is null and Color is null))
And (
Size = Coalesce(@Size, Size) or (@Size is null and Size is null))

The SQL statement above works against the AdventureWorks database included with the SQL Server 2008 express download.  It’s not unreasonable to want your stored procedures to play well with your user interface, it makes the whole development process a little nicer.  So if you have a web page or windows form that has a handful of options a user can specify to filter data, using a dynamic where clause will prevent you from using string concatenation to build your query.  If you were to pass ‘blue’ into this query as the Color parameter and Null as the Size parameter, the query will return all Products with the color blue regardless of value (or null value) in the size column.

However the query can be simplified if your columns do not contain null values or if you don’t want data returned if it does contain a null value, just remove the or statements as seen below
Select ProductID, Name, Color, Size
From Production.Product
Where Color = Coalesce(@Color, Color)
Size = Coalesce(@Size, Size)

Similarly, if you want your query to match every parameter as passed in, retrieving null values only when you pass in a null for the parameter modify it like this
Select ProductID, Name, Color, Size
From Production.Product
Where (Color = @Color or (@Color is null and Color is null))
And (
Size = @Size or (@Size is null and Size is null))

Wednesday, August 12, 2009

Code: Prevent an asp:Button from doing a postback

<asp:Button ID="btnRunRecent" runat="server" Text="Generate" 
OnClientClick="RunMyMethod(); return false;" />

If you want to run a JavaScript method on a button click for a richer client experience you’ll need to add an attribute for OnClientClick to your asp:Button.  When it renders the actual html input tag to your web page it will add an onclick attribute and set your JavaScript to its value (onclick=”RunMyMethod(); return false;”)   Just place the name of your JavaScript method as the attribute value to allow the page to postback after running your script, if you don’t want the form to do a postback after finishing your script follow your method name with “return false;” as shown in the example.  If you don’t want any custom JavaScript function to run and just want to prevent the button from causing a postback just put “return false;” as the OnClientClick value.

Money: Buy A/V Cables online instead of in store

As a former Best Buy employee I know that accessories receive the biggest markups of all of the items in the store.  I was in need a new HDMI cable recently and did a price comparison.  A 6 foot off-brand HDMI cable at Best Buy costs $20 a piece.   I purchased a pair of 6 foot cables on eBay for $6 including shipping.  I’ll definitely modify this post if the cables give less than advertised performance, but I suspect that will not be the case.  You could spend even more if you wanted to get name branded cables, but if the data is being transferred digitally (as is the case in HDMI) I don’t see how a different cable is capable of producing better quality.  Does your internet work faster if you spend big bucks on an Ethernet cable?  However if you do want to go name brand, those are way cheaper on eBay as well.

Tuesday, August 11, 2009

Code: Use jQuery to Bind an Event Handler to a DropDownList

<script type="text/javascript">
function EnableControls() {
$(document).ready(function() {
$("select#<%=ddDateType.ClientID %>").change(EnableControls);

If you haven’t yet spent time to learn what jQuery can do for your site, then I highly recommend you do.  Its benefits may seem trivial at first glance, but once you start digging in, its flexibility is very useful.  When the page loads (client side load, not to be confused with the Page_Load server event), jQuery will tell the DropDownList "ddDateType" that it should call the javascript method "EnableControls" when the selected value changes.  This comes in handy if you need to show/hide other controls (there’s also a jQuery method for that) or do some AJAX work (there’s also a jQuery method for that).

Monday, August 10, 2009

Money: Buy pop in 2 liter bottles

I'm surprised at how infrequently people buy pop in the form of 2 liter bottles. It's not hard to find store brand pop for 80 or 90 cents per 2 liter (64 ounces). That breaks down to 1.3 cents per ounce or just 17 cents per 12 oz glass. Compare that to name brand pop in cans at $3.50 per 12 pack equates to 29 cents per 12oz can. It doesn't sound like much when you think of it on a per cup basis, but 2 liters equate to roughly 40% savings. If you drink an average of 1 can per day you'd save about $40 a year, which isn't much, but multiply that by 2 cans a day or a family of 4 and then it starts to add up. Also consider how much less waste is created in the process (although that is negligible if you recycle every can along with the cardboard box).

I realize that the biggest argument against 2 liters is the portability factor, but you might be surprised at how portable a cup can be. If you want to take a pop on the road, just get enough that you know you'll finish before you arrive at your destination and leave the cup in your cars cup-holder until you get home. If you worry about spilling you can grab a cup with a lid from the nearest gas station and reuse it.

Now if I could only get a soda fountain machine installed at home...

Code: Parse Query String Outside of a Web Page

NameValueCollection queryString = HttpUtility.ParseQueryString(myQueryString);
string myId = queryString["myid"];

There are many reasons why a person would want to parse a query string outside of a web page. In order to accomplish this in C# .Net you can use the System.Web.HttpUtility.ParseQuerystring() method. One thing to note however is that you should not pass a full URL, it expects the query string only (everything starting with the "?").

Source: MSDN

Sunday, August 9, 2009

Windows 7: First Impressions

As a software developer I have access to new Microsoft products before the general public. This has allowed me to install the release version of Windows 7 this weekend. This install comes with the full release license (no time limit that the release candidate has). Prior to installing the release version I had the RC on my desktop and notebook, and thus far I've been very impressed with it. The new taskbar is probably the biggest change from Vista, and I think it is a fantastic upgrade. I'm a very visual person, so being able to see the icons for my most used programs at all times will really help to keep my train of thought when moving from one program to another to accomplish a task. The OS also feels very snappy, which was one of the major complaints against Windows Vista (I stayed with XP until now for this reason). Skipping Vista also meant that I missed out on the user interface upgrades it provided, so things like better thumbnail support that have been around for a while also help with the wow factor for me.
Installing a new OS also means that I need to reinstall the other software I use on a near daily basis. Here are the apps that I put on any computer I use (I have not noticed any issues with running these on Windows 7 yet):

  1. Mozilla Firefox - for all my surfing needs

  2. Google Chrome - for all my wife's surfing needs

  3. Media Monkey - Best program I've found to organize and play my MP3's

  4. Paint.Net - Image editor

  5. OpenOffice - Similar to Microsoft Office, and can create/edit Microsoft Word, Excel, and Powerpoint files

  6. VLC - plays just about any piece of video or audio file you throw at it

  7. PDF Exchange - open's pdf files faster than Adobe Reader and also allows for slight editing of the files

  8. Pidgin - Chat client compatible with many protocols. If I only chatted with friends using google chat I'd use google talk instead, but at work we chat via Windows Live Messenger, and I despise the Live Messenger UI.

Note that all of these programs are free and I highly recommend you give them a try. One complaint that I do have is that when using tabs in IE8 the taskbar preview shows all tabs, however the preview for Firefox only shows the active window. However I assume that this a change the Firefox needs to make to support this capability. Either Picasa or Windows Live Photo will be added soon to manage photographs.

Code: Capitalize first letter of every word in a string

Microsoft.VisualBasic.Strings.StrConv(item.Name, Microsoft.VisualBasic.VbStrConv.ProperCase, 0);

The string class in C# has built in methods for making all characters in a string upper or lower case, but nothing to capitalize the first letter in every work. However there is a method in the Microsoft.Visualbasic namespace that will do the trick. Just add a reference to Microsoft.VisualBasic and use the code above.

Saturday, August 8, 2009

Welcome to my blog!

Thanks for visiting. Hopefully you will, at some point, find something useful or interesting here. My name is Adam and I write computer software for a living. I also do lots of other things that have nothing to do with writing code. This blog serves as a message board for both my work and non-work life, hence the name. Perhaps I should explain the name. In many computer languages the exclamation point is used show inequality. For example 1 != 2 would be evaluate to "true". And !True would evaluate to False. So !Code reads literally as "Not Code", and my blog is essentially two main categories Code and Not Code. I expect few people will be interested in every post I make, so I will do my best to keep the post titles descriptive of the subject matter. If you're only interested in code you can use this url: If you're only interested in !Code you can use
Thanks again for visiting.