Monday, November 23, 2009

Tech: Uninstall Windows Live Messenger on Windows 7

Windows Live Messenger isn’t visible in the Programs and Features list in Windows 7, however Windows Live Essentials is, and clicking it will open a menu that will allow you to uninstall Live Messenger.  I really dislike the interface on Messenger, but I put up with it so I could use the voice and video chat services.  However messenger recently started starting itself and opening up chat windows randomly so it is now banned from my system.  I’ll use Pidgin instead, or try to convince my coworkers to use Google Talk.

Friday, November 6, 2009

Code: Windows Server 2008 R2 and Microsoft Message Queuing (MSMQ)

We’re nearing the end of a large development project in which we used MSMQ extensively.  All of our queues are private and transactional.  For the most part MSMQ works great and serves its purpose excellently.  Save one glaring issue: We have had serious issues trying to send messages to the queues from remote machines.  All of the machines are in the same domain (and location).  We’ve had the environment set up on 3 different machines (for various reasons).  The first two installs we seemed to be able to post to the queues, although it took many tries changing security permissions on the queues and changing connection string formats (TCP vs OS).  On this 3rd environment we have been totally unable to send messages to the queues from a remote machine.  The messages get eternally stuck on the sending machines outgoing queue.  In the end we believe it to be an issue with the security lockdown of Server 2008 R2.

To get around the issue we had to install MSMQ HTTP Support and send the messages over HTTP.  To do this IIS must be already installed.  Then go into Features and enable Message Queuing > Message Queing Services > HTTP Support.  This will install a MSMQ Virtual Directory/Application on the default web site.  After that we just needed to change the connection strings to below and now things work great.

Code Snippet
  1. FormatName:DIRECT=HTTP://192.168.230.86/MSMQ/Private$/transcodejobqueue

Monday, November 2, 2009

Code: C# Hide Properties When Returning to Web Service

The automatic serialization built into the .Net Framework makes life easy when creating web services because it allows you to just return an object (or list of objects) and the framework will handle generating the XML return structure.  In the case where you have a property on an object that you don’t want returned in your web service method, you can add an an XmlIgnoreAttribute attribute to the property.

Code Snippet
  1. public class ReportInfo
  2. {
  3.     public string Title;
  4.     public decimal p95;
  5.     public DateParts DateBreakDown;
  6.     public List<ReportBase> Data;
  7.     //don't show this in web services
  8.     [System.Xml.Serialization.XmlIgnoreAttribute]
  9.     public List<TranscodingReportData> TranscodingData;
  10. }

Friday, October 30, 2009

Tech: Set Gmail to handle MailTo links in Opera

For some reason unknown to me, Opera does not come with the ability to select Gmail as the default mail provider.  However you can fix this with a small configuration file change.  After installing Opera open up C:\Program Files (x86)\Opera\defaults\webmailproviders.ini (if you are not running a 64 bit system the (x86) wont be present).  Open the file and add the following text to the end:

[Gmail]
ID=8
URL=http://mail.google.com/mail/?extsrc=mailto&url=%s
ICON=http://mail.google.com/favicon.ico

Restart Opera after saving the file.

If you’ve already set up a different handler for MailTo links you’ll need to go to Tools > Preferences > Advanced > Programs.  Then click the mailto protocol and click edit.  Click the “Use Web mail service” radio button and Gmail should be present in the drop down list.

If you haven’t set up a mailto handler, just click on any mailto link and Opera will bring up a dialog box allowing you to choose Gmail.

Wednesday, October 28, 2009

Tech: Off Site Backup Using Windows Live Sync

First off let me say that if you currently have no backup in place for your files, you will regret it.  I keep all of my files on a separate physical drive than my OS and Programs.  My previous method of backup was to just copy all of the files on that drive to a large external hard drive and put it in a fire proof safe.  Not an optimal method for multiple reasons:
1.  Content on there was very rarely up to date because taking the drive out of the safe and copying files was a pain. 
2.  I’m putting a lot of trust that the safe is actually fire proof, and that it still wont get hot enough to run the drive in the case of a fire.

However I came up with a new plan the other day that uses Windows Live Sync.  I created 4 root folders on my “Files” drive: Documents, My Music, My Pictures, My Videos.  And all content is stored in their respective folder.  I then set up Windows Live Sync on my desktop with profiles for each of those folders.  Next I brought my external hard drive to work and set up sync profiles for those folders to the external hard drive.  So my system basically acts like DropBox, without the space limitations (but also without the online storage).This has been a great choice so far because:
1.  My files are automatically synced to an off site location with no space limitations (except my own hard drive space).
2.  ANY file I update or create at work or at home is automatically synced.
3.  Completely Free! (not counting the cost of the hard drives which I already had).

You might be wondering why I created 4 profiles if I’m backing everything up.  The reason is that I am also syncing “My Pictures” to my notebook computer.  My wife uses our notebook much more frequently than the desktop, and Windows Live Sync plays well with Windows Live Photo, so she can put photos from the camera onto the notebook and everywhere else is updated automatically.

One thing to note is that I have about 400 gigs of content so before bringing my external hard drive to work I manually copied the files via the usb connection so that it wouldn’t take forever to get all of the files.

Tech: Cool Desktop Backgrounds

Windows 7 has a nice feature that will change your desktop background every 30 minutes (configurable).  When setting up a new Windows 7 computer my first item of business is to select a theme.  Right click and select “Personalization” to choose a theme.  Then on the Personalization window you can click “Desktop Background on the bottom and it will show you the pictures that are a part of the theme.  From here you can choose the pictures that show up as part of the theme and tell windows where to look for more pictures.  I’ve been putting new photos directly in the United States them folder at C:\Windows\Globalization\MCT\MCT-US\Wallpaper.  The best site I’ve found for getting desktop images is www.caedes.net.  Caedes is sort of a YouTube for desktop background (all user created content).  Recently I’ve discovered another nice site at http://www.shiftedreality.com/, this is all one person’s work, some photography, some rendered, all very nice.

Friday, October 9, 2009

Code: Open Video Player Smooth Streaming ag_e_unable_to_play

If you are receiving the ag_e_unable_to_play or ag_e_network_error while attempting to do smooth streaming using the Silverlight Open Video Player (OVP) you may need to download AdaptiveEdge.xap.  This file does NOT come with the OVP download in the plugins directory.  I'm not sure why this is, especially since their own example.html references it!  I was able to view the source of http://www.smoothhd.com/ and download the file from http://www.smoothhd.com/plugins/AdaptiveEdge.xap

Wednesday, October 7, 2009

Home: Store Bread in your Refrigerator

We used to store our bread in a breadbox on the counter.  However we never seemed to be able to finish a loaf before it got moldy.  We've now moved the bread into the refrigerator and it seems to keep good much longer (3x longer or more).  Not that bread is expensive to replace, but it is much more of a convenience to actually have bread around when you want a sandwich.

Code: Develop Code in Unit Test Classes

I've never been good at getting myself to write unit tests, its just not fun to write code to test code.  However I've realized today that usually I end up writing console applications to test my business objects as I develop them, why not start with this code in a unit test?  That way if you don't come back later to more fully create your tests, at least you have something there.

Monday, October 5, 2009

Code: C# Escaping Curly Braces in String.Format

With the Format() method of String in C#, you use numbered braces to denote replacement positions.  If you want to display braces in your formatted text you need to escape them by entering the brace twice:

String.Format("{{ Go to {0} for help}}", "http://www.google.com");

Thursday, October 1, 2009

Code: Silverlight Video Player Not Displaying In Firefox

I ran into an issue today where the Silverlight video player on my web page would display in IE and Opera but not Firefox or Chrome.  The issue is with how the browsers handle the height and width specifications on the object tag.  If the html item that contains the object tag does not have a height specified in pixels, then the object tag must.

So changing my code from

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" 
width="100%" height="100%" id="slp">

to:

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" 
width="400px" height="400px" id="slp">



resolved the issue.

Wednesday, September 16, 2009

Windows 7: Sound Problems on Dell Studio 15 Notebook

Windows 7 stopped acknowledging the onboard speakers on my Dell notebook yesterday.  The only output options I had were via the HDMI port and the headphone jack.  Everything looked normal in device manager (no missing drivers) and no new software was installed to my knowledge.  I ended up fixing the issue by re-installing the audio drivers from the DVD that came with the computer.  Since Windows 7 was not the OS that came with the computer when I got it I had to choose Vista as my OS, but everything installed normally and the issue was resolved.

Tuesday, September 15, 2009

Code: Handling SQL Command Timeout Errors

Unfortunately there is not an exception object in .Net that corresponds directly to a command timeout.  However you can specifically handle one by checking the Number property on the exception.  The number for an SQL Exception happens to be –2 (Using reflection you can see the TdsEnum in System.Data.SqlClient).

catch (SqlException ex)
{
//Sql time out exception number is -2
if (ex.Number == -2)
{
//timeout exception, tell user to try changing params
lblTimeOut.Visible = true;
}
else
{
throw (ex);
}
}

Code: Setting Command Timeouts using Data Access Application Blocks

When doing database work in .Net you can set a timeout value in your connection string.  This timeout specifies the length of time (in seconds) to wait for a connection to the database server to be established.  If you want to specify a timeout value for your stored procedure in SQL command to complete, you need to set the time out on your command object.  If you are using Enterprise Library’s Data Access Application Blocks your code should look similar to below

Database db = DatabaseFactory.CreateDatabase("ConnectionStringName");
using (DbCommand cmd = db.GetStoredProcCommand("StoredProcedureName"))
{
    cmd.CommandTimeout = 60;
    int rowsAffected = db.ExecuteNonQuery(cmd);
}

Tuesday, September 8, 2009

Code: ASP.Net MVC Maintain Checkbox State

Below is a quick and dirty way to maintain a check box checked state during postbacks with MVC:

<%= Html.CheckBox("IsSecure", (Request.Form["IsSecure"] ?? string.Empty).Contains("true"))%>

Code: ASP.Net MVC SelectList / DropDownList Selected Item

I spent an hour on a strange issue on my MVC page the other day where MVC would not obey my SelectedItem assignment on a drop down list.  I originally thought the issue was how I was making the assignment in code, or the object I was using to do the binding, but it turns out that some built in MVC functionality was actually working against me.  If you name your ViewData key name the same name as your Html.DropDownList item, MVC will attempt to populate the selected value for you.  However I wanted to manually set the selected value so my solution was to change this:
<%= Html.DropDownList("Encoding", ViewData["Encoding"] as SelectList)%>

to:
<%= Html.DropDownList("Encoding", ViewData["EncodingData"] as SelectList)%>

And in my controller I just needed to change the ViewData key name accordingly:
Dictionary<string, string> pushPull = new Dictionary<string, string>();
pushPull.Add("pull_encode", "Pull");
pushPull.Add("push_encode", "Push");
if (pushPullValue == "") pushPullValue = "pull_encode";
ViewData["EncodingData"] = new SelectList(pushPull, "Key", "Value", pushPullValue);

Wednesday, September 2, 2009

Fitness: Listen to Music to Improve Your Workout

There have been numerous studies on the effect of listening to music during exercise, Men's health has a good summary and recommendations in their article The Science of Workout Music.  Below is a list of songs that seem to work well for me.  These are just some initial suggestions, use whatever motivates you.

Kanye West - Stronger
Kanye West - Gold Digger
Linkin Park & Jay-Z - Numb/Encore
Linkin Park - Somewhere I Belong
Paramore - For a Pessimist I'm Pretty Optimistic
blink-182 - All the Small Things
Fergie - London Bridge
Linkin Park - Papercut
Aerosmith - The Other Side
All American Rejects - Dirty Little Secret
Aerosmith - Mama Kin
All American Rejects - Move Along
Fall Out Boy - This Ain't A Scene, It's An Arms Race
blink-182 - Dammit
Buckcherry - Lit Up
Green Day - Basket Case
Eminem - Lose Yourself
Linkin Park - What I've Done
Linkin Park - Faint
Def Leppard - Promises
Green Day - Hitchin' A Ride
Everclear - Santa Monica
Eminem - The Way I Am
Evanescence - Taking Over Me
American Hi-Fi - Flavor Of The Weak
blink-182 - Adam's Song
Green Day - Brain Stew
Jay-Z - I Just Wanna Love U (Give It 2 Me)
Limp Bizkit - My Way
Lit - My Own Worst Enemy
Missy Elliott - Gossip Folks
New Found Glory - My Friends Over You
Pink - Sober
Rage Against The Machine - Renagades of Funk
Van Halen - Dance The Night Away
Van Halen - Why Can`t This Be Love
Van Halen - Right Now
Theory of a Deadman - Bad Girlfriend
Theory of a Deadman - So Happy
Tantric - Breakdown
Sum 41 - In Too Deep

Tuesday, September 1, 2009

Tech: Opera 10 Web Browser First Impressions

First let me admit that my current web browser of choice is Firefox, however I also have chrome and IE (and now opera) installed.  Opera 10.0 was released today so I thought I'd take a look and see how it stacks up.  The download is 6.6 MB, so not a bad size.  Installation is quick, choosing custom just lets you change the install path and choose to create start menu, desktop, or quick launch icons.  One thing to note that I installed this on Windows Server 2008 which only has the Windows classis UI, so buttons etc may look different.

The screen shot below is Opera 10 on Google's home page.  One issue I noticed immediately is the address bar didn't span the whole width when I reduced the size of the window for the screenshot.  This was remedied by expanding the size of the window which then showed the address bar and the search bar, and resizing the width by clicking between the two boxes.  I think I prefer chrome's approach to having a single bar for both purposes.

Opera on the left, Firefox on the right.

image image

I then opened 4 tabs with both browsers:

image image

With Google.com, omaha.craigslist.org, Hulu (paused on a video), and eBay.com pages loaded. Opera was using 176,000K of memory, Firefox was at 187,000K.  My machine has 6 gig of ram so even though those numbers seem high I still have plenty to spare on my system, they may be more frugal on system with less memory (but maybe not).  After killing all the open tabs except Google, Firefox's memory usage dropped to 89,000K whereas Opera hung around 149,000K.  Unexpectedly I did not have to install flash on Opera's browser when I went to Hulu.  So I then went to a Silverlight site and didn't have to install it either.  Nice. 

Opera feels very fast when navigating.  Pages load like they are in a hurry.  Opening a new tab loads a speed dial window showing your most visited sites in thumbnails.  There is a little x in the top right corner to remove unwanted items from the speed dial page.

image

One feature that only Firefox has implemented which keeps it at the top of my list is the ability to select a section of the page, right click and choose "View Selection Source" so you can see the html of your selection.  This feature is also not available in Opera 10.  New to Opera 10 is inline spell checking, so the browser will underline misspelled words in text boxes (this feature is available in Firefox).

I was unable to select gMail as my mail service when clicking on mailto links.  The 4 options shown to me were Yandex, Fastmail, Opera Mail, and Mail.ru.  I use (and have never heard of none of these).  I've read other blogs that seem to show gmail being provided as an option.  I don't know why it wasn't provided to me.  I even went to my gmail with opera logged in, restarted the browser, and still no change.  This will be a deal breaker if I cannot resolve the issue.

For the brief set of pages I visited Opera rendered all content correctly and quickly, and seemed faster than Firefox.  However the lack of "View Selection Source" and using gmail as my default mail provider leaves Firefox as the reigning browser of choice for me.

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:
[XmlInclude(typeof(InheritedClassName1))]
[XmlInclude(typeof(InheritedClassName2))]

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.

 image

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?
 
Nick
Ben
Adam
Chad
 
Overall
1 Airplane
2 Forest Gump
3 Gladiator
The Shawshank Redemption
GhostBusters
Forest Gump
Gladiator
Fight Club
Snatch
Groundhog Day
Kill Bill V2
L.A. Story
 
SciFi
1 Matrix
2 Star Wars
3 Short Circuit
The Matrix (I)
Return of the Jedi
The Fifth Element
Matrix
The Fifth Element
Gattaca
Dark City
Fifth Element
12 Monkeys
Drama
1 Forest Gump
2 Shawshank Redemption
3 American History X
The Shawshank Redemption
Forest Gump
Saving Private Ryan
Good Will Hunting
Phenomenon
American Beauty
Pulp Fiction
Being John Mal
LA confidental
Comedy
1 Airplane
2 Back to the Future
3 The Hangover
GhostBusters
Back to the Future (I)
European Vacation
Snatch
Christmas Vacation
Back to the Future
Groundhog Day
Superbad
Anchorman
Action
1 The Rock
2 Fight Club
3 Bourne Identity
The Bourne Identity
Raiders of the Lost Ark
Terminator II
Fight Club
The Bourne Identity
Transformers
Kill Bill
Batman Begins
Diehard
Horror
1 Se7en
2 Saw
3 The Shining
The Shining
The Exorcist
Night of the Living Dead
Scream
Se7en
Halloween
Scream
Alien
Aliens
Adventure
1 Gladiator
2 Lord of the Rings
3 Braveheart
LOTR - Return of the King
the Last Crusade
Braveheart
Gladiator
Braveheart
Lord Of The Rings
Lord of the Rings 1
Lord of the Rings 3
Lord of the Rings 2
Suspense
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
Heist
Signs
Sixth Sense
Romantic
Comedy
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
Roxanne
Animation

1 Toy Story
2 Shrek
3 Monsters Inc

Shrek
Toy Story
Monsters Inc.

Finding Nemo
Toy Story
Monsters Inc

Monsters Inc
Incredibiles
Shrek

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)
And
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);
});
</script>


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: http://blog.milrr.com/search/label/Code. If you're only interested in !Code you can use http://blog.milrr.com/search/label/NotCode.
Thanks again for visiting.
Enjoy!