CrossFit Sectionals NorCal Training Log 2010 #2

Another week, another bunch of training. After last week’s CrossFit Sectionals NorCal Training Log 2010 #1, this one was a bit better. Mainly because I got over my cold. However, some stuff was really tough.

SF Bay Swim 2010-01-16

Here’s what I did:

Monday 2010-01-11
WOD: 30 muscle-ups for time. I could only manage to do eight – which was a disappointment since I could do 30 back in September. I really feel like my upper body strength has taken a hit over the past 2 months. So that sucked.

After a rest, we did a 5×5 Back Squat, where I was a bit happier; 165 – 185 – 205 – 225 – 245, good, deep ROM throughout.

Being a bit miffed by poor muscle-up performance, I finished off with a bunch of slow, deep ring dips. Hoping that some weighted pull-ups and dips will bring back muscle-ups soon.

Tuesday 2010-01-12
WOD: Run a 5k. This was fine, raining a bit and our route through SF’s Pacific Heights is very hilly. My time was respectable enough, 26:40.
After that I took a rest and worked a 5×3 Power Clean. My max power clean previously was 195lbs, and I was disappointed to only be able to hit 3×175lbs this time. I was having odd sharp pains and spasms in my elbows and shoulders after each rep which I think were from the muscle ups on Monday. So I decided to leave it at that, which was a good idea I figure.

Wednesday 2010-01-13
WOD: 3 rounds for time of: 50 double unders, 50 push-ups. My time was 6:46 which wasn’t too bad. The push-ups were really what slowed me down. I feel like I used to be a lot faster at push-ups. I guess I just need to do like a 100 every morning when I get up.
After a rest, I did a Power Snatch to 5xOver Head Squat progression. I found that my elbows and shoulders were still sore from the muscle-ups and so I had to take some breaks in between each set for the spasms to die down. I made it up to 125lbs Power Snatch followed by 5xOHS, which was respectable enough.

Thursday 2010-01-14
Rest day

Friday 2010-01-15
WOD: Fairly long lifting session, 5×5 in Back Squat, Shoulder Press and Deadlift. Squat was reasonable I hit 260lbs x 5. Shoulder Press was a bit disappointing, I could only manage 4 reps at 125lbs, where as 2 months ago I was comfortably enough pressing 135lbs for 5 reps. So that sucked. For the Deadlift I started at 275lbs and hit 335lbs for 3 reps, but the bar just wasn’t coming up after that, possibly because I ripped a callous at 325lbs which was pretty distracting. Overall not a bad session but definitely not at my strongest at this point.

Saturday 2010-01-16
WOD: Swimming in SF bay! Thats where the photo above is from. This was pretty awesome – I actually ended up doing something like a mini-triathlon since I cycled 8 miles (to and from gym) ran 1.5 miles (from gym to bay) and swam for 10 minutes. Felt great, bloody cold though, looking forward to more swimming there in the future. 52F water is great substitute for an ice bath!

Sunday 2010-01-17
WOD: 5×5 dead hang pull-ups / weighted pull-ups @ 1 pood. 5×5 Ring dips. Like I said above I think my upper body strength needs some work so I thought this would be a good one. Definitely didn’t feel as strong with this resistance as I have in the past, so I think I’ll need to do this kind of WOD a fair bit more over the next few weeks.

Monday 2010-01-18
Rest day.

CrossFit Sectionals NorCal Training Log 2010 #1

In my last post on my CrossFit Sectionals NorCal Training Log I talked about why I was doing the sectionals, my goals, etc. That was a little over one week ago, and since then I’ve been working out pretty hard.

Here’s what I’ve done:

Saturday 2010-01-02
Training at home.
Four rounds for time: 30 Kettlebell Swings @ 1.5 Pood, 15 ring dips.
My time: 9:35

Sunday 2010-01-03
Rest day

Monday 2010-01-04
Back training at KMSF.
Started to come down with a cold.
As many rounds as possible in 12 minutes: Alley sprint followed by max pull-ups.
My results: 6 rounds, pull-up numbers: 20, 15, 10, 10, 10, 10. Hadn’t done max pull-ups for a while so didn’t go all out to avoid DOMS!

Tuesday 2010-01-05
2×800m sprints through Tenderloin.
First 800m: 2:20 (all out)
Second 800m: 2:58
5×5 Back Squat
185 – 205 – 225 – 245 – 265
Felt pretty good.

Wednesday 2010-01-06
This nasty WOD, with a nasty sore throat:
15-12-9
Overhead squats 135#
Burpees + Pull-ups

Getting hand position right for the squat after clean & jerk was the hardest part! Time was 11 minutes or so. Definitely need to work on power snatch – should just have been able to snatch 135# then go straight into squats.

Finished off with: 5 rounds of Power Snatch to 3xOverhead Squat. Got up to 125# comfortably on the power snatch+3xOHS.

Thursday 2010-01-07
Rest day. Cold got worse.

Friday 2010-01-08
Cold worse, sneezing all over the place, office party in evening so took another day off training.

Saturday 2010-01-09
Still had cold, decided to rest one last day.

Sunday 2010-01-10
Cold improving, back to training.
5 rounds for time: 20 Kettlebell swings @ 1.5 pood, 30 pushups.
My time: 11:10

CrossFit Sectionals NorCal Training Log 2010

Me participating in FBG IV at CF Oakland, Sep. 2009

I’ve signed up as an athlete in the CrossFit Games 2010 Sectionals NorCal. I’d consider myself an intermediate level CrossFitter at this point – able to complete all the WODs in a reasonable time – but certainly nothing compared to the guys at the top.

Why I’m doing the Sectionals

Great Team

Mostly, I’m going to compete because a bunch of my friends at the gym are also competing. I want to support our awesome crew and throwing my name in the ring seems like the best way!

Personal Goals

Even though I’m not exactly expecting to win, or even do especially well, I think the sectionals are important as a training goal. Having an event in the near future (12 weeks out at this point) is a great motivator. For me, CrossFit is very much a personal development thing. Although I enjoy the friendly competition at my gym and am looking forward to competing at the sectionals, as far as I’m concerned I’m mostly competing against myself. So, the Sectionals are basically a way to push myself and hopefully beat a bunch of my personal records along the way.

Training Log

I thought it might be cool to post my training log to my website. I already keep a private log as part of my diary, but having it public makes things a bit more interesting. I plan to update pretty regularly although I don’t know yet if it will be daily or more like a weekly digest. Since this is my first entry, I should start by stating roughly where I am right now.

Weight: 165 lbs
Height: 5′8″
Age: 26

Current Personal Records

Lifts

Shoulder Press: 155lbs
Back Squat: 300lbs
Deadlift: 375lbs
Power Clean: 195lbs
Overhead Squat: 145lbs

Named WODs

Fran: 4 minutes 33 seconds
Elizabeth: 9 minutes
Georgia: 5 minutes 20 seconds
Charlotte: 4 minutes 33 seconds
Randy: 3 minutes 57 seconds
Fight Gone Bad: 320 points

Other Stuff

5k time: 21 minutes 13 seconds
10k time: 48 minutes 10 seconds
Max pull-ups: 42
Max weighted pull-up: 95lbs

Many of the crew at CF KMSF!

Training Plan

I’ll be following the WODs at my gym as much as possible. I hope to be able to make it to the gym four times a week, more if possible. When not at the gym, I will work out at home. I have kettlebells, a pull-up bar, rings and an olympic weights set (300lbs of iron plates – can’t go too heavy) so I can do a bunch of good stuff in my apartment.

Strength

I believe that the single most important thing in the competition is going to be strength. The stronger you are, the easier every possible workout will be, no matter what. Also, strength takes a long time (years) to develop – compared with cardio endurance it can’t be trained quickly. So I’m going to work quite a bit on getting stronger with the power lifts and Olympic lifts.

Two-a-day

I’m also hoping to train in the morning and in the evening. In the morning I’ll probably focus on high intensity, many reps kind of stuff. I don’t know that I’ll be able to keep up two-a-day every day though.

Shoulder flexibility

Shoulder flexibility is probably the biggest single weakness I have. It makes some of the movements quite difficult and even painful for me – for example heavy push jerks. I’ve made good progress in the past year, but over the next 12 weeks I want to be particularly dilligent with icing and mobility work.

Diet

I’ll be following a Paleo Zone diet as best I can, although I’m not planning to be terribly strict about it for a while yet.

Supplements

I’m taking 200 mg chelated magnesium, 5,000 IU vitamin d3 and two tablespoons of fish oil daily and plan to continue.

Today’s Log

Gym is closed today so I worked out at home. Still getting back into things after a 2 week layoff while I was on vacation in Ireland. I ran this at home:

4 rounds of: 30 Kettlebell Swings @ 1.5 pood, 10 Dead Hang Pull-Ups.

Autocomplete with Python, Pylons, SQLAlchemy and jQuery

Recently I needed to implement my own autocomplete for a project on snagmachine.com. We had a large database of products and wanted to ease data entry by hinting to the user via autocomplete when possible.

autocomplete with python and sqlalchemy

In future, we can probably just use Freebase Suggest but right now we needed our own solution.

The Pieces

Autocomplete is not too hard to understand. It is comprised of two pieces:

  • Client-side javascript
  • Backend web service

Autocomplete JavaScript Widget

The client-side JavaScript code is the thing that watches user input to a given text-entry field, and sends queries to the backend web service. If the backend has some suggestions for the user, the JavaScript then displays those hints and lets the user pick one.

Although not hard to understand, the display code and query timing bits of the client-side component make it not utterly trivial to implement. For this reason, we decided to use an existing jQuery autocomplete widget, instead of writing our own.

Choosing one was a little bit confusing, because there are around four or five distinct jQuery autocomplete widgets floating around. It took some investigation to find one which fit our needs. We ended up picking Ajax Autocomplete for jQuery by Tomas Kirda.

We chose this one because it seemed to be the only widget which easily enabled you to pass arbitrary metadata to the client JavaScript from the backend, in addition to mere text completion. So, if you need to pass along IDs or other values with your suggestions, I recommend this widget instead of some of the simpler ones.

Setting up the autocomplete widget in your JavaScript is quite straightforward:

$("#sometextfield").autocomplete({
            serviceUrl:'/api/product_autocomplete',
            onSelect: function(val, data) {
              /* Handle data here */
            },
});

Backend Web Service

Writing an autocomplete web service is pretty simple. Your entrypoint is going to accept a string of text (query) and return a set of results to be displayed to the user by the autocomplete widget. Depending on your usage, you may also wish to include some metadata along with your results – for example, the database ID of each completion, or something like that.

The service is especially trivial if you are using a database which supports an analog to the SQL LIKE/ILIKE operator which does basic wild-card text matching. I believe that all databases supported by SQLAlchemy will have this feature.

Although I happened to be using SQLAlchemy and a fairly traditional RDBMS (PostgreSQL) for snagmachine.com, something similar should be quite possible with Tokyo Tyrant and the like.

We are using Pylons and SQLAlchemy for snagmachine.com, but again, it shouldn’t be much more complicated with some other web framework:

    @rest.restrict('GET')
    @jsonify
    def tag_autocomplete(self):
        if 'query' not in request.params:
            abort(400)
        fragment = request.params['query']
        keywords = fragment.split()
        searchstring = "%%".join(keywords)
        searchstring = '%%%s%%' %(searchstring)
        try:
            ac_q = Session.query(Tag)
            res = ac_q.filter(Tag.name.ilike(searchstring)).limit(10)
            return dict(query=fragment,
                    suggestions=[r.name for r in res],
                    data=["%s" %(r.name) for r in res])
        except NoResultFound:
            return dict(query=fragment, suggestions=[], data=[])

In the above code, we are using a very simple SQLAlchemy model class “Tag” which basically consists of a text `name’ field:

tag_table = sa.Table("tag", meta.metadata,
    sa.Column("id", types.Integer, sa.schema.Sequence('taq_seq_id',
        optional=True), primary_key=True),
    sa.Column("name", types.Unicode(50), nullable=False, unique=True),
    sa.Column("extra", types.String),
)
class Tag(object):
    pass
orm.mapper(Tag, tag_table)

We also use the Pylons rest decorator and the Pylons jsonify decorator for convenience.

Note that in the above code, we:

  • Use the ilike operator
  • Use wildcards at the beginning and end of the string
  • Replace whitespace with wildcards

We’ve found this mode to give us the best user experience, however there are performance implications. PostgreSQL at least can only utilise text indexes for LIKE, and furthermore only if the wildcards are suffixes [This email from Tom Lane has the details].

While using the index does yield about an order of magnitude difference in query response time, we are talking about 0.1 ms vs 1.0 ms with our dataset. For our use case, this is perfectly acceptable!

So, thats pretty much everything there is to it. Hope this article helps!

Pylons tip #5 – Streaming static files

Pylons makes it super easy to return data to a client. You just return a string from your controller method!

class HelloController(BaseController):
 
    def index(self):
        return 'Hello World!'

Very nice. However, what if you want to serve up a potentially quite large file to the client? Sure, you could read the file into memory, and then return the entire buffer, but that is not very efficient. If you have a multi-megabyte file, you end up wasting lots of memory.

What you want to do, actually, is read a chunk of the file at a time, and then send that. So instead of reading the entire file into memory and returning it in a single go, you do lots of little chunks.

Simple conceptually. How do you do this in Pylons? Thankfully you can do this with a Python generator. Instead of returning a buffer, you return a generator:

class ImageController(BaseController):
 
    def index(self, id):
        ''' Stream local image contents to client '''
        try:
            imgf = open("%s/%s" %(config['image_data_dir'],
                os.path.basename(id)), 'r')
        except IOError:
            abort(404)
        def stream_img():
            chunk = imgf.read(1024)
            while chunk:
                yield chunk
                chunk = imgf.read(1024)
            imgf.close()
        return stream_img()

This works quite nicely. Hope that helps!