Fun with Javascript pointers

I just spent the last hour trying to debug some Javascript code that wasn’t working the way I expected. It turns out I was dealing with the shallow copying behavior of Javascript. If you deal in Javascript objects regularly, you need to know this information! Here is a quick example that illustrates what I saw while debugging today: // First object, with a simple string property args1 = {}; args1.test1 = "blah"; // Second object, 'created' from the first args2 = args1; // As you might expect....

July 15, 2011 · 2 min · 243 words · Dan Esparza

Using Remember the Milk as a desktop task list

Using the free and excellent service Remember the Milk as your tasklist is great – but sometimes you need a nice simple tasklist you can keep close at hand on your desktop. If you use Google Chrome as your browser, there is a very easy way to do this. In Chrome, visit: http://www.rememberthemilk.com/services/modules/googleig/ (this should bring up your task list in Remember the Milk in a tiny view) Then in Chrome, select the ‘wrench’ icon, select ‘Tools’, and then select ‘Create Application Shortcuts’....

June 22, 2011 · 1 min · 106 words · Dan Esparza

Using the CollectionAssert class in a C# unit test

Unit testing with collections can be tricky, especially when you’re trying to compare collections. Enter the lowly ‘CollectionAssert’ class in C#: // Assert: // 1.) These items are not null // 2.) These items are of type MyClass // 3.) The expected collection is the same as the actual collection CollectionAssert.AllItemsAreNotNull(actual); CollectionAssert.AllItemsAreInstancesOfType(actual, typeof(MyClass)); CollectionAssert.AreEqual(expected, actual); // Also: // 4.) The collection we expect to be filled shouldn't be the same as the empty one // 5....

June 15, 2011 · 1 min · 93 words · Dan Esparza

A re-introduction to the Chrome dev tools

Here is a great presentation on the Chrome developer tools by Paul Irish and Pavel Feldman. PDF notes available from Google. A delightful Chrome Developer tools cheatsheet is also available in PDF and PNG formats from Paul’s colleague Boris Smus. ...

June 10, 2011 · 3 min · 543 words · Dan Esparza

Getting a 401.1 error when using IIS and NTLM security

Sometimes as a developer, it’s necessary to setup a website on your local IIS system to use NTLM or Windows based authentication. In an effort to make things a bit more secure in the OS, Microsoft has also made things a bit more difficult for developers when trying to setup NTLM locally for a specific website. If you find yourself getting a 401.1 error after configuring a local website to use Windows based authentication, follow the directions here and use option 1 if you can....

June 3, 2011 · 1 min · 85 words · Dan Esparza

Using jQuery on Google's CDN but having a plan B

For personal projects or (even not so personal projects) using Google’s CDN hosted jQuery libraries is a no brainer. But what happens when you need a plan B? Or what happens when you realize that you need to have a fallback plan just in case Google is banned in a country where you have website visitors? Well, the answer is a pretty neat trick I just learned. Taking advantage of the fact that Javascript is loaded synchronously – you can have a set of script tags that look like this:...

June 3, 2011 · 1 min · 118 words · Dan Esparza

Using the dig dns tool on Windows 7

Traditionally, nslookup is the tool of choice when trying to find out information about IP addresses or DNS information in Windows. In the Linux world, nslookup has been deprecated for a long time. The preferred way to query for dns information from the command line is the Domain Information Groper or ‘dig’ dns tool. Interested in learning more about DNS and dig? Check out this book: What can you do with dig? Using dig, you can find out what a particular dns server thinks the given host’s IP address should be, including a lot of other information that is also very helpful. For example, running this command: ...

May 17, 2011 · 7 min · 1285 words · Dan Esparza

jQuery tip: Operate on more than one item at the same time

Sometimes it’s useful to perform an action on more than one item on the page at the same time - like when hiding or showing a series of elements all at the same time. With jQuery selector syntax, this is very easy. First, if you’re not familiar with basic CSS or jQuery selectors, you should probably start there. Once you’re familiar with that basic syntax however, you’ll be happy to know you can combine selectors with a comma (using the ‘multiple selector’ syntax), like this:...

January 24, 2011 · 1 min · 89 words · Dan Esparza

Using Gravatar images with C# / ASP.NET

Including profile pictures in your application from the nifty (and free!) gravatar service is very easy, assuming you’ve already got an ’email’ field for your users that you’re tracking. To use the system, you just need to form a url that points to the user’s profile image (using a hash of their email address) and use that url in an image tag. The url looks something like this: Format: http://www.gravatar.com/avatar/{md5 hash} Example: http://www.gravatar.com/avatar/73543542128f5a067ffc34305eefe48a The basics But how do you create the MD5 hash of the email address? No problem. You can use .NET’s built-in crytography libraries to help you. Here is a nice helper function that takes an email address and forms the hash you’ll need in the gravatar url: ...

October 19, 2010 · 2 min · 326 words · Dan Esparza

Tips for using jQuery validation

<div id="content" style="padding: 10px;"> <form id="frmTest" method="get"> Lots of other content here<br /> Lots of other content here<br /> Lots of other content here<br /> Lots of other content here<br /> Lots of other content here<br /> Lots of other content here<br /> <input id="txtEmail" name="txtEmail" type="text" class="required email"/> <br /> <input id="txtName" name="txtName" type="text" class="required" minlength="2"/> <br /> Other content <br /> <button id="btnValidate" type="button">Test validation</button> </form> </div> label....

October 5, 2010 · 1 min · 132 words · Dan Esparza