About Kent Cowgill
Articles filed under...
abs ab_ripper andylester arms back baggyshorts bestpractices biceps bike birthday 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 home houston html humor journal kate kenpo 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 pdf perl phb photos physical_therapy plyometrics poor_gait presentation procrastination progress 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

(3)
(1)
(3)
(2)
(7)
(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...

    Re: Re: Yoga kicks my butt

    Chris @ 46: Tatyana @ 21 – at best its a stop gap measure...

    Re: Vibram FiveFingers FTW

    Hats off to whoever wrote this up and potesd it....

    Re: A little more detail on using a new model

    百度 [url=http://www.sina.com]sina[/url] ...

    Re: Catching up through week 7

    testing video ...

    Re: Porting a non-Moose object to Moose

    Wow, look what I found, greedy genius ...

    Re: Porting a non-Moose object to Moose

    Kevin, You're right, that does seem a little confusing. ...

    Re: Porting a non-Moose object to Moose

    Wait. I'm confused. Moose isn't the tool to reach for. So...

    Re: Porting a non-Moose object to Moose

    You should switch to MooseX::Types to declare your Typed and...

    Porting a non-Moose object to Moose

    I'm currently working with a lot of legacy code in an envi...

    Testing strategy for mocking code

    I keep finding myself using the following idiom for writing ...

    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.

    Easy way to copy code to Keynote

    Kent Cowgill

    So I'm working on a new presentation for my local Perl Mongers group, and (indirectly) thanks to Ricardo Signes, I've got a cool way to get properly syntax colored code into my slides.

    Ricardo has been working on an easy way to get syntax colored code into Keynote presentations. I wondered why he was bothering to convert the syntax colored code to RTF - then I realized why - I think because TextEdit.app on Mac OSX is a cocoa application, the font coloring is preserved through copying and pasting the code into Keynote, another cocoa application.

    A little later on, I was creating some other presentation, and was copying some code out of my blog and happened to notice that the code I copied and pasted from Safari, my web browser, also retained its coloring information.

    Problem solved, right? Anything I want to put into a Keynote slide, I should blog about first. Right?

    Wrong.

    That's too much blogging.

    Instead, I wrote a teeny tiny little CGI to post up the syntax colored source of anything sitting around on my server, using the same Text::VimColor module on the backend.

    This is that CGI:

    #!/usr/bin/perl -T

    use strict;
    use warnings;
    use Text::VimColor;
    use CGI qw/:standard/;
    use CGI::Carp qw/fatalsToBrowser/;

    $ENV{'PATH'} = '/bin';

    my $file = param('f') || 'photos/photoblog';
    my $lang = param('l') || 'perl';

    die "Bad file" if $file =~ /^[^a-z]/i;
    die "Bad file" if $file =~ /[^a-z\/._-]/i;
    die "Bad file" unless -f $file;

    die "Bad type" unless $lang =~ /(?:perl|php|xml)/;

    open my $in, '<', $file;
    my $text = do { local $/; <$in> };

    my $vim = Text::VimColor->new(
      string => $text,
      filetype => $lang,
      vim_options
        => [qw(-RXZ -i NONE -u NONE -N -T xterm)],
      vim_command => '/usr/local/bin/vim',
    )->html;

    ... and then a little HTML to display it in the right font, font size, and using my standard code stylesheet - which is left as an exercise for the reader.

    Related Photos: code keynote

    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

    Too slow

    Kent Cowgill

    So I'm really disappointed.

    That syntax coloring I'm doing for the various bits of code?

    Slow.

    Like, really really slow.

    I know I've posted about it before, but since then, I've got 8 separate syntax colored boxes on my primary page. This takes anywhere from 1.8 to 2.4 seconds to generate.

    This is not an acceptable solution.

    The alternative is that at this point, I will have to come up with at least 5 posts in a row that don't have any syntax colored blocks at all before the page generation times comes down to a more acceptable level. Until then, I apologize for the poor viewing speed.

    Related Photos: None
    Comment on 'Too slow' [ no replies - permalink ]

    Text::VimColor works!

    Kent Cowgill

    Turns out I was able to get Text::VimColor to work after all - seems I wasn't quite reading the documentation properly. See, vim needed a little help to figure out what's what - in this case, what kind of terminal it's attached to (which it isn't in this case, which is running as a CGI under apache).

    According to the documentation for vim:

    -T {terminal}
            Tells Vim the name of the terminal
            you are using. Only required when the
            automatic way doesn't work. Should be
            a terminal known to Vim (builtin) or
            defined in the termcap or terminfo file.

    So all I really needed to do was give it a hint so it wouldn't complain about not being attached to a terminal. Therefore, the solution is:

    my $vim = Text::VimColor->new(
      string => $code,
      filetype => $filetype,
      vim_options => [qw(-RXZ -i NONE -u NONE -N -T xterm) ],
    );

    Unfortunately, it's slow.

    It's a known issue - this is why Apache::VimColor uses caching to speed up the HTML generation. In fact, with five code snippets on the main page (just prior to this current time of writing) case the page generation speed to go from about 0.07 seconds to nearly 1.1 seconds. That's quite an order of magnitude increase. And that's not counting adding these two snippets in a single post5, nor the posts in the future that will undoubtedly have more code and other syntax colored snippets.

    5 Adds another 0.4 seconds for a total run time of nearly 1.5 seconds.

    Related Photos: None

    Kate doesn't do VIM

    Kent Cowgill

    I guess I shouldn't be surprised.

    I was hoping to post up bits and pieces of my .vimrc file - after all, Text::VimColor displays .vimrc syntax just fine. Naturally.

    Unfortunately, Kate doesn't appear to support .vimrc files.

    At least not yet.

    Until I write Syntax::Highlight::Engine::Kate::Vim, I'll have to make due with using the 'LPC' syntax file, which at least colors comments differently from non-comments , and somewhat reliably.

    Here's a snippet from my .vimrc for some new (to me) features that I've been playing with lately:

    " auto indenting, dealing with tabs
    " how to deal with tabs. indent of two
    set tabstop=2
    " expand tabs to spaces
    set expandtab
    " number of spaces to use for autoindenting
    set shiftwidth=2
    " auto indenting features
    set autoindent
    set smartindent
    "make tab in visual mode indent code
    vmap <tab> >gv
    vmap <s-tab> <gv


    Enjoy!

    (Note, due to difficulties and annoyances beyond my control, I've manually edited the above snippet using Text::Textile formatting.) Figured it out.

    Related Photos: kate

    Syntax highlighting

    Kent Cowgill

    Always looking for inspiration, I happened upon Jonathan Rockway's blog and noticed that he makes use of syntax highlighting in his Angerwhale blog. After a few aborted attempts to use Text::VimColor, I broke down and decided to try out Syntax::Highlight::Engine::Kate.

    I'm pretty pleased, after I finally figured out enough of how it formats bits of code and how to translate that to my vim colorscheme of choice.

    All it takes is the following modifications to your text:

    <pre class="Language">
        # your code here
      

    And if Kate recognizes your 'Language', it'll format your text.

    N.B. -- I can't quite figure out how to show a closing 'pre' tag inside a 'pre' block. Hope that doesn't offend you.

    Related Photos: kate

    Main Page | Login

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