About Kent Cowgill
Articles filed under...
abs ab_ripper andylester arms back baggyshorts bestpractices bike blog bugs bus calculator cardio catalyst cgi chart chest chinups code cpan datamodel dbi doctor documentation exercise exhaustion fitness flattire flat_tire google gps heart_rate helmet history houston html humor journal kate kenpo_x kettlebell knees lazy legs lisa lisanne maps math matthew michaelmckenna mom montreal motivation movie mysql oops orm P90X pain park patellar_tendonitis patrick perl phb photos physical_therapy plyometrics poor_gait presentation procrastination pullups pushups pyramid rabbits racecondition rant refactor rest ribs ride route running shoulders situps slides sore spike sql statistics syntax test testing textile timex training triceps ups versioncontrol video vim vimrc walk warren work workouts yapc yapcna2007 yoga youtube

A R C H I V E S

(5)
(15)
(16)
(25)
(3)
(4)
(2)
(4)
(11)
(1)
(1)
(3)
(2)
(2)
(10)
(5)
(2)
(3)
(4)
(9)
(21)
(3)
(3)
(1)
(6)
(4)
(1)
(4)
(3)
(2)
(1)

    Is Kent Cowgill Online?
    View Kent Cowgill's profile on LinkedIn
    Add to Technorati Favorites

    Recent Entries...

    On track so far...

    The week is about half way over, and so far I haven't skippe...

    My pants are on fire!

    I lied. Friday evening I didn't do anything. Saturday ...

    Playing catch-up

    It's been a while since I've updated my P90X progress. A ...

    Re: Yoga kicks my butt

    You should try a different yoga mat. I highly recommend the...

    Yoga kicks my butt

    It's time for a confession. I haven't done an entire Yoga...

    Recovery week comes in the nick of time

    Since it's been a few days, and I know I've rearranged my in...

    Early to Bed, Early to Rise

    So I'm not exceptionally healthier, wealthier, or wiser. Bu...

    Chest and Back, week 3

    Sure, the date that's listed for this post is 10/28, but it'...

    No Procrastination, Some Pain, Some Gain

    After much cajoling and self-flagellation, I convinced mysel...

    Odd Math

    I must be counting something wrong. Granted, I haven't be...

    weblog | `web·lôg -läg |
    noun
    Another term for BLOG
    ORIGIN 1990s: from web in the sense [World Wide Web] and log in the sense [regular record of incidents.]
    blog | bläg |
    noun
    A web site on which an individual or group of users produces an ongoing narrative.
    ORIGIN a shortening of WEBLOG.

    Slow no more

    Kent Cowgill

    Hooray!

    Shortly after complaining about how long my main page was taking to load, I started thinking up ways to make it go faster. As far as I could see, one option would be to try to parse the perl with perl - but just borrow all the ideas and regexes from the perl.vim vim syntax file. Easy enough - just figure out what the metacharacters in vim map to in perl, etc etc and so forth.

    About a third of the way through my translation, I realized it was going to be harder than I was expecting/hoping, because there are some conventions in vim's syntax files that makes that sort of thing somewhat easy.

    Plus, I wasn't even sure how good the translations were, or whether or not they'd even do anything useful:

    
    my( $I, $i )
      = ( qr/[A-Za-z_]/, qr/[0-9A-Za-z_]/ );
    
    my $packageRef = qr/(?:$I$i*)?(::|')$i/;
    
    my $varPlain
      = qr/\\?(?:[@%\$]|\$#)\$*(?:
            $I$i)?(?:(?:::|')$I$i*)*\b/x;
    
    my $functionName
      = qr/\\?&\$*(?:$I$i*)?(?:
            (?:::|')$I$i*)*\b/x;
    
    
    

    Yuck.

    I toyed with the idea of doing something with PPI, but quickly dismissed that.

    I then thought I might've remembered reading something about creating some kind of "vim server" with Text::VimColor - so a quick read of that yielded nothing. But I noticed the link in SEE ALSO to Apache::VimColor, which thank goodness mentions Cache::Cache (and sibling Cache::FileCache).

    What was I thinking?

    So the solution was exceedingly simple:

    
    use Cache::FileCache;
    
    # to create a key for the cache
    use Digest::MD5;
    
    sub vimformat {
      my( $self, $text ) = @_;
      my $key = Digest::MD5::md5_hex( $text );
      my $cache = new Cache::FileCache;
      my $return = $cache->get( $key );
      if( ! defined $return ){
        # do hugely time-expensive formatting, set
        # the value of $return to desired text
        # set the cache key at the end
        $cache->set( $key, $return );
      }
      return $return;
    
    
    

    And just like that, the page is back to being under 2 tenths of a second to create. Even with (as of this post) more than 10 hunks of syntax colored code.

    Yay!

    Related Photos: None

    Main Page | Login

    Do you want to buy me ? Find more gift ideas at my wishlist