Archive for the ‘Programming’ Category

Book Review: Automate with Grunt — The Build Tool for JavaScript

Automate with Grunt is an excellent book on how to automate your workflow using Grunt, JavaScript’s task runner. Brian P. Hogan has written a lightweight book that is heavy on the content you need, stripping away all of the unnecessary text, and getting right to the heart of the matter: ways to use Grunt.

I appreciate how he started the book with the basics of using Grunt – creating tasks, expanding tasks to accept inputs and have one or more outputs, chaining and multitasks, manipulating files on the file system – before moving on to more complex automation exercises. Brian then introduces how to utilize Grunt to execute a real-life workflow scenario, with all of the considerations that must be made when doing so. He finishes up with building Plug-ins with Grunt and, taking things a step further, creating project scaffolds to take care of the mundane setup associated with a new project.

All of the Examples Brian uses are practical and apply to things that developers face daily in their jobs and careers. I liked that he introduced Bower into the examples early on, as this is a commonly used package manager for web sites and applications. And though I am not a fan of CoffeeScript, it was easy to ignore that fact when it was introduced, as it did show the true power and potential of Grunt as an automation tool.

I would recommend this book to anyone who is new to Grunt and just starting to learn it, or anyone who wants to take their Grunt task runner to the next level in the automation needs of their web projects.

***** (5 stars)

Categories: Books, Programming Tags:

Proper Case Script for ESRI’s ArcMap

January 16, 2011 Leave a comment

I want to make sure that any maps I make in ESRI’s ArcMap look as good as possible, and one thing I believe looks good on a map is street names having proper case. That is, instead of the name being completely uppercase or lowercase, the first letter of each word is capitalized while the rest of the letters in the word are lowercase.

The problem I have run into with the county’s data is that everything in the system seems to be capitalized, whether is be street names, the owner’s name to a parcel, or whatever. Everything is all uppercase. This is fine for within the database, actually I have issues with it, but I do not want to get into that in this blog post. So, what am I to do? After several iterations, I have hammered out what I think is a pretty good VBScript solution which will take the uppercase data passed to it and return a proper case result. In the following example, I am getting as parameters the street name (i.e. MAIN) and the street type (i.e. ST), but this could be altered to first and last name, or only a single parameter; you get the idea. This script takes care of names with spaces and apostrophes too.

Function FindLabel([ST_NAME], [ST_TYPE])
  Dim label, labelWords, i, j, retVal, word, apostWords 

  label = [ST_NAME] & “ “ & [ST_TYPE]

  If (NOT IsNull(label) AND Len(label) > 0) Then
    labelWords = Split(label)
    For i = 0 To UBound(labelWords)
      If (i > 0) Then
        retVal = retVal & " "
      End If
      word = UCase(Left(labelWords(i), 1)) &  LCase(Mid(labelWords(i), 2))
      apostWords = Split(word, "'")
      word = ""
      For j = 0 To UBound(apostWords)
        If j > 0 Then
          word = word & "'"
        End If
        word = word & UCase(Left(apostWords(j), 1)) & LCase(Mid(apostWords(j), 2))

      retVal = retVal & word
    retVal = ""
  End If

  FindLabel = retVal
End Function


Feel free to use this within your ArcMap’s Label Expressions and I hope it helps someone else out in the future.

AUTHOR NOTE: I had originally written this function in JScript, but for some unexplainable reason, ArcMap simply did not like my code, so I switched to /sigh/ VBScript instead.

Categories: GIS, Programming Tags: , ,

HTML5 Bandwagon

September 22, 2010 Leave a comment

I am officially jumping on the HTML5 bandwagon — I know I was always a strong proponent of XHTML, but I see great potential here. I am currently reviewing HTML5: Up and Running (O’Reilly) by Mark Pilgrim, and my mind is filling up with ideas for what I can do with it. Especially the <canvas> element, oh my!

But I figured I should learn more about all of this new stuff, especially since I have reentered the programming world after an almost three year hiatus. So I am also taking a free HTML5 Mobile course from @oreillymedia and @creativeLIVE starting October 5, 2010 that runs ten weeks (until December 7, 2010). Check out the course at

Book Review: Building the Realtime User Experience

September 9, 2010 Leave a comment

The Web is moving ever faster towards sites that give users what they want, not when they load or refresh pages, but rather in real time. Understanding how this works and how to leverage it on your own site so that it is useful to the user is important knowledge any developer should have. In his book, Building the Realtime User Experience, Ted Roden does just that.

Building the Realtime User Experience breaks down the technologies that make the most sense for a developer to deliver to the user in realtime such as syndication and instant messaging, for instance. One thing the book does that I appreciate is it presents the examples found throughout using different languages, applying the most practical language for a give scenario or toolkit. Doing this does not make understanding the examples very difficult, however, and any developer with reasonable coding skills should be able to follow along in any language without difficulty.

The first chapter gives an introduction into what “realtime” means in terms of the Web and development and lays out the languages the examples will use. From Chapter 2 on, the book jumps right into the different technologies that present well in a realtime format starting with syndication. Roden focuses on two technologies for syndication, Simple Update Protocol (SUP) and PubSubHubbub, giving each protocol pretty much equal treatment, leaving it for the reader to decide which protocol to implement. Chapter 3 discusses how to implement widgets that will display realtime on a web page, using Twitter and FriendFeed as examples. What was of more use was the discussion in Chapter 4 on server-side “push” technologies, and the transition into Chapter 5, which introduces the reader to Tornado – an excellent chapter that shows through example how to get Tornado running and in use on a site.

The next three chapters deal with chat, instant messaging, and SMS respectively. In each chapter, Roden gives examples on how to build an application around these technologies, which a web environment can then utilize. The chat application built throughout Chapter 6 is quite robust, as is the instant messaging client/server created in Chapter 7. Chapter 8 then extends the instant messaging service by integrating SMS into it.

I found Chapter 9 to be an interesting chapter, but it differs from the rest of the book in that it focuses on what a developer can do with analytics to view a site from an administrative point of view in realtime, instead of focusing on delivering something realtime to the end user. The examples yielded some interesting concepts and left me considering all of the possibilities for back-end development that I more often than not neglect or even disregard in my own development. Of all the chapters in the book, I think this one is the one I am most thankful Roden took the time to write. Roden finishes the book with a “Putting It All Together” chapter that takes the different applications built throughout the preceding chapters and mashes them together into a realtime game that could be pretty fun with a group of friends.

Overall, Building the Realtime User Experience is a terrific introduction into the realtime Web, and shows the reader just some of the technologies that may work well on a site. The examples are thorough and yield robust applications that are tweakable and integrate into existing sites. I would recommend this book to anyone interested in developing applications or widgets for their site that work in a realtime manner.

***** (5 stars)

Categories: Books, Internet, Programming Tags:

Book Review: Even Faster Web Sites

August 11, 2009 Leave a comment

Today’s Web developer knows that the speed of one’s site is an important measure to its overall success, and Steve Souders’ previous book, High Performance Web Sites (O’Reilly), laid out what seemed to be every way to achieve good performance gains without the sacrifice of functionality or aesthetics. When I began reading Souders’ Even Faster Web Sites, I therefore wondered how he could possibly demonstrate fresh ways to achieve performance gains without regurgitating the content of his previous book. What I discovered as I read Even Faster Web Sites was it presented all new best practices for making your web sites “leaner and meaner” without repeating the content of his last book.

Even Faster Web Sites takes the latest techniques available to developers and organizes them into three performance areas: JavaScript, network, and browser. Though I believe Souder knows what he is talking about regarding web site performance, I found it refreshing this time around that he had the contributions of other experts in the field to give their ideas on performance gains in these areas.

I thought the chapters on JavaScript, especially those discussing Ajax and asynchronous techniques, were well written and gave good, new best practices to trim time off the loading of content on a site.  I also appreciated the chapter dealing with Comet, as these technologies are surely a driving force for future web applications, and having best practices early in their development will only help their progress.  Of the two chapters on browser performance, I found the honesty of the discussion on the downsides of using iframes most helpful, especially when their use was discussed as a viable technique for improving performance early in the book.  I did find the chapter on CSS selectors extremely useful for analyzing where slowdowns in styling may exist based on browser implementation.  The chapters on network performance gave a good background on common hindrances such as connection limits and poor image choices, but also walked through what I felt were performance gains that can be made through less utilized techniques like chunked encoding and better compression.

Souder finished this book with an Appendix on performance tools that can be used to help in the improvement of a web site, which I found to be immensely helpful.  While many tools he listed are well known to developers, there are some I was unaware of and began making use of immediately on my own sites.

Even Faster Web Sites is an excellent follow-up to High Performance Web Sites, giving new best practices for making your web sites even faster.  As I see it, even hundredths of a second begin to add up when you put all of these techniques together, and most of the techniques presented in this book are practical for any web site being developed.  I would recommend this book to any developer looking for ways to improve the performance of his web site, as Souder has certainly demonstrated his knowledge and expertise on improving the speed of a site.

***** (5 stars)

Categories: Books, Internet, Programming Tags:

Creating a random password with PHP

October 31, 2008 Leave a comment

I have been working on getting my domain back up and running, when I ran into the need for new functionality to automatically create a random password for a user should he or she have forgotten theirs.

The following is a partial solution to what I came up with, along with commentary on what the rest of the functionality entailed.

First confirm that the user is indeed who he or she claims to be.  Good ways of doing this are getting a full name, email address, maybe even a birthday.  Next, for my site I give the ability for a user to create their own secret question and answer to go along with it.  This affords a little more security than having canned secret questions — not much, but a little.  The secret question is presented, and when a correct answer is given, I create an email that sends the random password to their account.

Simple enough, so here is the code for the random password part of this solution:

$chars = 'abcdefghijkmnopqrstuvwxyz023456789!@#$';

srand((double)microtime() * 1000000);

$passwd = '';
for ($i = 0; $i < 10; $i++)
    $passwd .= substr($chars, (rand() % 37), 1);

You will notice that in the $chars string I omitted the characters l and 1. I did this because these two characters could be confused with one another, which is something you do not want when sending a random string to a user.

Simple enough. Enjoy.

Categories: Programming Tags: ,

C# XML Documentation Bug for Visual Studio 2005

November 16, 2007 Leave a comment

I have found a bug that only occurs under very specific circumstances as far as I can tell. My setup is Visual Studio 2005 with Visual SourceSafe 2005 as my source control. What I am attempting to do is use XML documentation (I am using C#) to document a class I have written.

I start off with a summary section, followed by a remarks section and everything is fine. Next I wanted to add an example section to show how the class must be configured in the Web.config. That seems harmless enough, so I add the following documentation:

                <add name="WSAuth" type="MyWS.Auth" />

The problem with this is twofold. First, Intellisense is trying to identify each of the XML elements in the example element. Second, when this is documented using Sandcastle, it will not show up correctly.

The solution to this problem is adding <![CDATA[ and ]]> around the example code. This stops Intellisense from attempting to identify the elements, and it will now show up in the help documentation. But instead of being nicely styled in the help document so that it is easy to read, all whitespace is stripped from the help file and the example ends up crunched together like this:

<add name="WSAuth" type="MyWS.Auth" /></httpModules></system.web>

Now I know from previous experience that if I add a code element around the example and CDATA, it will honor the whitespace in the help document and color-code it as well. This is just what I want.

Here is where the bug is introduced. When I try to get my cursor focused on the correct spot in the code using the mouse, Visual Studio hangs. There is nothing that can be done until it finally throws an error (after 10 minutes or so) complaining about a runtime problem, upon which time it promptly crashes. Here is what is says:

VS 2005 Documentation Bug

I have no idea what is causing this. I do know that if you type <code> and </code> somewhere else and then cut-and-paste you can get around the problem. But it could still hang even while attempting this. I would love to hear anyone’s idea solution to this problem.