California Flowers
Sunnyvale, CA, April 2010Off Montana Interstate 90: Returning
Off I90 returning from Anaconda, MT, November 2009Glacier National Park: Peaks
Glacier National Park, Montana, November 2009Glacier National Park: Lake
Glacier National Park, Montana, November 2009Off Montana Interstate 90
Off I90 near Missoula, MT, November 20092009 Grandfather Mountain Marathon
I last ran Grandfather Mountain Marathon in 2007 as a training run, and figured it would again be good for hill training. This time DJ joined PM and me, and a great time was had by all.
In 2007 I went out conservatively for the first ten miles, then ran a hard effort to finish up with 3:32. This time I stuck with a more even effort over the entire course, finishing in 3:13 and 13th overall. (However, still only 7th in the 30-39 age group).
Lots of recap and photos behind the link
Miles For Marines trail 15K
Tino, Hochberg, Janie and I drove down to SC last Friday for the first annual Miles For Marines 15K trail run. Intended as a fundraiser for injured U.S. Marines, the run is not formally a race, with no race numbers or formal timing. The course was through Westminster Park, private land owned by a Presbyterian Church, much of it on well-groomed trails and even a few miles of freshly mowed field grass.
I wasn’t exactly feeling up for a quick trail race, so I stayed well behind a lead pack of about 5 (which included Hochberg), and kept them in sight for about two miles. I found the paths reasonably marked, but apparently the lead pack did not, and took a wrong turn sometime around mile 4. Turns out I unknowingly led the race until about mile 7. (I thought it was strange that I was knocking down so many cobwebs!) One guy paced along with me for most of the race, and then left when another guy overtook us with a lot more enthusiasm than I had. So, I think I was third, and was happy with my pace, considering the workout my ankles and other underutilized trail muscles got. Hochberg ended up running too many extra miles to be happy, and Tino and Janie seemed uncomfortable with the terrain. I liken the terrain to Anne Springs Close Greenway, though the mowed sections were often slanted and tricky on tired ankles.
I give the volunteers a big thumbs-up; the event was very well-done to not be a formal race. Plus, it was for a very good cause. Next year I would encourage them to organize with a timing company (this course has the makings of a great XC race), but I will likely return regardless. Friendly people, great cause, good fun.
Myers Park Summer Track, final week
Last night was the final night of CTTC Myers Park Summer Track Series, featuring championship races for the top qualifiers from the month, and a 5000 meter race instead of the 2 mile. This was only my second visit, but I’ll definitely be at more of them next year.
I did reasonably well with a 5:24 mile and an 18:52 5K, slight improvements over my previous week efforts. I haven’t done speed work on a track since before I got hurt last year, so I have a lot to learn about pacing on a track. My current intention is to be able to break a 5 minute mile and to run the 5K comfortably in the 17s this time next year, so I have plenty of work cut out for me.
Very nice to see plenty of Crazy Leggers show up. Congrats to Dan “Duracell” Hochberg, who placed third in the master’s championship mile with a smoking 5:16. Very nice seeing Mike, Tino, and the entire Koos family all running events, and also having Julia and the Stewarts there to cheer us on.
Myers Park Summer Track
I’m late to the party, but Summer Track Series is every Tuesday evening in June at Charlotte’s Myers Park High School. Lots of fun, tons of events for both kids and adults, 50m all the way up to 2 miles.
I haven’t run on a track since late last summer, and was happy to run a poorly-paced 5:26 mile at the 6/23 event. (Honestly, I was a little surprised to run under 5:40). Looking forward to sane pacing and getting closer to 5:20 next week.
I was spent after the mile, but I ran the two-miler for kicks. Total dead legs, but ran a negative split, with first mile at 6 flat.
Funny note: The runner I was trying to hang with for most of the two-miler was a tiny TrySports girl apparently named “Mo”, so every lap there were lots of “Go Mo” calls from their team, followed immediately by the occasional “Go Bo”. I would have been laughing if I wasn’t desperately trying to keep from passing out. And, yeah, she kicked my ass.
Great to see lots of familiar faces out, and to have met some friendly new ones. See you next week!
China Grove Main Street Challenge 5K
On the reliable recommendations of a few past participants, I made the trek up to China Grove last Friday for the Main Street Challenge 5K. Plenty of local support (around 400 runners), and the late 9PM start time is novel. I convinced a couple of Hochbergs to join me, and the afternoon drive up I85 in their convertible was a nice start to the evening.
The course is an out-and-back burner from the small China Grove downtown. It starts on a long, gradual downhill for about half a mile, and there is a long, gradual uphill for the half mile at the turnaround. It was nice to warm-up jog the course along with some friendly folks before the sun dropped, though the flying bugs along the graveyard road were not an ideal pre-race snack (also didn’t appreciate the one that got stuck in my eye).
The course is fast, and I was hoping to stay well under 19; unfortunately, my legs didn’t have any speed in them come race time. I struggled the entire race and salvaged a 19:07. Friday night runs are awesome fun, but my body just can’t seem to get into gear for them. I shouldn’t complain much, as I was happy the time was good enough for third-place age group award.
Post-race snacks were quite good (I enjoyed a huge chunk of watermelon, a cookie, and a free energy drink, and people tell me the chocolate dip-and-sprinkle Krispy Kreme stand was a winner), and the tech tee event shirt will definitely fit nicely into my post-run shirt stack. The after dark, small town atmosphere was very friendly, and regardless of my time I’m already looking forward to the race next year.
Shout-outs to the friendly people I warmed up with: Dan was right behind me and good for a third in his age; Stan, Jinnie, and Bill from TrySports went home with hardware, as did Bobby. I also ran into Théoden, who set a nice PR and has a great account of the race on his blog. I suspect his daughter will be passing all of us in no time!
Newton Gravity shoe review
Quick summary: An efficient, neutral-gaited runner’s dream trainer. The upper is perfect (very breathable; you can see toes through the mesh), and the midfoot cushioning suits me perfectly. Most comfortable shoe I’ve ever run a marathon in. Cons? Too expensive ($175), but I’ll make sacrifices.
2009 Gravity: I’m a fan of the redFull review and photos behind the link
Pocono Mountains Run for the Red Marathon
It is not accurate to call the Pocono Mountains Run for the Red Marathon an easy marathon. It is a very fast marathon, but the descents are as quad-trashingly brutal as you will encounter. I can usually jog a day or so after a marathon, and I comfortably run a week afterward. After Pocono, I was having difficulty walking almost a week later.
So, what was my opinion of the race? I absolutely loved it.
Such a thing as an accidental personal best?I’ve run a lot of organized marathons recently (five in the past six months), but most have been paced like long runs rather than all-out races. Each has been faster than the previous one; since I’ve been slowly recovering from some nagging injuries, this strategy has been good for me both physically and mentally. I’ve managed to stay focused with my recovery without piling on massive weekly mileage totals, and the events are fun motivation. It works for me, at least.
My splits and more photos behind the link
Mac OS X: 2D Dock in 10.5
I don’t mind the 3D look of the OS X 10.5 dock, but I often prefer the 2D look of the old dock. Plus, I prefer the more-obvious running app indicators from the 2D dock; I find these hard to see in the 3D version. Also, sometimes I just prefer the same look for my dock whether it’s right- or bottom-oriented. Also, hidden apps (⌘H will hide, not minimize, an app’s windows) can be configured to show as transparent icons.
From a terminal:
defaults write com.apple.dock no-glass -boolean YES defaults write com.apple.dock showhidden -boolean YES killall Dock
Credit should be given to macosxhints.com for this.
Moving graphics with trigonometry
Notice: This is intended to involve only very basic concepts.
No matter the scope, most “game” programming these days involves moving pictures around on a computer screen, and performing this task can be very easy with a little basic math (specifically, trigonometry). Small two-dimensional graphics in games are usually called “sprites”, and in this exercise we’ll simply move a sprite.
We will be plotting a trajectory of a sprite across our screen, and to do this we keep track of
- the sprite’s position (a single point containing its X and Y coordinates),
- a velocity,
- and an angle at which to plot the distance the sprite travels.
Our game will draw the sprite to the screen as fast as it can, and we will know how much time has elapsed since the last time we drew the sprite. So, we will be provided the final number we need to plot our new sprite position: elapsed time.
We are calculating a distance vector, which is basically a line from one point to another. If our sprite’s velocity is five pixels per second, and one second elapses, it will travel a distance of five pixels. However, what is the new X,Y position of that point? It depends on the angle!
To calculate the amount along the X and Y axes our sprite has traveled, perform two simple calculations:
distanceX = velocity * elapsedTime * cos(angle); distanceY = velocity * elapsedTime * sin(angle);
Add these values to the previous X,Y position of the sprite and you’ll have the new position of the sprite. The diagram assumes a starting position of (1,1), and shows two distance vectors: The red is with an angle of π/4 radians (or 45º from vertical), while the green is an angle of π/2 radians (or 90º from vertical). Both have the same velocity magnitude.
To add a little simple rebound off the sides of the screen, make sure that the X and Y coordinates of the sprite are not beyond the edges. For a screen 800×600 pixels, where directly up is an angle of 0, simple reverse the angle when the sprite goes off the left or right of the screen, and subtract the angle from PI when it goes off the top or bottom.
if (xPosition > 800) { xPosition = 800; angle = -angle; } if (xPosition < 0) { xPosition = 0; angle = -angle; } if (yPosition > 600) { yPosition = 600; angle = PI - angle; } if (yPosition < 0) { yPosition = 0; angle = PI - angle; }
To slow the sprite down at a certain rate of deceleration, simply subtract from the velocity an amount that is multiplied by the elapsed time:
velocity = velocity - (deceleration * elapsedTime);
This isn't the most accurate of physics demonstrations, but surprisingly advanced games can be built around calculations as simple as these.
Next we'll discuss how to derive a distance from two points, and soon go over some handy linear interpolation.
Get Windows key on an old keyboard
I have a particular love of IBM keyboards, both the clicky Model M (compact) as well as scissor-key ThinkPad keyboards. Neither of these, however, has a Windows key. This key is good for much more than popping up the Start menu, so I’d like to get it back. Also, I never use Caps Lock, and have always preferred having Control in that location. So, I remapped Left Control to the Caps Lock key, and then reassigned Left Control to work as Left Windows. Works like a charm.
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout] "Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,1d,00,3a,00,5b,e0,1d,00,\ 00,00,00,00
Explanation of the code to put into the registry can be found here, or you can just use KeyTweak to reassign.
Back to speed, even if slowly
Some months ago, I tweaked a hip flexor during an impromptu trail race. I didn’t give the injury proper respect, instead drawing out my recovery much longer than it should have taken. Furthermore, adjustments in my stride resulted in development of a very annoying plantar fascia cyst.
Now, as I’m training my way back into shape, I’m experiencing some extreme tendonitis in my right ankle area. Initial icing and mild anti-inflammatories were doing the trick, but it got worse over the weekend. Just as I was ramping up to 50-mile weeks. So depressing!
So what have I learned from the past year? First, I should give injuries proper respect. Part of what makes endurance athletes special is their constructive tolerance of pain. I pride myself in this, but I need to get better in distinguishing constructive and destructive pain tolerance. I need to listen. So, I’m taking at least most of a week off, even though I have a marathon date bearing down on me.
Second, I’ve really let my core conditioning go. I hate lifting weights when it’s not part of a routine, so I must find a new routine that includes core. Skimping on core strength is so common for runners, and has to be one of the most counterproductive things a runner can do.
I’m signed up for Birmingham, Albany, and Boston. The coming weeks will tell when my next attempt at a personal best should happen. It doesn’t have to be soon.
Sync two iTunes libraries
I have two Macs, and I use iTunes on both of them. My music library is managed on my MacBook, but I want access to all of the music on my Mac Pro at home without having to stream it. What’s the easiest way to keep these synchronized? We’re dealing with a Unix, so rsync comes to the rescue:
- Please back up your music, in case you get the hosts swapped or something. Tar it up or something:
tar -zcvf myMusic.tar.gz Music - Make sure one computer is available to the other via SSH by enabling “Remote Login” under System Preferences/Sharing. Grab a terminal and test this:
ssh userid@hostNameOrIPAddress - Also in the terminal, in your home directory, try a test run of rsync. I am transferring files from my laptop to my desktop, from a terminal on the desktop, so the command is:
1 2 3
rsync --archive --verbose --rsh=ssh --progress --log-file=anyNameYouLike.log --dry-run my-macbook.local:Music/iTunes .
- Add additional -v flags to get more verbose output. Run until you feel comfortable. Take off the
--dry-runand sit back. - Lastly, go select “File/Add to Library…” in iTunes and select your Music/iTunes directory. It’ll churn through the files and update its local database.
Update:
Turns out, these days I hardly ever rsync between two Macs; I buy music and rip CDs into my laptop, and I have a Sonos system that accesses tunes via a shared drive attached to my network. I easily mount this drive share to my laptop, so it regularly shows up in /Volumes on my laptop. So, the rsync command line looks like I’m synchronizing two directories local to my laptop:
cd Music/iTunes rsync --archive --verbose --stats "iTunes Music/" "/Volumes/NAS/iTunes Music/"
C# tip: Touching brain with reflection
In the interest of speed, I’ll start with a list of truths I won’t be discussing at length:
- Some day you will need to address a problem in someone else’s libraries without the luxury of patching and recompiling their code.
- Most people know .NET reflection allows you to interact with types you didn’t have access to at compile time. It also allows you to interact with types you don’t have permission to directly address in code (internal classes, private members, etc.).
- .NET Reflector is an essential tool for any C# developer who uses someone else’s API. Which is everybody.
Using reflection to read members and invoke methods is easy:
- Get an instance of System.Type from your object. All objects have a GetType() method.
- Call Type.InvokeMember(), passing in the instance you’re wanting to manipulate as well as the name of the member and access flags.
Real-world
The XNA framework is a delightful graphics and games programming API by Microsoft, which is free (as in beer) but not open-sourced, and is officially unsupported. I play a bit with XNA and recently came across a serious performance killer in XNA 2.0 (which I’ve been assured is fixed in 3.0 final; forum post here and bug report here). Basically, there is a leaky dictionary embedded two internal classes deep that never gets cleaned up, framerate goes poop in a little while if you’re loading and unloading content like crazy.
So, inside the public GraphicsDevice class, there is an instance of an internal DeviceResourceManager, and inside this is the collection of internal ResourceData structs which never gets cleaned up. Once the content that’s being tracked has been disposed, its ResourceData instance can go away, so we’re going to periodically poke into this collection and flush items that are slowing down access to the collection.
In our code, we have easy access to the public GraphicsDevice. So, let’s get access to an instance of the internal DeviceResourceManager inside of it, which is a private instance named “pResourceManager”:
1 2 3 4 5 6 7 8 | Type graphicsDeviceType = this.GraphicsDevice.GetType(); object deviceResourceMgrInst = graphicsDeviceType.InvokeMember("pResourceManager", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance, null, this.GraphicsDevice, // the instance we're manipulating null); |
So, we have access to a private instance of DeviceResourceManager. Now, we go inside it in the same way to get the private collection:
1 2 3 4 5 6 7 8 | Type deviceResourceMgrType = deviceResourceMgrInst.GetType(); System.Collections.IDictionary resourceDataDictionaryInst = deviceResourceMgrType.InvokeMember("pResourceData", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance, null, deviceResourceMgrInst, null) as System.Collections.IDictionary; |
Inside the class there is a sync object for locking as we address the dictionary, but now we know how to get access to that and use it. Then, we can iterate over the objects in our dictionary and remove the ones that are no longer in use.
That’s all the magic. Use this sparingly, as the performance of addressing objects via reflection is horrendous, and it’s always dangerous to subvert API access declarations. However, it might be just the thing that saves you in a pinch.
For the curious, the continued code for the XNA 2.0 leak work-around:
Read the rest of this post »
Davidson Half-marathon
All out at the Davidson half-marathon finish(thanks to Jeri for picture)
Fun race last weekend in Davidson. Most of Crazy Legs showed up and we even got a few age group awards. I was 13th overall with a 1:25:35, good for an age-group second in my first race in the 35-39 group (congrats to fellow CL Paul Gonzalez for getting first about a minute ahead; I was no match for him in on the hills).
C# tip: Dependency Injection on the cheap
I want to keep this post short, so I won’t go into why you should design your code around interfaces, or why injecting dependencies at runtime is such a good idea. Rather, if you’re using .NET and want to quickly use Dependency Injection in your design, but are hesitant to adopt yet another framework (like Spring.NET, which I heartily recommend) for whatever reason, look to System.Activator.
In the way I usually use Activator, you need:
- The path to the assembly containing your implementation. The magic here is that you don’t need this referenced anywhere in the original application (you know, Dependency Injection and all).
- The name of the implementation class you want to load. I’m actually going to traverse all of the types in the injected assembly, which isn’t necessarily the most secure or efficient way to do things, but it is convenient and works well.
Namespaces used:
- System.Activator, to create the instance from a loaded assembly
- System.IO.FileInfo, to conveniently get the full path to the assembly you want to load
- System.Reflection.Assembly, to load your assembly (inject the dependency) into the current app domain
Some code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | IPluggableDependency pluggableInstance = null; // Load the injected assembly with its absolute path FileInfo assemblyFile = new FileInfo("PluggableStuff.dll"); Assembly assembly = Assembly.LoadFile(assemblyFile.FullName); // Find the matching Type you're wanting to instantiate foreach (Type type in assembly.GetTypes()) { if (type.FullName == "PluggableStuff.ClassName") { // Create an instance of your implementation, // cast as an interface pluggableInstance = Activator.CreateInstance(type) as IPluggableDependency; } } |
Now, as I said before, look into using a lean, established, flexible, robust DI framework like Spring. However, if that’s not an option for whatever reason, you can still build your apps around a nice DI pattern. Future migration to Spring will be a snap.
