Posts

Showing posts from February, 2012

Slow going on coding project

I've embraced Ruby for my coding project. Ruby has been great: I really like it's object-oriented nature: it's inherently object-oriented, with that built in to the core of the language, rather than some sort of kludge built onto what is essentially a sequential language. Actually, I'm not sure whether "object" versus "sequential" is correct, here, since Ruby is still highly sequential, it just heavily uses objects. You can still write Ruby code which looks much like Perl code, with notable exceptions. But I don't want to write Ruby code which looks Perlish. I want it to look Rubyish. So therein is what makes for slow going: I write stuff, check it, re-read the on-line documentation to make sure I'm not reinventing any wheels (there are a lot of standard methods in Ruby), make adjustments, run, and track down the inevitable bugs. Slow going, but it's what it takes to build aptitude in a language. So my end-of-Feb deadline for t

SB1464: revised 3-foot passing bill for California

Image
Last year California's Governor Jerry Brown pocketed SB910 , a bill which would have effectively banned drivers from passing cyclists with less than a 3-foot margin. Additionally it would have allowed drivers to cross the center-line when it was safe to do so in order to provide for that mandatory margin, which is a practice well over 99% of the drivers already exercise, anyway. His logic in pocketing the bill seemed inconsistent with the bill itself, as I described , bringing into question whether politics and influence was the actual motive. So another year brings another legislative session, and the California Bike Coalition continues, to its substantial credit, to push the matter. The Give Me Three campaign is not dead, not at all. Instead, SB910 has been replaced with SB1464 . This bill is a direct response to Brown's concern, in his own words: On streets with a speed limit of 35 or 45 mph, slowing to 15 mph to pass a cyclist could cause rear-end collisions. On t

Strava lament

My KOM up Dyer's Pass on the South Island of New Zealand was crushed "yesterday"... I put "yesterday" in quotes because it's hard to figure out precisely what it means that many time zones away, especially with the date line: The horror... the horror... With my light bike, with fresher legs, with a better warm-up, I know I could have gone faster. But a full minute faster? Or rather -- 61 seconds faster? That's the way Strava is. With exponentially increasing user base, records don't usually last long. In the San Francisco Bay area, things are hitting the linear growth regime, but elsewhere, the market penetration is still much smaller. Every week, more people are going to be posting rides, more climbs are going to be ridden hard, and KOMs come and all-to-quickly go. I'd love to go back -- it was a great trip, and I miss the great riding there, even if I am appreciating with renewed freshness the riding here in the San Francisco area

Ruby SmoothData class: now static-free

Last time I posted what I called a "SmoothData" class for Ruby. But even as I was hitting "publish" on Blogger I realized I wasn't being honest. There wasn't much "class" about it: it was a single static method which was similar to what one would write for any sequential procedural language. Indeed, since it was essentially ported from Perl, this shouldn't be a surprise. Initially my attitude was "this function doesn't need to preserve any local state. There doesn't need to be multiple instances of it. It's just an algorithm an nothing more. Why make life too complicated just for a dogmatic adherence to the object oriented cult?" But then I tried to use it and I realized... hmm... maybe I should reconsider. The plan was to, for various measured Strava parameters (altitude, speed, power) to have both measured values and smoothed values. So, for example, for altitude, I'd have an altitude array and a smoothed al

SmoothData : a simple Ruby data smoothing class

Ruby self-teach continues, so I put together a data smoothing class for Ruby. Nothing new here: another in a series of codes I've used for comparing Java to Perl to Ruby. Data smoothing is an important part of anything I do with cycling data. So this is a critical component for me on any sort of project I might want to accomplish. For example, suppose I wanted to write a code to identify and rate climbs in an activity. I know -- Strava already does this, but I've got my own ideas about algorithms. Well, if I were to take altitude data raw, a small glitch yielding a 50% grade between two closely-spaced points might generate a huge spike in the climb rating for just those two points. Instead it would be important to smooth the altitude out, for example with a 50 meter characteristic smoothing distance. 50 meters is a fairly good number on climbs this length and shorter you can generally use momentum to blunt the blow. It also covers up small errors in position and altitu

StravaToCSV : It's Ruby's turn

StravaToCSV has become my "test app" for various programming languages ( Perl , Java , and now Ruby). And for that it works fairly well: I need to process command line arguments, open an HTTP connection to Strava, download JSON data, convert it, then then output it as CSV. So there's a decent amount there. This project went much smoother than my Java implementation. It was fairly quick, taking a bit longer when I wanted to avoid the program imploding when it was fed a bad activity specification. This version takes as its only command line arguments activity numbers (for full activities) or activity-segment pairs, where the activity number is separated from the matched segment by a "#". It will sequentially load each of these, outputting a CSV stream with the header determined by what fields it finds in the first non-empty activity. It adds the activity number as the first column of the CSV stream. At first I expected the JSON library to have some sort

Perl, Java, Ruby

Well, I realized the Pine Flat Road Race was tomorrow (Sunday) not today (Saturday) and so, had I rested today, I probably could have gone. Ah, well. I have a rule that I need to do a hard group ride before I even think about racing, and I haven't yet done so this year, or even towards the end of last year. No, the Friday Noon Ride is not a "hard group ride".... nor is Wednesday. Only Tue and Thu come close to qualifying. So it probably wouldn't have been prudent trying to mix it up at Pine Flat, anyway. But on the positive side, that's 6-7 hours I will not be spending in a car, and more time I won't spend in a smelly motel room, more time to devote to my coding project. On Facebook, it was recommended I look at Ruby. This was an obvious thing to do, since it is what Strava uses for its API example . However, I had gravitated towards Java because with Java I knew I could generate an Android app. All it takes is a bit of Googling to note that Android a

the importance of a good Tuesday

Image
The key for me in having a good week, fitness-wise, is Tuesday. The ideal week begins with a tired Monday. If I feel like riding on Monday, I didn't ride/run/whatever hard enough over the weekend. Tuesday I typically either ride to work, go out to do some intervals, or get a good run in. Actually, it's been awhile since I've actually done any intervals. But I've been fairly reliable on doing one of the other two options. Wednesday can be ride to work, do the Noon Ride up Old La Honda, or go off and do a lunch ride on my own. Some weeks I've run on Wednesday instead. Thursday is then an easy day. Just ride to work and back. But some weeks I've also ridden to work on Thursday. Friday I typically recover if I rode in on Thursday, or else try to get is little ride in. The Apple lunch ride is a good option, or I just ride on my own around Mountain View. Then the weekend: During Low-Key Hillclimb season, I was doing the climb on Saturday, then some sort

Setting Emacs tab stops for Java

I have a problem with Java code: with classes, methods, exception blocks, loops, etc, there's a lot of indentation. Especially when I'm posting code to this blog, with its narrow text column, things quickly flow off the right side of the page. And it's so unnecessary. I don't think 4-column tab stops, which I was using, is needed to produce readable code. The key to solve this is in the following file on my Linux system: ~/.emacs.d/init.el This contains "elisp" commands which are executed upon emacs start-up. Elisp is the Emacs variant of LISP. Honestly, even though I am good with basic MIT Scheme, and also the Elk Scheme I use at work, I find Elisp fairly challenging. But Google is my friend, so I inserted the following: ;Basic unit of spaces for each indentation level. ; c-basic-offset: sets offset for "C-class" languages ; I specifically set it smaller in Java, which tends to have extra indents ; with its class structure. (setq c-basic

mired in Java

So, while this weekend was largely consumed with The MegaMonster Enduro , my quest to become a Java master continues. The Megamonster went okay. It's a long trip down to Paicines: I am in Howard's debt for the ride. And since I have the Low-Key "stuff", it made for a full car. I didn't really help much while there: this year I rode. I did the 100-miler for the first time in 3 years, the preceding two not having the fitness for it. I felt fairly good, but I was slow, taking 5:35 for the course. It's not easy: wind, hills, and this year light rain. I don't think the rain was much of a factor but the wind always is. Anyway, the big deal is doing the results after. I always have a hard time with Megamonster results: for each rider we have three checkpoint times, a start time, and a finish time. I'm prone to making typos, and my scoring scripts only get used once per year, so it's never as smooth as I want. I think things are in fairly good

Republican party and public health care

I'm going to take a small break from cycling to vent a bit... The Republican campaign for president continues... but I have no interest. I gave up on the Republican party long ago. Actually, I'm a Republican wanna-be. I want to vote for a party which is fiscally responsible, which balances its budget, which limits its federal involvement to things which the federal government is uniquely qualified to do like interstate commerce and international relations. I agree states should be granted broad freedom in their ability to decide on local matters, that competition between states is good, and that free market principles should be harnassed whenever externalities don't dominate. I have a strong appreciation of the tragedy of the commons . Further, I am a champion of individual freedom: I agree we should be able to express ourselves freely, travel freely, choose if and how we practice religion freely, and have input over the policies and actions of our government. These

implementing StravaToCsv in Java

In an earlier post I wrote how I put together a "Strava_to_CSV" code using Perl in maybe half an hour. It was pretty easy once I'd installed the Perl JSON libary. But my goal here is Java, not Perl, so I decided to try to write a similar code in Java. Well, I did it, but it took a lot longer than a half an hour (maybe 5 hours total) and it's a lot longer. Of course, I know Perl fairly well, while Java I'm trying to learn, so the time is an unfair comparison. Still, in the Java there's stuff to look after. I won't share the full code here, but will summarize the key points. First, to get the data from Strava, I once again used their "streams" method from version 1 of the API: System.err.println("processing Strava activity # " + stravaToCsv.activities[n]); String urlString = "http://app.strava.com/api/v1/streams/" + stravaToCsv.activities[n]; System.err.println("accessing ride data via URL = " + urlString); j

Comments on Contador

Image
Charles Pelkey wrote a truly excellent commentary on the recent decision to "retroactively" suspend Alberto Contador for trace levels of Clenbuterol in his blood during the 2010 Tour de France. It's probably the most level-headed, well thought out analysis I've yet seen on the matter. Clenbuterol is hardly an exotic doping agent. Even Sears sells it as a weight-loss supplement. There's a lot of the stuff flying around, and some of it ended up in Contador's blood in that Tour. How? The Court of Arbitration for Sport claims that the most likely method, having considered the alternatives, is a contaminated supplement. Indeed, the levels in Contador's blood were so low that no credible source claims they could have provided a performance boost. Either he ate contaminated food, took a contaminated drug or supplement, or transfused contaminated blood. The Court considered this last possibility, and claimed there was no supporting evidence. Anyway, Ch

update on Java coding project

Image
While it seems at times my early progress on my Android/Strava app project has stagnated, really I've gotten a decent amount done. On the computer side, I had to upgrade the Ubuntu on my Thinkpad T60 from 9.10 to 11.10 to allow for the installation of current packages. This was inhibited by an inability to access my CD drive, but a bit of isopropyl alcohol blown off with a blast of dry compressed air (borrowed from the tech support at work... shh!) on the sensitive bits seemed to fix that. As with my previous Ubuntu upgrade, I lost a lot of packages in the shuffle, even things as fundamental as emacs, but as these omissions are encountered I reinstall them. Things are basically up and running now. Second, I gave in and ordered a Mac Air. The Thinkpad is in a fairly sorry state at this point, and I really think the Mac will provide a better machine for my needs. I'll get that in another week. Then education: The Oracle (formerly Sun) Java Tutorial is quite good. I admi

commuting home on Potrero Hill

Image
Since returning home from my wonderful New Zealand trip I've definitely been in a rut. The rut is a "go to work, work through lunch, come home in the evening, eat dinner and go to bed" rut. It's a "I don't have time or energy to go for a ride/run/gym/whatever" rut. A rut where I can't leave early enough to ride to work, where I need to get in too early to ride to work, and so I take the train instead. It's a bit depressing. Being on vacation is being intensely alive: every minute of the day is one to be savored. "Normal life" is only a shadow of that, finding intensity in the fringes of our days. But while I've not yet SF2G 'ed this year, I've managed at least a few mid-say workouts. First last Friday I did a bit of a solo ride, hoping to catch the Apple lunch ride but unaware that it had been delayed. Then on Tuesday there was a group run from work, which was really nice. 17 km is a bit more than is justified from

Email to Nancy Pelosi on federal transportation bill

The house is considering a staggering $260B transportation bill , a bill which places the focus on the usual suspects: roads, cars, and drilling. It's an appalling continuation of the 20th century priorities which got us into such a mess of squandered resources, wasteful land use, and reliance on the whims of unstable governments supplying our oil. Here's my letter to Nancy Pelosi: It is foolhardy for us to continue spending valuable resources on a highway network which indirectly increases our reliance on fossil fuels, primarily imported. For energy independence we need to increase the efficiency of our transportation system, which means federal investments, if any, focused on public transit, not highway programs which are a relic of the last, misguided century. Please end the foolhardy reliance on highway programs which not only increase the nation's already crippling debt burden, but do nothing to create the sort of jobs or infrastructure we need to compete internat