Parse Garmin TCX files

So I was looking at my Vibram FiveFingers Bikila LS shoes and noticed that they started to wear a fair bit on the soles. I then got curious as to how many miles I had put on them. I also have a Garmin Forerunner 305 that I wear on every run, so I figured this should be easy. *brrrrp* Wrong!

The Garmin Training Center software lists the totals for my activities, but includes ALL activities (i.e. biking) in the total. NOT what I need! It also only exports as a TCX file. I looked around quickly, but didn’t find something that would summarize by activity type, so I rolled my own!

Wrote a quick Ruby script to pull out all activities from the exported TCX file (which is just XML) and the pulled that into Excel to create a pivot table using that data, summarizing by the ID column (since it gives me multiple laps per activity). Then I was able to manipulate to my heart’s content!

Turns out I’ve run 75 miles in these shoes. I’m hoping that I’ll end up with something more along the lines of these experiences in the longevity of my shoes. But then, I am a fat 275 lb bastard, so that will put a little extra wear and tear on the shoes… ;]

Neat find/grep trick

So for the longest time I was always bothered by the fact that I couldn’t grep for files of a particular name that were buried several levels deep. For example, if you wanted to do grep -r nifty.java.property *.properties

, then unless you had a *.properties file in your current directory, grep would assume that there are no other matches lower down in the structure, so you’d find nothing. Hmph.

So of course, find comes to the rescue. You can run find . -name *.properties -exec grep nifty.java.property {} \;

and that finds all your matches – with one problem: this doesn’t tell you which file it found the match in, so that’s pretty useless as it stands (in any case, remember to escape the ; with \ if you run this from the shell to prevent your shell from interpreting the ; as a command separator and not passing it to find).

So, there are a couple of solutions to this.

    • find . -name *.properties -exec grep nifty.java.property /dev/null {} \;


    The reason why this works: grep normally only shows the file names in which it matched a string if it has multiple files to process. Since the find command launches one grep per file name matched when it is ended with ; (in this case \;, otherwise the shell would interpret it instead of it being passed to find), grep assumes which file name you just called it with and therefore doesn’t spit out the file name.

    So, adding the /dev/null means another file to be searched (which is always going to return 0 results), therefore grep decides it needs to show the file name, which is really cool, because otherwise find gives you no clue as to which file it executed grep for. You could of course pass -print to find, but that gives you every single file name matched and would be totally useless as you would potentially drown in matches.

    This is probably the most portable option since it does not rely on any special options for grep or find.

      • find . -name *.properties -exec grep nifty.java.property {} +


      For the longest time I totally missed that most (if not all) find versions offer the option of ending the command with +. This has the effect of passing as many paths as will fit as an argument, i.e. we’re back to grep having multiple files to match and it prints the path name again. Neat!

        • find . -name *.properties -exec grep -H nifty.java.property {} \;


        Some versions of grep offer the -H option, which forces grep to act as if it was matching multiple files and it prints out the file name (with full path) once again.

        So there you have it – three methods of getting the results you need. Happy grepping! ;]

        PS: If find barfs on a whole bunch of “permission denied”‘s and spews out a bunch of extra stuff that prevents you from easily seeing the results you’re interested in, remember that you can add a 2> /dev/null

        to redirect stderr to that great bit-bucket in the sky and get rid of all that annoying stuff.

        Samsung Galaxy S II Epic 4G Touch

        Longest product name EVER!? Seriously people, who wants to type all that? Seesh! Marketing… pht!

        Appropriate name for an attorney’s office

        Take back your Win-Space!!!

        So ever since I installed Windows 7, it bugged the hell out of me that I couldn’t use my beloved Win-Space hotkey anymore for my equally-beloved Launchy.

        That is, Until I found this post. Once again, the inimitable AutoHotKey comes charging in on its ugly white horse (the language is a bit of a pain ;] ) to the rescue!

        Simply run a script as follows:

        #space::SendInput !{Space}

        Now put a link in your Start menu (which if you’re like me you spend a bit of time hunting around for in Windows 7 – you can find it under C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu (seriously!? can you make this stuff harder to find please, Microsoft!?) and every time you boot Windows, your Win-Space with the IMHO useless “desktop peek” functionality is overridden to send an Alt-Space hotkey instead, which if you configure Launchy to listen for that, will bring up its sweet goodness, just like it used to! ;]

        Enjoy – I know I will!

        SpongeBob SquarePants in Buckaroo Banzai!?

        So I was watching Buckaroo Banzai again after first having seen it way back when in college in the ’90s and I’m sitting through the opening credits when the following frame catches my attention (grabbed from 2m37s into the movie as it plays on streaming Netflix right now):

        Buckaroo Banzai SpongeBob small frame

        Wait! What was that? That looks like… nah, it can’t be! Or is it? Damn me to hell and back, that does look an awful lot like SpongeBob SquarePants – what’s he doing in “The Adventures of Buckaroo Banzai Across the 8th Dimension”!? Here’s a closer look:

        SpongBob closeup

        Wow! Looks just like him, don’t you think?

        SpongeBob SquarePants current

        What can I say except: wow!

        My desk, post 4am programming orgy

        image

        ’nuff said… ;]

        DVD burner complexities

        So I took apart my DVD burner today – no worries, it was already broken… ;]

        I have to say, I was simply astounded at the complexity of the mechanism. I mean, sure, I knew that it was complex, but the intricacies of the mechanism floored me. I had no idea that such am everyday item possessed such engineering beauty!

        First of all came the tray mechanism with all of its plastic-geared beauty… Well, maybe that bit wasn’t so beautiful after all… ;] However the worm gear drive and stepper motor was pretty cool.

        The direct drive CD spinning motor was pretty cool, too – at least I think it is when you think about how fast it had to spin that little plastic platter.

        The real marvel of the thing comes in the read-write head, however. That is a precision-cast little bit of aluminium (to keep it light) that is machined to some apparently pretty tight tolerances to keep the optical path accurate. This is wrapped in a miniature 3D circuit board whose equal I have yet to see elsewhere, including laptop designs. These were little bits of board connect with filigree ribbon (I hesitate to call them “cables”) that wrapped around all sides of the aluminium substructure.

        Not stopping there, we have a wonderfully complex optical path that includes the laser diode, a detector and the lens that is suspended on the teeniest imaginable copper springs which also service as current-carrying conduits that energize the circuit boards on either side of the lens. TheseĀ  circuits create electric loops which then help to drive it up and down inside the strong magnetic field generated by the two tiny rare-earth magnets on either side.

        All in all a complete engineering marvel that I picked up for a measly $40.

        I think I’m beginning to understand why these things cost over $1,000 at inception… ;]

        Yeah, the C64 is coming back! ;]

        This is kinda cool. It’s a new C64 (this time a 64-bit full Wintel computer) in the same form factor as the old C64. Not sure how practical it’ll be, especially with the keyboard being kind of thick, but it makes me go all nostalgic inside.

        Whoa!

        Wow – this is like cool beyond words! I kinda want a copy of Mathematica 7 now… ;] (click the image to read the blog post explaining the neat image processing capabilities of Mathematica 7).

        OK, yeah, I’m a huge nerd – what’s your point? ;]

        Bad Behavior has blocked 6 access attempts in the last 7 days.

        Performance Optimization WordPress Plugins by W3 EDGE