Attend Give Camp or the X Conference? Both!

Torn between attending Lansing Give Camp or the Kalamazoo X Conference?
You don't have to choose; do both!

Give Camp or X Conference?

The first ever Lansing Give Camp is being held April 24-26. The first ever Kalamazoo X Conference is being held April 25. The sessions of the X Conference offer a great opportunity for learning and for improving your craft. For $20, you can't beat that. But Lansing Give Camp is a weekend of giving back to the community by helping out local charities. Coding for a cause; you can't beat that, either. Two amazing events, slightly more than an hour from each other, are being held the same weekend. It's like a bad case of deadlocked threads. Kalamazoo or Lansing? Lansing or Kalamazoo? How do you choose between them?

You don't have to choose. Go to both.

Spend the weekend in Kalamazansing!

Kalamazoo X Conference and Lansing Give Camp have partnered together. Lansing Give Camp will have special projects that will accommodate X Conference attendees. Kalamazoo X Conference is waiving its registration fee for anyone attending Lansing Give Camp. Friday night, come out to Give Camp. Saturday morning you can grab a shower (thanks to a partnership with the Lansing YMCA), and head out to Kalamazoo. When the event is over, finish out the weekend back in Lansing, coding for a cause. It's almost like one big event, spread between two Michigan cities. Kalamazansing.

I want to go to Kalamazansing!

Sign up Lansing Give Camp at http://www.lansinggivecamp.org. The registration form includes an option to sign up for the X Conference, too. We'll take care of the rest.

Lansing Give Camp 2009, April 24-26

LansGiveCamp2009 On April 24th-26th, 2008, the local software development communities will pool their talents to put together the first ever Give Camp in Lansing Michigan. The event will be hosted at the Impression 5 Science Center in downtown Lansing. For more information, please visit the event's web site, http://www.lansinggivecamp.org.

Lansing Give Camp

April 24-26 at the Impression 5 Science Center
200 Museum Drive, Lansing, MI 48933
http://www.lansinggivecamp.org

What is a Give Camp?

A Give Camp is a weekend-long event where software developers, designers, and database administrators donate their time to create custom software solutions for non-profit organizations. This custom software could be a new web site for the nonprofit organization, a small data-collection application to keep track of members, or an application for the Red Cross that automatically will email a blood donor three months after they've last donated blood to remind them that they are again eligible to donate blood. The only limitation for a Give Camp project is that it must be scoped to be completed within a weekend.

During the event, developers are welcome to come and go as they please. The event will continue 24/7 from Friday afternoon through Sunday afternoon, and developers can choose to go home in the evenings or camp out for the entire weekend. Showers are not available at the Impression 5 facility, but the Lansing YMCA--just down the street--is donating their facilities throughout the weekend for any Give Camp attendees.

How can I help?

If you are a developer and are interested in attending, please go to the event web site and register for the event. We are looking for developers of all skill levels to help out, from students to senior developers, and for developers of all skill sets, including designers, developers, database administrators, and more. If you can code, we want you there!

What about Sponsorship?

Lansing Give Camp is seeking cash donations of any amount, or the sponsorship of a meal. A meal sponsorship would entail funding breakfast, lunch, or dinner for roughly 100 volunteers. Typical meals would be sandwiches, pizza, or BBQ. As consideration for your donation, your organization’s logo will be added to the Give Camp web site, along with mention during the opening and closing sessions.

Technorati Tags: ,,

[Fixed] Adding DotNetKicks FeedFlare to FeedBurner

FeedBurner used to allow adding DotNetKicks FeedFlare to your feeds. Even today, the FeedFlare catalog lists "Kick It" using DNK's FeedFlareUnit file. Unfortunately, when adding this file to FeedFlare using the link given in the catalog, the unfortunate user receives only a JavaScript alert of "We could not find a valid FeedFlare file at that location" instead of an enhanced feed. Why? No XML Declaration is contained within DNK's XML file.

Example XML Declaration

<?xml version="1.0" encoding="utf-8"?>

By adding only an XML Declaration to the top of the file, FeedBurner is now able to properly parse the document, and add the new flare to a feed. This would also apply to any custom FeedFlareUnit that you develop; be sure to add an XML Declaration to your XML.

Corrected File for DotNetKicks

Download: kickitflare.xml

<?xml version="1.0" encoding="utf-8"?>

<FeedFlareUnit>

  <Catalog>

    <Title>Kick it</Title>

    <Description>Kick this story on dotnetkicks.com</Description>

  </Catalog>

  <FeedFlare>

    <Text>Kick it</Text>

    <Link href="http://www.dotnetkicks.com/kick/?url=${link}" />

  </FeedFlare>

</FeedFlareUnit>

I have logged a ticket with DotNetKicks on their Google Code issue tracker. Hopefully, as opportunity allows, they can update the file on dotnetkicks.com so that the FeedFlare catalog entry will work once again. Feel free to add DotNetKicks FeedFlare to your FeedBurner feed using the file link above until they have an opportunity to address the ticket.

Adding DotNetKicks FeedFlare to your FeedBurner Feed

To add the "Kick It" FeedFlare to your existing FeedBurner feed:

  1. Copy the URL for the updated kickitflare.xml file to your clipboard:
    http://www.cptloadtest.com/content/text/kickitflare.xml
  2. Log in to FeedBurner at http://feedburner.google.com
  3. Navigate to your feed details, then to the Optimize tab, then to FeedFlare
  4. Paste the URL into the textbox, and click Add New Flare.
  5. As desired, check the appropriate checkboxes to add the flare to your RSS feed and to your site.
  6. Click the Save button at the bottom of the page.

Dev Basics: What is Continuous Integration?

Scheduled Integration is hard. I remember being involved in projects where developers would get a copy of the latest source code and a task, and race off like horses at the track while they spent a few weeks implementing their assigned feature. At the end of these many weeks was a scheduled integration, where all developers in the team would reconvene with their code modifications, and try to get their respective code to play well in a single sandbox. Project managers always seemed to expect that this would be a quick and painless process, but, of course, it never was. Reintegration of the code sometimes took just as long as the implementation, itself. Even if developers are all working in one big room throughout the project, the code remains isolated, never shared or reintegrated. Fortunately, Continuous Integration specifically focuses on this problem by reducing (and often eliminating) the end-of-project reintegration cycle through a continuous constant integration process.

Continuously Integrating your Mind

For a moment, compare  the process of software development with the process of learning new technologies in your field. In the past few years of Microsoft's .NET platform, we've seen .NET 2.0, Windows Communication Foundation, Windows Presentation Foundation, Workflow Foundation, Extension Methods, Generics, Linq, Dynamic Data, ASP.NET MVC, and more. For a developer that has not kept up with the latest trends, to suddenly and quickly catch up with the bleeding edge would be a major undertaking, and psychologically intimidating. This Scheduled Integration approach to learning can be overwhelming; the learning process is isolated, and only occasionally reconnects to the latest technologies. However, a developer that has kept up with the trends, learning through a continuous integration process, has been constantly updating, constantly learning the Next Big Thing over these past few years; this developer is already long familiar with .NET 2.0, WF, WCF, WPF, Generics, and Linq, and is now working on only Dynamic Data and MVC. The Continuous Integration process ensures that those involved are current with the latest developments in their project, and that the overwhelming burden of integration at the end of a project is instead simplified by distributing it throughout the course of the timeline.

Core Continuous Integration

At its core, Continuous Integration, or CI, is a development model where developers regularly commit and update against their source control repository. By committing (giving everyone else access to your code changes) and updating (getting code changes from everyone else), the scheduled, tedious integration process at the end of the project is eliminated. Added on top of this single fundamental, is ensuring the code works: Automating the build through scripting frameworks like Make, MSBuild, or NAnt helps developers validate their status quickly, by invoking a validation step that not only compiles, but executes a suite of unit tests against the code base. Validation results, along with the latest valid code, are then made easily accessible to anyone on the team.

The ten tenets of Continuous Integration are:

  1. Maintain a Source Code Repository
    Use a code repository, such as Subversion, Bazaar, or even Visual Source Safe. This allows a central point-of-truth for the development team, against which code can be committed or updated. This even applies to a development team consisting of only one person, as a local hard drive alone cannot provide change logs, revision differences, rollback capability, and other benefits of source management.
  2. Commit Frequently
    As other developers commit code changes, your local version of the code will get further and further from the revision head, thus increasing the likelihood of a conflicting change that will need manual resolution. By committing often (and by association, updating even more often), everyone can stay very close to the revision head, reducing the likelihood of conflicts, and reducing time to integrate code and functionality.
  3. Self-Testing Code
    "It compiles" is not sufficient criteria for determining if a project is ready for delivery or deployment to the client. Some level of testing must be conducted against each compile to measure application quality. Using unit tests, functional tests, or some other form of automated acceptance tests, the code can evaluate itself against expected outcome, providing a much more accurate and granular metric for readiness.
  4. Automate the Build
    Using Make, NAnt, MSBuild, or similar frameworks, consolidate execution of your full build into a single command, or a single icon on your desktop. These scripts should execute a full compile, and run your full suite of testing and evaluation tools against the compile.
  5. Build Fast, Fail Fast
    Even if your build is automated, no one wants to wait 30 minutes for the build to complete. Building your code should not just be a lunch-break activity. Keep the build fast to enable developers to do so as often as possible. And if there is a problem, fail immediately.
  6. Build Every Mainline Commit on an Integration Machine
    We all have applications on our local desktops that will not be present in Production. Instant Messenger, iTunes, Visual Studio, and Office are all common for us, but rare in Production. However, these applications can conflict or distort build results, such as a reference to an Office assembly that is not included in your deployment package. By executing the automated build on an integration machine (iTunes free, and using a CI suite like Hudson or CruiseControl), you can increase confidence in your application and eliminate "it works on my box!"
  7. Automate the Deployment
    Manual code deployment is a mundane, highly repetitive, error-prone, and time-consuming process that is ripe for automation. The time commitment adds to the stress when QA requests yet another deployment to the testing environment, particularly when all of the developers are in 80-hour-week crunch mode. In turn, this stress reduces deployment quality; environments often have configuration differences, such as different database connection strings, credentials, or web service URLs, and often only one configuration change needs to be overlooked to cause the entire system to malfunction. Automate this task, so that it can be executed easily, dependably, and often.
  8. Test in a Clone of the Production Environment
    In addition to Office and iTunes not being a part of the production server build, there are aspects of the production environment that are not a part of the desktop environment. Server farms, federated databases, and load balancing are examples of things that do not exist on the developer desktop, but do exist in production, and can cause surprises if they are not considered during development and testing. Consider the haves and the have-nots in your test environment, and eliminate these surprises. And if the cost of another production environment is out of reach, consider Virtual Machines. VMs have significantly reduced the cost of creating things like server farms or database clusters; even if you cannot exactly replicate your production configuration, mitigate your risk by reducing the differences between your test and production environments.
  9. Everyone Can View the Latest Build Results
    The underlying driver behind Continuous Integration is transparency and visibility. Communication enables both transparency and visibility by allowing everyone on the team to know the full status of the build. Did it compile? Did the unit tests pass? Which unit tests failed? Did the deployment work? How many seconds did it take to compile the application? Who broke the build? Continuous Integration suites, such as Hudson or CruiseControl, provide reporting mechanisms on build status. Make this status available to anyone, including project managers, and even the sales guy.
  10. Everyone Can Get the Latest Executable
    On a software development project, communication is more than just green icons (successful builds) and red icons (failed builds). Communicate the ones and zeros, in the form of your compiled application, to your team. By allowing other developers, testers, and even the sales guy (perhaps for a demo) to get the latest bits for themselves, developers can focus on writing code.

Benefits of Continuous Integration

By continuously integrating all new code and feature sets, development teams can eliminate that long and tedious scheduled integration effort, which reduces overall effort, time line, and budget. Through self-testing code and building every mainline commit, code is continuously tested against a full suite of tests, allowing quick analysis and identification of breaking changes. Through the easy accessibility of the latest bits, the team can test early and often, allowing quick identification of broken functionality, and for early identification of features that don't quite align with what the client had in mind. And finally, the immediate and public feedback on the success or failure of the build provides incentives for developers to write code in smaller increments and perform more pre-commit testing, resulting in higher quality code.

I consider Continuous Integration to be an essential, required part of any development effort, every time. I started using CI in 2004, and I have since become dependent on it. I even have a Continuous Integration box at home, validating home projects for my development-team-of-one, and I am comforted by having a Continuous Integration server analyzing and validating every code change that I make. I break unit tests as often as anyone else does, and there still continues to be plenty of times that I even break the compile. At least once, every developer among us has checked in the project file while forgetting to add myNewClass.cs to Source Control. It will break the compile every time. Fortunately, Continuous Integration is always watching my code commits; it will let me know that it could not find myNewClass.cs, every time. And my application's quality is remarkably better for it. Every time.

Changing of the Guard at Ann Arbor .Net Developers

February was election month for us .Net Developers in Ann Arbor, Michigan. On February 11th, during the monthly meeting, the Ann Arbor .Net Developers user group held its annual elections. After serving as the group's leader for the past 3 years--ever since the group was formed--Bill Wagner decided to hand over the reigns. When the election dust settled, I stood as the 2nd President of the Ann Arbor .Net Developers. I appreciate the honor and the opportunity given to me, and I look forward to serving the group for 2009.

The Elected

President: Jay Harris
Vice Pres: Scott Zischerk
Secretary: Darrell Hawley
Treasurer: Eric Bratton

That evening, after the meeting, we held our first board meeting, as we were responsible for filling the two appointed positions: Program Chair and Webmaster. As the group has grown, so have these two roles. Program Chair turned into a catch-all for most of the membership and speaker management, and was an overload for one person. Webmaster had changed, too, as the group's web site is no longer the only communication medium we employ.

We restructured these two appointed positions into four. Program Director is responsible for knowing what people want to learn about, and making sure that our schedule is booked solid with great speakers. Webmaster has been rebranded as Communication Director, and is the public voice of our group; the position is responsible for any articles and communications published by the group, and also for maintaining the web site, Twitter, Facebook, and all of our other various methods of getting the word out. Membership Director is one of our entirely new roles, responsible for maintaining demographics on the group, membership listings, and swag. Finally, we wanted to ease the burden on our group membership and work towards eliminating our member-dues fiscal model; the new Sponsorship Director is responsible for finding sponsorship funding to help run our group.

The Appointed

Program Director: Mike Woelmer
Membership Director: Dennis Burton
Sponsorship Director: Brian Genisio
Communications Director: Len Smith

The new board has some great ideas for the upcoming year, and I'm excited to be a part of it. And a sincere thank you goes out to the departing board members, Bill Wagner (President) and Dave Redding (Vice President); we appreciate the effort that you have put in to this group.

Posted by Jay Harris is Cpt. LoadTest
Filed under: ,

Quick Tips: Changing Subversion Commit Comments

Have you ever made comments when committing in to source control that you wish you could take back? Perhaps in a rage, you entered "Jimmy's code was a pile of fermenting humus that didn't work. So I fixed it!" Now you realize that Jimmy will see it, your boss is going to see it, and you want to change the comments to something that has a bit more tact. Or maybe your reason is far less malicious: you identified a major bug that you just committed, and you would like to update the comment log to say "Don't use this revision. It has a major bug."

In Subversion, the comments can be updated long after the original commit. Log messages are just a property on the repository revision.

svn propset --revision <REVISION> --revprop <MESSAGE> <URL>
  • <REVISION> : The revision number of the target log message.
  • <MESSAGE> : The value of the new log message, wrapped in quotes if necessary.
  • <URL> : The base URL of your repository. Since this applies to a revision property, rather than a file property, only the base URL of the repository is needed, rather than a URL directly to a file.

Now your malicious revision comment can be overwritten by:

svn propset --revision 123 --revprop "Fixed issue #17" http://svnserver/myrepos/

But next time, do try to be nice to Jimmy.

Visual Studio Macro: Modify Text Editor Font Size

Increasing or decreasing the font size of your code in Visual Studio's text editor is almost required whenever VS is fired up on a projector. Anyone who has had to demo code, or give a talk at a user group, or present new technologies to their team has experienced the pain of increasing the font size through the Tools -> Options menu, followed by an inquiry to the crowd: "How's that? Is this font size readable by everyone?" Often times the selected size is not quite the right solution, and the process is repeated. Life as a presenter would be easier if only you could modify the font size through a simple keyboard command, similar to how browsers enable you adjust the font through the ctrl+ and ctrl- commands.

Macros.Samples.Accessibility.DecreaseTextEditorFontSize
Decreases the text editor font size in Visual Studio

Macros.Samples.Accessibility.IncreaseTextEditorFontSize
Increases the text editor font size in Visual Studio

Fortunately, this is easy with the help of Visual Studio's Sample Macros. To help show you the ropes of writing custom macros, VS ships with a collection samples, and two of these samples respectively increase and decrease the font size of the text editor. Right out of the box, Visual Studio comes with the ability to modify the font size for your code; all that remains is mapping these macros to the keyboard.

Visual Studio Options Window, Assigning Macro to Keyboard CommandMapping to the Keyboard

Anchoring these macros to specific keyboard commands is a simple process.

  1. From Visual Studio, access the Tools -> Options menu.
  2. In the Options window, navigate to Environment -> Keyboard.
  3. Using the "Show commands containing" input, enter in IncreaseText or DecreaseText. The list of available commands will automatically filter as you type, reducing the list to the applicable macro.
  4. Select the macro command, and select the "Press shortcut keys" input, and enter your desired keyboard command. Click the Assign button to set the command. I use "Ctrl, Alt, Shift, =" (plus) and "Ctrl, Alt, Shift, -" for my Increase and Decrease commands, respectively.

This is CodeMash! A look back at CodeMash 2.0.0.9

Last week was CodeMash 2009, a developer's conference in Sandusky, Ohio. The conference, which lasted from Wednesday, January 7th, through Friday, January 9th, was held at the Kalahari Resort, a hotel and indoor water park; this makes the conference unique, as families are able, and encouraged, to join the attending developer for the week, and while the developer is off learning about the Next Big Thing, the significant others, spouses, and children are off enjoying the fun of the water park. As for the conference itself, it is billed as an event where opposing developer communities congregate and mash together. Attendees are encouraged to exit their comfort zone—.Net developers can attend sessions on Java or Ruby; Java developers can attend sessions on Azure or .Net—allowing a seasoned developer to get a new perspective, and allowing communities to cross-pollinate ideas and practices. This was not only my first CodeMash as a speaker, but also as an attendee, and it will not be my last.

Day Zero (The Precompiler)

As Brian Prince points out, we developers love to start lists with zero. It's cool, now that we no longer think digital watches are a pretty neat idea. Day Zero at CodeMash was the Precompiler, an optional extra day of sessions that was new feature of the 2009 event. Unlike the conference's traditional hour-long sessions, the precompiler is split into two half-day sessions, allowing attendees to take a deep dive into a particular topic. For me, it was a dive into Ruby by Joe O'Brien and Jim Weirich and into Windows Azure with David Aiken.

In the Ruby session, @objo and @jimweirich used "koans" to teach Ruby to the attendees. Effectively, these koans were unit tests coded in Ruby against the Ruby language. Each test purposefully failed, and the process of correcting the code of the each test progressively taught more and more about the ruby language. The tests begin with assert false which must be converted to assert true to pass, and proceeds through conditionals, strings, arrays, hashes, blocks, and beyond. Ingenious.

In the Azure session, @thedavidaiken, the evangelist for the Azure platform, gave a once-over and code demo to Azure. After this talk, I'm very excited about playing in the Azure sandbox, and have been brainstorming for a good topic. I have since gotten my invite into the Azure CTP, and should be making sand castles, soon.

Other precompiler sessions were available, including 101-level sessions on iPhone development, Java, and more, and what I have only heard described as a phenomenal talk by Mary Poppendieck on Value Stream Mapping. Also, an all day CodeJam allowed any of the attendees to pop in and code with their friends, colleagues, and other attendees. I wish I could have cloned myself, and attended some of these other sessions.

Day One

After a night that included a few hours of water park slides followed by a few hours catching up with people I hadn't seen since DevLink 2008 or last fall's Ann Arbor Day of .Net, the conference officially kicked off with breakfast and a fantastic keynote by Venkat Subramanian. Then it was off to a day of sessions and Open Spaces, split by a keynote by Mads Torgersen during lunch. I attended Jeff Blankenburg's A Lap Around the Live Framework and Mesh Services talk, and stopped in to Bryan Weber's Functional Concepts for OOP Developers talk for a bit, all in between preparing for my talk. The Open Spaces, where this year's theme was Techniques, Not Tools, are always a part of my day at conferences, especially since these were facilitated by Alan Stevens. Any time he is involved in organizing an event's open spaces, the attendees are in for a treat. We had some great conversation on testing practices and on pragmatic learning (which incidentally spawned another open space on Day Two on mentoring.

During Day One's final block of sessions was my talk, Continuous Integration: It's More Than Just a Toolset. Though this was my first presentation at a conference, it went off great. Having given this talk a few times prior at various area user groups, I was comfortable with the talk and had all of the bugs worked out. I was fortunate enough to have a sizeable crowd and great questions from the audience. I am looking forward to speaking, again.

Day Two

The second day kicked of with another breakfast keynote, this time delivered by Eric Meyer. I spent the entire day involved in open spaces. Alan Barber convened a discussion on Getting in to Speaking. Rick Kierner convened an open space on having and becoming a mentor, a topic that originated from the pragmatic learning discussion from the prior day. I hope that the outlines of these discussions make its way to Heartland Open Spaces, soon.

The day, and the conference, ended with a trip to the open spaces Closing Circle followed by the Closing Giveaway. The Closing Circle, open to anyone who wished to participate, is where we could all look back on the open spaces of the event, and discuss what we liked and provide constructive feedback on how to improve for next year. Alan did another great job with organization; I would have liked the open spaces to be in a more prominent location, to help introduce open spaces to the crowd, and apparently, this is already taken care of for next year. The Closing Giveaway in the conferences Great Hall ended the show for everyone with an hour of prize giveaways, which included two XBox 360s, a Wii, the full Rock Band 2 set, the full Guitar Hero World Tour set, and much more. My number was cursed; I did not win a thing. I'll have to acquire Rock Band 2 through some other means.

Thoughts

This was my first CodeMash. I loved it. It is a very cool event, for if no other reason than it is great to have the conference and the hotel room be in the same building. I enjoyed the opportunity to learn new things that were outside of my day-to-day space, as well as share the wealth by giving a talk to others. I look forward to next year, and I hope that they will again have me as a speaker.

Thank you to all of the CodeMash organizers for a great event.

Technorati Tags:

ActionScript Brush for Google Syntax Highlighter

My earlier post on creating custom brushes in Google Syntax Highlighter (Extending Language Support in Google Syntax Highlighter) contains a rudimentary brush for ActionScript. The original is designed for Stone Soup; it is something to get an AS brush established, but is not meant to be exhaustive. I have revisited the brush and added some meat. The bush should now supply a more thorough coverage of the language. A download is provided below.

ActionScript Brush

dp.sh.Brushes.ActionScript = function() {

  var keywords = 'and arguments asfunction break call case catch clear ' +

    'continue default do else escape eval false finally for getProperty ' +

    'if ifFrameLoaded in instanceof loop NaN new newline not null or ' +

    'prototype return set super switch targetPath tellTarget this throw ' +

    'trace true try typeof undefined unescape var visible void while with';

  var builtin = '_currentframe _droptarget _framesloaded _global _height ' +

    '_level _name _root _rotation _target _totalframes _url _visible ' +

    '_width _x _xmouse _xscale _y _ymouse _yscale Array Boolean Button ' +

    'bytesLoaded bytesTotal Camera Color Date enabled Error focusEnabled ' +

    'Key LoadVars Math Mouse MovieClip nextFrame Number Object Selection ' +

    'Sound Stage String StyleSheet System TextFormat';

  var funcs = 'addProperty attachMovie attachVideo browse cancel ' +

    'clearInterval clone concat createEmptyMovieClip createTextField ' +

    'dispose draw duplicateMovieClip dynamic equals extends function ' +

    'getInstanceAtDepth gotoAndPlay gotoAndStop identity implements ' +

    'import interface isEmpty isFinite isNAN join length loadClip ' +

    'loadMovie loadMovieNum loadVariables loadVariablesNum merge moveTo ' +

    'on onClipEvent onDragOut onDragOver onEnterFrame onKeyDown onKeyUp ' +

    'onKillFocus onMouseDown onMouseMove onMouseUp onPress onRelease ' +

    'onReleaseOutside onRollOut onRollOver onUnload play pop prevFrame ' +

    'private public push registerClass removeMovieClip reverse rotate ' +

    'scale setEmpty setInterval setProperty shift slice sort sortOn ' +

    'splice startDrag static stopAllSounds stopDrag subtract swapDepths ' +

    'toString toString translate union unloadClip unloadMovie ' +

    'unloadMovieNum unshiftclass unwatch valueOf watch';

  var includes = '#include #initClip #endInitClip';



  this.regexList = [

    {regex: dp.sh.RegexLib.SingleLineCComments, css: 'comment' },

    {regex: dp.sh.RegexLib.MultiLineCComments, css: 'comment' },

    {regex: dp.sh.RegexLib.DoubleQuotedString, css: 'string' },

    {regex: dp.sh.RegexLib.SingleQuotedString, css: 'string' },

    {regex: new RegExp(this.GetKeywords(keywords), 'gm'), css: 'keyword' },

    {regex: new RegExp(this.GetKeywords(funcs), 'gm'), css: 'func' },

    {regex: new RegExp(this.GetKeywords(builtin), 'gm'), css: 'builtin' },

    {regex: new RegExp(this.GetKeywords(includes), 'gm'), css: 'preprocessor'}

  ];

  this.CssClass = 'dp-as';

  this.Style = '.dp-as .func { color: #000099; }' +

               '.dp-as .builtin { color: #990000; }';

}



dp.sh.Brushes.ActionScript.prototype = new dp.sh.Highlighter();

dp.sh.Brushes.ActionScript.Aliases = ['actionscript', 'as'];

Usage

Upload the Brush javascript file to your Google Syntax Highlighter Scripts directory, and load the file in unto your HTML with a <SCRIPT> tag with your other brushes.

<script language="javascript"

  src="dp.SyntaxHighlighter/Scripts/shBrushAs.js"></script>

Display syntax-highlighted ActionScript using a traditional Google Syntax Highlighter <PRE> tag, using as or actionscript as the language alias.

<pre name="code" class="as">

  // Some ActionScript Code

</pre>

Brush In Action

/*

Sample ActionScript for Demo

ActionScript Brush for Google Syntax Highlighter

*/

if (dteDate.getMonth() == intCurrMonth && intCurrMonth == intOldMonth

    && intOldYear == intCurrYear) {

  if (dteDate.getDay() == 0 and dteDate.getDate()>1) {

    intYPosition = intYPosition+20;

  }

  duplicateMovieClip ("DayContainer", "DayContainer"+intDate, intDate);

  setProperty ("DayContainer"+intDate, _y, intYPosition);

  setProperty ("DayContainer"+intDate, _x, intXPosition[dteDate.getDay()]);



  } else if (intCurrMonth == 6) {

    if (intDate == 4) {

      clrFColor = new Color("DayContainer"+intDate+".foreground");

      clrFColor.setRGB(0xFF0000);

      clrBColor = new Color("DayContainer"+intDate+".background");

      clrBColor.setRGB(0xFF0000);

    }

  } else if (intCurrMonth == 9) {

    if (intDate == 31) {

      clrFColor = new Color("DayContainer"+intDate+".foreground");

      clrFColor.setRGB(0xFF9922);

      clrBColor = new Color("DayContainer"+intDate+".background");

      clrBColor.setRGB(0xFF9922);

    }

  } else if (intCurrMonth == 10) {

    if (intDate >= 22 && intDate <= 28 && dteDate.getDay() == 4) {

      clrFColor = new Color("DayContainer"+intDate+".foreground");

      clrFColor.setRGB(0xFFCC00);

      clrBColor = new Color("DayContainer"+intDate+".background");

      clrBColor.setRGB(0xFFCC00);

    }

  set ("DayContainer"+intDate+":MyDate", new Date(dteDate.getFullYear(),

    dteDate.getMonth(), dteDate.getDate()));

  setProperty ("DayContainer"+intDate, _visible, true);

  intDate++;

  dteDate.setDate(intDate);

}

Download

Download: shBrushAs.zip
Includes:

  • Compressed shBrushAs.js for production. 
  • Uncompressed shBurshAs.js for debugging.

As always, this code is provided with no warranties or guarantees. Use at your own risk. Your mileage may vary.


          

        
 

Announcing Ann Arbor Nerd Lunch

Brian Genisio has organized a monthly lunch for the local development community around Ann Arbor, Michigan. The event, held on the third Thursday of every month, will be an opportunity for developers to get together, network with colleagues, talk about what is cool or what is in the way in day-to-day development efforts, and have a good time socializing at lunch. A Google Group has been set up for more information, and will serve as the primary method of communication.

The first Ann Arbor Nerd Lunch will be held next week, noon on Thursday, December 18th, at the Mahek Indian Cuisine restaurant in downtown Ann Arbor. The plan is to change the meeting place every month to accommodate different taste buds, but to keep the meeting time consistently on the third Thursday.

Ann Arbor Nerd Lunch - Google Group
Thursday, December 18th, Noon

Mahek Indian Cuisine - Map
212 E. Washington Street
Ann Arbor, Michigan 48104

Please RSVP on the Google Group, so that proper table sizes can be planned.

For every meeting, you are encouraged to bring a friend. For this first meeting, you are challenged with bringing someone who does not normally attend community functions, such as local conferences and user group meetings, yet is interested in getting involved. Help get Ann Arbor Nerd Lunch off the ground. Also, come with some ideas for the group. Should it stay casual? Should "special guests" be brought in to help start conversation? This is an event for the community, and the goal is to make a lunch that is beneficial for everyone. It should be a great time.

I'll see you there.

Technorati Tags: ,
Posted by Jay Harris is Cpt. LoadTest
Filed under:

Extending Language Support in Google SyntaxHighlighter

As I discussed in an earlier post (Blog your code using Google SyntaxHighlighter), Google SyntaxHighlighter is a simple tool that allows bloggers to easily display code in a format that is familiar end users. The tool renders the code in a very consumable fashion that includes colored syntax highlighting, line highlighting, and line numbers. Out of the box it supports most of the common languages of today, and a few from yesterday, but some common languages are unsupported. Perl, ColdFusion, and Flash's ActionScript all are unloved by Google SyntaxHighlighter, as are many others that you may want to post to your blog. For these languages, the solution is a custom brush.

Syntax Highlighting Brushes

For Google SyntaxHighlighter, brushes are JavaScript files that govern the syntax highlighting process, with names following the format of shBrushLanguage.js, such as shBrushXml.js. Brushes contain information about the keywords, functions, and operators of a language, as well as the syntax for comments, strings, and other syntax characteristics. Keyword-level syntax is applied to any specific word in the language, including keywords, functions, and any word operators, such as and, or, and not. Regular expressions apply character-level syntax to code, and identifies items such as character operators, the remainder of an inline comment, or the entire contents of a comment block. Finally, aliases are defined for the brush; these are the language aliases that are used within the class attribute of the Google SyntaxHighlighter <PRE> tag. With this information, the brush applies the syntax highlighting styles according to the CSS defined for each component of the language.

Breaking Down Brushes

Decomposing the SQL Brush

In JavaScript, everything is an object that can be assigned to a variable, whether its a number, string, function, or class. Brushes are each a delegate function. The variable name of the brush must match dp.sh.Brushes.SomeLanguage.

dp.sh.Brushes.Sql = function() {

Next, define the list of keywords for applying syntax highlighting. Each list is not an array, but rather a single-space delimited string of keywords that will be highlighted. Also, multiple keyword lists can exist, such as one list for function names, another for keywords, and perhaps another for types, and unique styling can be applied to each grouping (we'll get to styling a little later).

  var funcs = 'abs avg case cast coalesce convert count current_timestamp current_user ' +

    'day isnull left lower month nullif replace right session_user space substring sum ' +

    'system_user upper user year';



  var keywords = 'absolute action add after alter as asc at authorization begin bigint ' +

    'binary bit by cascade char character check checkpoint close collate column commit ' +

    'committed connect connection constraint contains continue create cube current ' +

    'current_date current_time cursor database date deallocate dec decimal declare ' +

    'default delete desc distinct double drop dynamic else end end-exec escape except ' +

    'exec execute false fetch first float for force foreign forward free from full ' +

    'function global goto grant group grouping having hour ignore index inner ' +

    'insensitive insert instead int integer intersect into is isolation key last level ' +

    'load local max min minute modify move name national nchar next no numeric of off ' +

    'on only open option order out output partial password precision prepare primary ' +

    'prior privileges procedure public read real references relative repeatable ' +

    'restrict return returns revoke rollback rollup rows rule schema scroll second ' +

    'section select sequence serializable set size smallint static statistics table ' +

    'temp temporary then time timestamp to top transaction translation trigger true ' +

    'truncate uncommitted union unique update values varchar varying view when where ' +

    'with work';



  var operators = 'all and any between cross in join like not null or outer some';

Following the keyword definitions is the Regular Expression pattern and Style definition object list. The list, this.regexList, is an array of pattern/style objects: {regex: regexPattern, css: classString}. The regexPattern is a JavaScript RegExp object, and defines the pattern to match in the source code; this pattern can be created using one of three options within Google SyntaxHighlighter.

Predefined Patterns
Within Google SyntaxHighlighter, dp.sh.RegexLib contains five predefined regular expression patterns. MultiLineCComments is used for any language that uses C-style multi-line comment blocks: /* my comment block */. SingleLineCComments is used for any language that uses C-style single line or inline comments: // my comment. SingleLinePerlComments applies for Perl-style single line comments: # my comment. DoubleQuotedString identifies any string wrapped in double-quotes and SingleQuotedString identifies strings wrapped in single-quotes. These options are used in place of creating a new instance of the RegExp object.
Keyword Patterns
Google SyntaxHighlighter has a GetKeywords(string) function which will build a pattern string based on one of the brush's defined keyword strings. However, this is only the pattern string, and not the RegExp object. Pass this value into the RegExp constructor: new RegExp(this.GetKeyword(keywords), 'gmi')
Custom Pattern Definition
Create a new RegExp object using a custom pattern. For example, use new RegExp('--(.*)$', 'gm') to match all Sql comments, such as --my comment.

For these pattern/style objects, the regular expression pattern is followed by the name of the CSS class to apply to any regular expression matches. The style sheet packaged with Google SyntaxHighlighter, SyntaxHighlighter.css, already defines the many CSS classes used by GSH; place the additional styles for your custom brushes within this file, in a new file, in your HTML, or defined them within the brush using JavaScript.

  this.regexList = [

    {regex: new RegExp('--(.*)$', 'gm'), css: 'comment' }, // one line and multiline comments

    {regex: dp.sh.RegexLib.DoubleQuotedString, css: 'string' }, // double quoted strings

    {regex: dp.sh.RegexLib.SingleQuotedString, css: 'string' }, // single quoted strings

    {regex: new RegExp(this.GetKeywords(funcs), 'gmi'), css: 'func' }, // functions

    {regex: new RegExp(this.GetKeywords(operators), 'gmi'), css: 'op' }, // operators and such

    {regex: new RegExp(this.GetKeywords(keywords), 'gmi'), css: 'keyword'} // keyword

  ];

The delegate definition ends with any style specifications. Apply a style sheet to the entire code block using this.CssClass. Also, as mentioned above, the brush can define custom CSS using this.Style as an alternative to placing the CSS in HTML or a CSS file. When finished, close the delegate.

  this.CssClass = 'dp-sql';

  this.Style = '.dp-sql .func { color: #ff1493; }' +

    '.dp-sql .op { color: #808080; }';

}

The final component of a Brush, set outside of your delegate, contains the prototype declaration and any aliases to apply to the Brush. Aliases consist of a string array (a real array this time, not a space-delimited string) of language aliases to use, such as ['c#','c-sharp','csharp']. Alias values must be unique across all defined brushes that you have included into your site.

dp.sh.Brushes.Sql.prototype = new dp.sh.Highlighter();

dp.sh.Brushes.Sql.Aliases = ['sql'];

Making a Custom Brush (for ActionScript)

I like rich media applications, such as those developed in Flash or Silverlight. I was surprised when I found that Google SyntaxHighlighter does not ship with an ActionScript brush, and more surprised when I found out that no one has written one, yet. So, using the methods from above, I created one. This isn't meant to be an exhaustive brush, but more like Stone Soup. It's a start. Please feel free to add to it.

dp.sh.Brushes.ActionScript = function() {



  var keywords = 'and break case catch class continue default do dynamic else extends ' +

    'false finally for if implements import in interface NaN new not null or private ' + 

    'public return static super switch this throw true try undefined var void while with';



  this.regexList = [{ regex: dp.sh.RegexLib.SingleLineCComments, css: 'comment' },

    { regex: dp.sh.RegexLib.MultiLineCComments, css: 'comment' },

    { regex: dp.sh.RegexLib.DoubleQuotedString, css: 'string' },

    { regex: dp.sh.RegexLib.SingleQuotedString, css: 'string' },

    { regex: new RegExp(this.GetKeywords(keywords), 'gm'), css: 'keyword'}];



    this.CssClass = 'dp-as';

}



dp.sh.Brushes.ActionScript.prototype = new dp.sh.Highlighter();

dp.sh.Brushes.ActionScript.Aliases = ['actionscript', 'as'];

Extending Language Support in Google Syntax Highlighter

As I discussed in an earlier post (Blog your code using Google Syntax Highlighter), Google Syntax Highlighter is a simple tool that allows bloggers to easily display code in a format that is familiar end users. The tool renders the code in a very consumable fashion that includes colored syntax highlighting, line highlighting, and line numbers. Out of the box it supports most of the common languages of today, and a few from yesterday, but some common languages are unsupported. Perl, ColdFusion, and Flash's ActionScript all are unloved by Google Syntax Highlighter, as are many others that you may want to post to your blog. For these languages, the solution is a custom brush.

Syntax Highlighting Brushes

For Google Syntax Highlighter, brushes are JavaScript files that govern the syntax highlighting process, with names following the format of shBrushLanguage.js, such as shBrushXml.js. Brushes contain information about the keywords, functions, and operators of a language, as well as the syntax for comments, strings, and other syntax characteristics. Keyword-level syntax is applied to any specific word in the language, including keywords, functions, and any word operators, such as and, or, and not. Regular expressions apply character-level syntax to code, and identifies items such as character operators, the remainder of an inline comment, or the entire contents of a comment block. Finally, aliases are defined for the brush; these are the language aliases that are used within the class attribute of the Google Syntax Highlighter <PRE> tag. With this information, the brush applies the syntax highlighting styles according to the CSS defined for each component of the language.

Breaking Down Brushes

Decomposing the SQL Brush

In JavaScript, everything is an object that can be assigned to a variable, whether its a number, string, function, or class. Brushes are each a delegate function. The variable name of the brush must match dp.sh.Brushes.SomeLanguage.

dp.sh.Brushes.Sql = function() {

Next, define the list of keywords for applying syntax highlighting. Each list is not an array, but rather a single-space delimited string of keywords that will be highlighted. Also, multiple keyword lists can exist, such as one list for function names, another for keywords, and perhaps another for types, and unique styling can be applied to each grouping (we'll get to styling a little later).

  var funcs = 'abs avg case cast coalesce convert count current_timestamp ' +

    'current_user day isnull left lower month nullif replace right ' +

    'session_user space substring sum system_user upper user year';



  var keywords = 'absolute action add after alter as asc at authorization ' +

    'begin bigint binary bit by cascade char character check checkpoint ' +

    'close collate column commit committed connect connection constraint ' +

    'contains continue create cube current current_date current_time ' +

    'cursor database date deallocate dec decimal declare default delete ' +

    'desc distinct double drop dynamic else end end-exec escape except ' +

    'exec execute false fetch first float for force foreign forward free ' +

    'from full function global goto grant group grouping having hour ' +

    'ignore index inner insensitive insert instead int integer intersect ' +

    'into is isolation key last level load local max min minute modify ' +

    'move name national nchar next no numeric of off on only open option ' +

    'order out output partial password precision prepare primary prior ' +

    'privileges procedure public read real references relative repeatable ' +

    'restrict return returns revoke rollback rollup rows rule schema ' +

    'scroll second section select sequence serializable set size smallint ' +

    'static statistics table temp temporary then time timestamp to top ' +

    'transaction translation trigger true truncate uncommitted union ' +

    'unique update values varchar varying view when where with work';



  var operators = 'all and any between cross in join like not null or ' +

    'outer some';

Following the keyword definitions is the Regular Expression pattern and Style definition object list. The list, this.regexList, is an array of pattern/style objects: {regex: regexPattern, css: classString}. The regexPattern is a JavaScript RegExp object, and defines the pattern to match in the source code; this pattern can be created using one of three options within Google Syntax Highlighter.

Predefined Patterns
Within Google Syntax Highlighter, dp.sh.RegexLib contains five predefined regular expression patterns. MultiLineCComments is used for any language that uses C-style multi-line comment blocks: /* my comment block */. SingleLineCComments is used for any language that uses C-style single line or inline comments: // my comment. SingleLinePerlComments applies for Perl-style single line comments: # my comment. DoubleQuotedString identifies any string wrapped in double-quotes and SingleQuotedString identifies strings wrapped in single-quotes. These options are used in place of creating a new instance of the RegExp object.
Keyword Patterns
Google Syntax Highlighter has a GetKeywords(string) function which will build a pattern string based on one of the brush's defined keyword strings. However, this is only the pattern string, and not the RegExp object. Pass this value into the RegExp constructor: new RegExp(this.GetKeyword(keywords), 'gmi')
Custom Pattern Definition
Create a new RegExp object using a custom pattern. For example, use new RegExp('--(.*)$', 'gm') to match all Sql comments, such as --my comment.

For these pattern/style objects, the regular expression pattern is followed by the name of the CSS class to apply to any regular expression matches. The style sheet packaged with Google Syntax Highlighter, SyntaxHighlighter.css, already defines the many CSS classes used by GSH; place the additional styles for your custom brushes within this file, in a new file, in your HTML, or defined them within the brush using JavaScript.

  this.regexList = [

    {regex: new RegExp('--(.*)$', 'gm'), css: 'comment'},

    {regex: dp.sh.RegexLib.DoubleQuotedString, css: 'string'},

    {regex: dp.sh.RegexLib.SingleQuotedString, css: 'string'},

    {regex: new RegExp(this.GetKeywords(funcs), 'gmi'), css: 'func'},

    {regex: new RegExp(this.GetKeywords(operators), 'gmi'), css: 'op'},

    {regex: new RegExp(this.GetKeywords(keywords), 'gmi'), css: 'keyword'}

  ];

The delegate definition ends with any style specifications. Apply a style sheet to the entire code block using this.CssClass. Also, as mentioned above, the brush can define custom CSS using this.Style as an alternative to placing the CSS in HTML or a CSS file. When finished, close the delegate.

  this.CssClass = 'dp-sql';

  this.Style = '.dp-sql .func { color: #ff1493; }' +

    '.dp-sql .op { color: #808080; }'; }

The final component of a Brush, set outside of your delegate, contains the prototype declaration and any aliases to apply to the Brush. Aliases consist of a string array (a real array this time, not a space-delimited string) of language aliases to use, such as ['c#','c-sharp','csharp']. Alias values must be unique across all defined brushes that you have included into your site.

dp.sh.Brushes.Sql.prototype = new dp.sh.Highlighter();

dp.sh.Brushes.Sql.Aliases = ['sql'];

Making a Custom Brush (for ActionScript)

I like rich media applications, such as those developed in Flash or Silverlight. I was surprised when I found that Google Syntax Highlighter does not ship with an ActionScript brush, and more surprised when I found out that no one has written one, yet. So, using the methods from above, I created one. This isn't meant to be an exhaustive brush, but more like Stone Soup. It's a start. Please feel free to add to it.

dp.sh.Brushes.ActionScript = function() {



  var keywords = 'and break case catch class continue default do dynamic else ' +

    'extends false finally for if implements import in interface NaN new not ' +

    'null or private public return static super switch this throw true try ' +

    'undefined var void while with';



  this.regexList = [{regex: dp.sh.RegexLib.SingleLineCComments, css: 'comment'},

    {regex: dp.sh.RegexLib.MultiLineCComments, css: 'comment'},

    {regex: dp.sh.RegexLib.DoubleQuotedString, css: 'string'},

    {regex: dp.sh.RegexLib.SingleQuotedString, css: 'string'},

    {regex: new RegExp(this.GetKeywords(keywords), 'gm'), css: 'keyword'}];



    this.CssClass = 'dp-as';

}



dp.sh.Brushes.ActionScript.prototype = new dp.sh.Highlighter();

dp.sh.Brushes.ActionScript.Aliases = ['actionscript', 'as'];

About Jay Harris

Photo of Jay Harris After seeing yet one more link on the internet attributed to Captain LoadTest, I figure that it is time to put a face to the nickname, plus associate it with any other mindless drivel that might spew out of my head in the next 10 minutes.

I am Jay Harris, the software developer. Not to be confused with Jay Harris the sportscaster on ESPN or Kay-Jay Harris the football player of the New York Giants. I am a senior software consultant for SRT Solutions in Ann Arbor, Michigan, where I specialize in ASP.NET development and automated developer testing. Prior to SRT, at least since moving to Michigan in 2003, my career includes stints at Latitude Consulting Group in Howell, Michigan as a Senior Developer and Performance Specialist, and at Novations Learning Technologies in East Lansing, Michigan as a Presentation Developer and Performance Specialist. Before moving to Michigan, my positions include Lead Quality Analyst, Developer-In-Test, and Presentation Developer at various companies throughout Western New York, and four years as Student at Clarkson University, where I hold a Bachelor of Science in Technical Communications and a minor in Computer Science.

Throughout my career, I have focused on the full user experience. I am not only driven towards providing usable interfaces but I am also a strong advocate of practices and processes that improve quality through code, such as automated testing, continuous integration, and performance analysis. I am also active in the developer community, speaking at area user groups and conferences, serving on the executive board of Greater Lansing Users Group for .Net (GLUG.net), and organizing local study groups to help area developers pursue Microsoft .NET certifications.

Random Trivia

  • I enjoy restoring wooden furniture. I like bringing old, discarded, unloved furniture back to life. It fits well with taking existing code and making it better, taking a poor performing application and making it faster, or even when I was a kid rebuilding Legoland after yet another natural Lego-disaster.
  • I am an endorphin junkie. Combine that with a high tolerance for g-forces, and I have an addition for fast vehicles, extreme roller coasters, and crazy amusement park rides. I hope that I can soon add bungee jumping and sky diving to the list.
  • I am not a Michigan Native; I am originally from Western New York. I was born and raised near Rochester, New York, and I moved from Syracuse, New York to Michigan in 2003 with my wife so that she could attend law school at Michigan State. We like it here, but still consider ourselves tourists, and probably always will.
Posted by Jay Harris is Cpt. LoadTest
Filed under:

URL Rewrite, Part 3: Improving SEO and the 'www' subdomain

Did you know that yourdomain.com and www.yourdomain.com are actually different sites? Are they both serving the same content? If so, it may be negatively impacting your search engine rankings.

Subdomains and the Synonymous 'WWW'

Sub-domains are the prefix to a domain (http://subdomain.yourdomain.com), and are treated by browsers, computers, domain name systems (DNS), search engines, and the general internet as separate, individual web sites. Google's primary web presence, http://www.google.com, is very different than Google Mail, http://mail.google.com, or Google Documents, http://docs.google.com, all because of subdomains. However, what many do not realize is that www is, itself, a subdomain.

A domain, on its own, requires no www prefix; a subdomain-less http://yourdomain.com should be sufficient for serving up a web site. And since www is a subdomain, dropping the prefix could potentially return a different response. There are some sites that will fail to return without the prefix, and some sites that fail with it, but the most common practice is that the www subdomain is synonymous for no subdomain at all.

The Synonymous WWW and SEO

The issue with having two synonymous URLs (http://yourdomain.com and http://www.yourdomain.com) is that search engines may interpret them as separate sites, even if they are serving the same content. The two addresses are technically independent and are potentially serving unique content; to a cautious search engine, even if pages appear to contain the same content, there may be something different under the covers. This means your audience's search results returns two entries for the same content. Some users will happen to click on yourdomain.com while others navigate to www.yourdomain.com, splitting your traffic, your page hits, your search ranking between two sites, unnecessarily.

HTTP Redirects will cure the issue. If you access http://google.com, your browser is instantly redirected to http://www.google.com. This is done through a HTTP 301 permanent redirect. Search Spiders recognize HTTP response codes, and understand the 301 as a "use this other URL instead" command. Many search engines, such as Google, will then update all page entries for the original URI (http://yourdomain.com) and replace it with the 301's destination URL (http://www.yourdomain.com). If there is already an entry for the destination URL, the two entries will be merged together. The search entries for yourdomain.com and www.yourdomain.com will now share traffic, share page hits, and share search ranking. Instead of having two entries on the second and third pages of search results, combining these entries may be just enough to place you on the first page of results.

In addition to combining search entries for subdomains, you can also combine root-level domains through HTTP 301. On this site, in addition to adding the www prefix if no subdomain is specified, captainloadtest.com will HTTP 301 redirect to www.cptloadtest.com.

Combining the Synonyms

We need a way to implement an HTTP 301 redirect at the domain level for all requests to a site; however, often we are using applications that may not grant us access to the source, or we don't have the access into IIS through our host to set up redirects for ourselves. URL Rewrite, Part 2 covers a great drop-in redirect module by Fritz Onion that uses a stand-alone assembly with a few additions in web.config to HTTP 301 redirect paths in your domain (it also supports HTTP 302 redirects). This module is perfect for converting a WordPress blog post URL, such as cptloadtest.com/?p=56, to a DasBlog blog post URL like cptloadtest.com/2006/05/31/VSNetMacroCollapseAll.aspx. However, to redirect domains and subdomains, the module must go a step further and redirect based on matches against the entire URL, such as directing http:// to https:// or captainloadtest.com to cptloadtest.com, which it does not support. It's time for some modifications.

private void OnBeginRequest(object src, EventArgs e) {

  HttpApplication app = src as HttpApplication;

  string reqUrl = app.Request.Url.AbsoluteUri;

  redirections redirs = (redirections) ConfigurationManager.GetSection("redirections");



  foreach (Add a in redirs.Adds) {

    Regex regex = new Regex(a.targetUrl, RegexOptions.IgnoreCase);

    if (regex.IsMatch(reqUrl)) {

      string targetUrl = regex.Replace(reqUrl, a.destinationUrl, 1);



      if (a.permanent) {

        app.Response.StatusCode = 301; // make a permanent redirect

        app.Response.AddHeader("Location", targetUrl);

        app.Response.End();

      }

      else

        app.Response.Redirect(targetUrl);



      break;

    }    

  }

}

By converting app.Request.RawURL to app.Request.AbsoluteUri, the regular expression will now match against the entire URL, rather than just the requested path. There is one downside to this change: the value is the actual path processed, not necessarily what was in the originally requested URL. To this effect, the value of AbsoluteUri for requesting http://www.cptloadtest.com?p=56 is actually http://www.cptloadtest.com/default.aspx?p=56; by requesting the root directory, the default page is being processed, not the directory itself, so default.aspx is added to the URL. Keep this in mind when setting up your redirection rules. Also, the original code converted the URL to lower case; with my modifications, I chose to maintain the case of the URL, since sometimes case matters, and instead ignore case in the regular expression match using RegexOptions.IgnoreCase. Finally, I made some other minor enhancements, like using the ConfigurationManager, since ConfigurationSettings is now obsolete, and reusing the matching Regex instance for replacements.

Download: RedirectModule.zip

Includes:

  • Source code for the drop-in Redirect Module
  • Sample web.config that uses the module
  • Compiled version of redirectmodule.dll

The code is based on the original Redirect Module by Fritz Onion and the Xml Serializer Section Handler by Craig Andera. As always, this code is provided with no warranties or guarantees. Use at your own risk. Your mileage may vary. Thanks to Fritz Onion for the original work, and allowing me extend his code further.

The usage is the same as Fritz Onion's original module. Drop the assembly into your site's bin, and place a few lines into the web.config. The example below contains the rules as they would apply to this site, 301 redirecting http://www.captainloadtest.com to http://www.cptloadtest.com, and adding the www subdomain to any domain requests that have no subdomain.

<?xml version="1.0"?>

<configuration>

  <configSections>

    <section name="redirections"

      type="Pluralsight.Website.XmlSerializerSectionHandler, redirectmodule" />

  </configSections>

  <!-- Redirect Rules -->

  <redirections type="Pluralsight.Website.redirections, redirectmodule">

    <!-- Domain Redirects //-->

    <add targetUrl="captainloadtest\.com/Default\.aspx"

      destinationUrl="cptloadtest.com/" permanent="true" />

    <add targetUrl="captainloadtest\.com"

      destinationUrl="cptloadtest.com" permanent="true" />



    <!-- Add 'WWW' to the domain request //-->

    <add targetUrl="://cptloadtest\.com/Default\.aspx"

      destinationUrl="://www.$1.com/" permanent="true" />

    <add targetUrl="://cptloadtest\.com"

      destinationUrl="://www.$1.com" permanent="true" />



    <!-- ...More Redirects -->

  </redirections>

  <system.web>

    <httpModules>

      <add name="RedirectModule" type="Pluralsight.Website.RedirectModule, redirectmodule" />

    </httpModules>

  </system.web>

</configuration>

The component is easy to use, and can redirect your site traffic to any URL you choose. Neither code changes to the application nor configuration changes to IIS are needed. By using this module to combine synonymous versions of your URLs, such as alternate domains or subdomains, you will improve your page ranking through combining duplicate search result entries. One more step towards your own search engine optimization goals.

URL Rewrite

Blog your code using Google SyntaxHighlighter

Google SyntaxHighlighter is a simple tool that allows bloggers to easily display code in a format that is familiar end users. The tool renders the code in a very consumable fashion that includes colored syntax highlighting, line highlighting, and line numbers.

/*

This is an example of how Google

SyntaxHighlighter can highlight and display syntax

to you, the end user

*/

public void HelloWorld()

{

  // I have some comments

  Console.WriteLine("Hello, World!");

}

It is purely a client-side tool, as all of the processing is done strictly within the browser through JavaScript. There is no server-side processing. Since it is all JavaScript, you don't need special Copy/Paste plugins and macros installed to your favorite IDE or your blog authoring tool. (I am leery of random plugins and installing them into the software that I use to feed my family.) To including code in your blog post, copy your code from Visual Studio, Notepad, Flash, Firebug, or any tool that displays text, and paste it in to your post. As of v1.5.1, Google SyntaxHighlighter supports C, C++, C#, CSS, Delphi, HTML, Java, JavaScript, PHP, Pascal, Python, Ruby, SQL, VB, VB.NET, XML, XSLT, and all of this is just what comes out of the box.

Setting Up SyntaxHighlighter

To get SyntaxHighlighter running on your blog, download the latest version of the RAR archive and extract the code. The archive contains a parent folder, dp.SyntaxHighlighter, with three child folders:

dp.SyntaxHighlighter

  \Scripts         //Production-ready (Compressed) scripts

  \Styles          //CSS

  \Uncompressed    //Human-readable (Uncompressed/Debug) scripts

Once the archive is extracted, upload dp.SyntaxHighlighter to your blog. Feel free to rename the folder if you like, though I did not. It is not necessary to upload the Uncompressed folder and its files; they are best used for debugging or for viewing the code, as the files in the Scripts folder have been compressed to reduce bandwidth by having most of their whitespace removed.

After you have uploaded the files, you will need to add script and style references to your site's HTML. This is code is not for your posts, but rather for your blog template. In DasBlog, I place this code in the <HEAD> block of my homeTemplate.blogtemplate file. Remember to change the file paths to match the path to where you uploaded the code.

<link type="text/css" rel="stylesheet"

  href="dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css"></link>

<script language="javascript" src="dp.SyntaxHighlighter/Scripts/shCore.js"></script>

<script language="javascript" src="dp.SyntaxHighlighter/Scripts/shBrushCSharp.js"></script>

<script language="javascript" src="dp.SyntaxHighlighter/Scripts/shBrushXml.js"></script>

<script language="javascript">

window.onload = function () {

  dp.SyntaxHighlighter.ClipboardSwf = 'dp.SyntaxHighlighter/Scripts/clipboard.swf';

  dp.SyntaxHighlighter.HighlightAll('code');

}

</script>

To make the tool most efficient, including minimizing the code download by the client browser, highlighting is only enabled for the languages that you specify. The highlighting rules for each language is available through a file referred to as a Brush. The code sample above enables only C# and XML/HTML by including the core file, shCore.js, the C# brush, shBrushCSharp.js and the XML/HTML brush, shBrushXml.js. A unique brush file is available for each of the supported languages, and only the core file is required. These brushes are located in your Scripts directory (the human-readable version is in the Uncompressed folder). Include only the brushes that you like; if you forgot a language brush, the code will still display on your page, but as unformatted text.

<!-- Unformatted HTML Code / No Brush -->

<p id="greeting">Hi, mom & dad!</p>
<!-- Formatted HTML Code -->

<p id="greeting">Hi, mom & dad!</p>

Making SyntaxHighlighter Go

Now that the application is deployed to the site, how does it get applied to a post? Paste the code into the HTML view of your post, inside of a <PRE> tag. Create a name attribute on your tag with a value of code, and a class attribute set to the language and options you are using.

<pre name="code" class="c-sharp">

  public void HelloWorld()

  {

    Console.WriteLine("Hello, World!");

  }

</pre>

One catch is the code must be first made HTML-safe. All angle-brackets, <tag>, must be converted to their HTML equivalent, &lt;tag&gt;, as well as ampersands, & to &amp;. I also find it helpful if your code-indentation uses two-spaces, rather than tabs.

<!-- Pre-converted code -->

<p>Hi, mom & dad!</p>
<!-- Converted code -->

<pre name="code" class="html">

  &lt;p&gt;Hi, mom &amp; dad!&lt;/p&gt;

</pre>

The class attribute is made up of both language and option aliases. These aliases consist of one language followed by your desired options, all in a colon delimited list.

class="language[:option[:option[:option]]]"

The value of language is any of SyntaxHighlighter's defined language aliases, such as c#, csharp, or c-sharp for C#, or rb, ruby, rails, or ror for Ruby. See: full list of available languages.

Options allow for such things as turning off the plain text / copy / about controls (nocontrols), turning off the line number gutter (nogutter), or specifying the number of the first line (firstline[n]). A JavaScript code block with no controls header, and starting the line numbering at 34 would have a class attribute value of class="js:nocontrols:linenumber[34]". See: full list of available options.

Extending SyntaxHighlighter

Because Google SyntaxHighlighter is entirely in JavaScript, you have access to all of the code. Edit it however you like to suit your needs. Additionally, brushes are very easy to create, and include little more than a list of a highlighted language's keywords in a string and an array of language aliases. Creating a brush for ActionScript or QBasic would not take much time. Language brushes exist in the wild for Perl, DOS Batch, and ColdFusion.

In a future post I plan on discussing Brush Creation in depth through creating a brush for ActionScript.

Comparing SyntaxHighlighter to Others

I am a fan of this tool, though that should be obvious considering it is what I use on this blog. I like how readable the code is, how extendable it is, and how easy it is to use. I don't like its compatibility--or lack thereof--with RSS; since all of the work is done in JavaScript, and RSS doesn't do JavaScript, there is no syntax highlighting, numbers, or options within a feed, though the code formatting is still maintained. Other tools, like the CopySourceAsHtml plugin for Visual Studio or Insert Code Snippet for Windows Live Writer convert your code into formatted HTML, where all of the syntax highlighting is applied through HTML attributes and embedded CSS. Their methods are much easier than SyntaxHighlighter, since there are no stylesheets or JavaScript files to include in your HTML, and you don't have to worry about making your code HTML-safe. Also, their method works in RSS feeds. However, there isn't the same level of control. Through SyntaxHighlighter's extendibility, I can theme my code views, such as if I wanted them to look like my personal Visual Studio theme. Through SyntaxHighlighter, I can also make changes at a later time, and those changes will immediately reflected in all past posts, whereas making modifications to the HTML/embedded CSS pattern is much more difficult.

Final Thoughts

I like CopySourceAsHtml in Visual Studio. I used it for years on this blog. But I code in more languages than VB.Net or C#, and the plugin isn't available within the Flash or LoadRunner IDE. I was also frustrated with pasting my code in, only to find that it was too wide for my blog theme's margins, and would have to go back to Visual Studio, change my line endings, and repeat the process. I'm sticking with Google SyntaxHighlighter. It works for all of my languages (as soon as I finish writing my ActionScript brush), and when my line endings are too long, I simply change my HTML. And in my HTML, my code still looks like code, rather than a mess of embedded style. I have to sacrifice RSS formatting, but as a presentation developer that is very particular about his HTML, I am glad for the customization and control.

More Posts Next page »