Archive

Author Archive

Removing empty XML elements in Scala

March 21, 2011 1 comment
import xml.transform.{RuleTransformer, RewriteRule}
import xml.{NodeSeq, Node, Elem}
import xml.Utility.trim

object RemoveEmptyElementsSpike {
  val x1 = <xml><empty/><nonEmpty>data</nonEmpty></xml>
  val x2 = <xml><nonEmpty name="legend"></nonEmpty><empty /></xml>
  val x3 = <xml><Empty><empty/></Empty><nonEmpty>data</nonEmpty></xml>
  val x4 = <xml><empty>
           </empty><nonEmpty>data</nonEmpty></xml>
  val x5 = <xml><empty c={val s:String=null;s}/><nonEmpty name="f"/></xml>

  class RemoveEmptyTagsRule extends RewriteRule {
      override def transform(n: Node) = n match {
          case e @ Elem(prefix, label, attributes, scope, child @ _*) if
              (isEmptyElement(e)) => NodeSeq.Empty
          case other => other
      }
  }

  val myRule = new RuleTransformer(new RemoveEmptyTagsRule)

  private def isEmptyElement(n: Node): Boolean = n match {
      case e @ Elem(prefix, label, attributes, scope, child @ _*) if
          (e.text.isEmpty &&
            (e.attributes.isEmpty || e.attributes.forall(_.value == null))
           && e.child.isEmpty) => true
      case other => false
  }

  def main(args: Array[String]) = {
      println(myRule.transform(trim(x1)))
      println(myRule.transform(trim(x2)))
      println(myRule.transform(trim(x3)))
      println(myRule.transform(trim(x4)))
      println(myRule.transform(trim(x5)))
  }
}

/* Output
<xml><nonEmpty>data</nonEmpty></xml>
<xml><nonEmpty name="legend"></nonEmpty></xml>
<xml><nonEmpty>data</nonEmpty></xml>
<xml><nonEmpty>data</nonEmpty></xml>
<xml><nonEmpty name="f"></nonEmpty></xml>
*/

The Agile Game

December 3, 2009 Comments off

Dr. Stuart Brown, founder of the National Institute of Play, believes that the act of play is essential to human development and intelligence. After watching one of his TED talks, Play is more than fun, I was inspired to look into games an agile team can play during a regular sprint. After all, it seems pretty straight forward that human development and intelligence are valuable aspects of a software developer’s career. So I hit up Google for what it could tell me about agile games, and found a bunch of balloon toting, crazy string wielding fun games I could play with my development team. I envisioned my team’s reaction to the introduction of these wild games:

1. Get a bunch of awkward looks.
2. Make a fool of myself to help lead the way
3. Get a few giggles playing the game
4. Try to come up with a different crazy game the following sprint

To me this seemed like a lot of effort for a little flash-in-the-pan fun. I decided I wanted to focus more on games we could play that would infuse themselves into our work stream — Heck, let’s just make our work a game! First let’s discuss what makes a game fun. Games are scenarios where you have a goal to reach while operating within established rules, boundaries and limitations. What makes the game fun is having the freedom to choose different paths toward the goal, being able to use your skills to achieve smaller goals along the way, and to reap the rewards for achieving the goal.

We already have plenty of rules, boundaries and limitations in our workplaces, but let’s talk more specifically to agile software development. I am talking about story breakdown, story estimating, spiking, definition of done for a story, coding standards, pair programming, TDD, stakeholder satisfaction, etc. Once the rulebook is well understood by your team you must give them time to play the game. YOUR ATTENTION PLEASE: the players need uninterrupted blocks of time where they get to play by the rules and innovate a solution. Don’t be afraid, these blocks are measured in hours, not days. Do what you need to do to provide the players with at least 75% of their day as uninterrupted game time (the more the better). If you need meetings with them make sure you consider the following:

1. Do you NEED the meeting?
2. Does everyone need to attend?
3. Can the meeting occur at the edge of a break (start/end of day, right before/after lunch)?

As a Team Lead your job is part referee and part coach. Encourage healthy demonstrations of play and discourage improper play. Help remove problems which affect their ability to play, and celebrate their victories while helping them learn from their defeats.

And finally, a word to the wise – break down your stories into small enough pieces that they can be achieved in no more than 2 work days. Having those frequent moments of accomplishment makes every game more enjoyable.

Logan Peters

What happened to building race cars?

October 5, 2009 Comments off

When my older brother was a young man his fantasy was to be a part of a great team building cutting edge race cars. His passion led him to spend countless hours on his own figuring out how an internal combustion engine works, how well-tuned suspension helps keep power to the ground, and why one transmission was better than another. He got his foot in the door at the local garage and began his career as a mechanic. Today he is a very successful, respected and knowledgeable mechanic at a different local garage. I am very proud of him and the skills he has acquired over the years. But what happened to building race cars?

At his garage my brother had all the tools he needed plus skilled co-workers.  What stopped him from building his race car?  Whenever my brother wanted to work on something new, innovative, and generally cool he would have to wait until after work hours or the weekend.  Young and energetic he would complete his work day and dive into his own pursuits.  Sometimes he was even able to get co-workers to stay with him and try something he could not do alone.  This lasted for a while but as time went on he could not afford to invest the hours his creative mind was asking of him.  At the end of the day he would be exhausted and ill-suited to pour creative energy into his projects.

In the agile software development environment I currently work in I am surrounded by seasoned professionals, inexperienced raw talent, and everything in-between.  I am proud to be a part of a company that values professional development time as discussed in Hemant Naidu‘s post, A Vivid Imagination Isn’t Just for Kids.  In doing this we acknowledge how important creativity and innovation is to the growth and success of our company.

In an effort to provide momentum to the professional development time the development leads have asked our developers to get together with no manager participation.  They have been tasked with using their professional development time to work together on the major hurdles affecting development across all teams.  It is our hope that leaders will rise, tribes will form, and developers will learn to work together on their own initiatives.  As a developer, expect from us the creative freedom to try, and from yourself the courage to fail.

By Logan Peters

Vim commands in Firefox

June 5, 2009 Comments off

I have always been secretly frustrated switching between keyboard and mouse trying to navigate the web.  I say secretly because I have always accepted the awkwardness of having to use multiple input devices and never openly questioned the deficiencies of such a work flow:  use keyboard to perform search, switch to mouse to click on resulting links, switch to keyboard to enter form data, switch to mouse to follow new links… does this scenario sound familiar?  If you have ever tried to use only the keyboard to perform this work flow you would have quickly become agitated using the TAB key to jump through the maze of focal points on a web page.

About two weeks ago I was introduced to a Firefox add-on, Vimperator, from Vimperator labs.  “Vimperator is a free browser add-on for Firefox, which makes it look and behave like the Vim text editor. It has similar key bindings and you could call it a modal web browser, as key bindings differ according to which mode you are in.” – http://vimperator.org/trac/wiki/Vimperator

Being somewhat familiar with Vim from using Linux I was curious how a Vim command overlay would work for browsing the web.  I admit it was a bit intimidating at first when the Firefox toolbar and address bar disappeared, but after I started using the built-in help system, I quickly became amazed at how intelligent the integration was.  A favorite command so far is the way Vimperator handles links: use the ‘f’ key to tell Vimperator to enumerate the links visible on your screen, then use either the number to navigate to a link or start typing the text of the link and as soon as Vimperator identifies a unique link on a page you will be directed there, awesome.  Notice the yellow highlighted areas and the red/white numbered boxes in the screenshot below:

Vimperator QuickLinks

I was tempted to write this blog detailing the basics of how to use Vimperator but after a few google searches I realized there are many good blogs on this subject already.  One in particular stood out of the crowd and I would encourage you to take a look:  http://www.thegeekstuff.com/2009/05/firefox-add-on-vimperator-make-firefox-behave-like-vim/

The most important things I should mention before you start on this adventure are:

1) use the help system! (accessed by typing ‘:help’ without the quotes in the Vimperator command line).

2) use autocomplete to help you find new commands (accessed by typing ‘:set wildoptions=auto’ without the quotes in the Vimperator command line).

3) there are situations which don’t work well with Vimperator at this time so don’t throw out your mouse (e.g. flash, filling in a form containing a lot of checkboxes, pages with high use of IFrames).

4) I would love to have a button – obvious to non-Vimperator users – to disable Vimperator.  It is not obvious for the non-initiated to disable Vimperator unless they know it is a Firefox add-on or they know how to execute a Vimperator command ‘:addons’ (without the quotes).

5) Vimperator mixes well with other add-ons:
* Speed dial [http://addons.mozilla.org/en-US/firefox/addon/4810]
* It’s All Text! [http://addons.mozilla.org/en-US/firefox/addon/4125]
* Ubiquity [http://labs.mozilla.com/2008/08/introducing-ubiquity/]

Good luck, be patient as the learning curve is steep, and have fun!

Logan Peters, Marcos Tarruella

Running Fedora 10 using VirtualBox on MacBook Pro

May 19, 2009 1 comment

VirtualBox is a freely available open source x86 virtualization product released under the GNU General Public License (GPL).  I was directed to this product by a colleague of mine while trying to find a way to get a Linux bash shell running on my MacBook Pro for Linux Certification training purposes.  There are a ton of great images available covering GNU/Linux, GNU OpenSolaris, BSD and others.  Here is my experience getting Fedora 10 running in VirtualBox on my MacBook Pro:

Note: instructions provided are for VirtualBox 2.2.2 and OS X

1. Download and Install VirtualBox for OS X
2. Download the Fedora image
3. Uncompress the Fedora 7Z somewhere you want to store it (you may need p7Zip, EZ 7Z or something else to uncompress)
4. Launch VirtualBox
5. Click New
6. Click Next button
7. Enter name ‘Fedora10-x86’ (can be anything you want)
8. Operating System: Linux
9. Version: Fedora
10. Click Next
11. Memory: I recommend 512MB+ (you will get much faster boot time with 1024MB)
12. Click Next
13. Use existing hard disk
14. Click the little folder icon
15. Click Add
16. Browse for the VDI file you extracted in step 3
17. Click Open
18. Click Select
19. Click Next
20. Click Finish
21. Select Fedora10-x86 and click Start
22. Login with the credentials you saw from the linked page in step 2
23. ENJOY!

Logan Peters

Fedora 10 running in VirtualBox on Macbook Pro

Tools of PyCon 2009

April 13, 2009 Comments off

Having attended PyCon 2009 in Chicago I would like to highlight a few tools which were demonstrated and I feel stood out from the crowd.

Crunchy

http://code.google.com/p/crunchy/

It’s safe to assume you have read online tutorials for a programming language and had the following setup: a) a web browser window open displaying the tutorial documentation, b) IDE / Command Prompt open to write and execute code, c) multiple monitors so you can show it all at once (if you’re lucky).  Crunchy takes a different approach and delivers HTML formatted documents with an interactive python shell so that you can try the code snippets as you encounter them.  A demonstration of this tool included the user being able to read the requirements for a function, implement that function to the best of their ability, and finally execute pre-existing unit tests to check if their implementation works!

Reinteract

http://www.reinteract.org/trac/

It can be annoying running a time-consuming python program and after 2 minutes of execution you find there is a problem and have to start over.  This would really start to gnaw at your patience if this happened a few more times.  Wouldn’t it be great to have a Python shell that clearly showed you which line the execution was hanging on, allow you to make a fix, and then only re-execute the code that is necessary to realize your change?  This Python graphical shell implements this, and more, great functionality which I really hope to see adopted elsewhere.

PlayerPiano

http://code.google.com/p/playerpiano/

Chances are this has happened to you or someone you know:

You plan on demoing some code to a group of peers.  You begin to code and upon execution you get an error.  You try to recover but are too nervous and cannot get the %&*$ thing to run.  The demo ends with an awkward bit of silence and a brief apology.

First of all, let’s avoid live code demos.  Second, let’s pretend they’re live demos!  For those of you who don’t know, a Player Piano is a self playing piano running pre-programmed music.   PlayerPiano is a great python tool that runs doctests inside a fake Python shell; effectively it runs your pre-programmed demo while you can focus on speaking and paying attention to your audience.

Please, please, please no more live code demos.

By: Logan Peters