syntax highlighter

I just installed a syntax highlighter tool here on Rhymes With Milk and am pretty excited about it so far. What it means is that I can paste snippets of code into WordPress’ post editor essentially verbatim, and a JavaScript function translates it into a nicely formatted version for the blog.

I had seen this sort of thing on other websites before, but only just realized that I might have a use for it, too. I wasn’t quite sure how to go about finding something like that, so I asked Twitter if it had any recommendations. True to form, Twitter offered me no help, so I started doing my own research. Finding the right set of keywords to search for one of these wasn’t easy, but I eventually stumbled onto Alex Gorbatchev’s webiste. It was exactly the one I was thinking of when I set out to find one.

After a super simple install (you just have to FTP the files to your server and add the right file calls in your header) and some custom styling, it was all ready to go. I did have a few problems personalizing it though.

toolbar functionality

The program has an optional little toolbar that pops-up when you hover over the syntax highlighter div with buttons for printing, copying, displaying as plain text in a pop-up, and a small “about” pop-up. I initially thought this toolbar could be pretty handy, but that some of the buttons could probably go—namely the print one. I hardly believe anybody is ever going to see my code examples, a small fraction of them are actually going to care about what they’re looking at, fewer would actually want to use it for reference, and none of them would want it physically represented so badly that there should be just a single button for them to accomplish that. But despite digging around in the core JavaScript file for quite a while, I wasn’t able to figure out how to selectively remove buttons. It looked like for me it was all-or-nothing.

I decided that I should go with “all” at this point mostly because of the copy button. The way the lines are displayed within the div make it so that when you manually highlight-and-copy, you also get stuck copying the line numbers. This little cumbersome detail made me think that having a single copy button that only grabs the relevant code would be convenient, but there’s some sort of XML file that the function looks for but could not find. Something like that. Again, digging around in the core files didn’t help me any, and unfortunately the official website has pretty poor documentation and troubleshooting help.

line wrap

The line wrap function, unlike the ones dictating the toolbar buttons, can simply be switched on or off with an appropriately placed “true” or “false” respectively. When turned on, lines wrap nicely (although no line wrap is generally all that nice when looking at code), expanding the height of its table row, pushing the following lines and line numbers down further. When wrap is turned off a scrollbar appears at the bottom. I almost prefer this method, but it doesn’t display everything beyond the edge of the box very nicely. For some reason, the lines alternating colors end at the edge of the box, and a solid background color is displayed beyond their right ends, and depending on the CSS, this color might not ever correspond to either of the line colors. Lame.

solution?

I found this guy who has created a modified version of the original syntax highlighter. His previous documentation claims that a few of the issues I mentioned above had been fixed, and a ton of extra (and helpful) functionality had been added. I downloaded it and started testing the different functions…and it fell short of the claims. For all that I could tell, I had downloaded the same damn thing as the original. And again, explanations on how to implement said added functionality was minimal. I gave up with it much quicker than I normally do with things mostly because the test html file that comes with the download (it’s meant to test whether the program works or not) was out of date. It was the test file for the previous release, not the most current. I couldn’t even use his own test file as reference on how to implement the various features. I can think of other ways to find reference, but I stopped there because even that kind of small oversight makes me lose faith in the developer.

Therefore, I stuck with the official release (not the mod) and just turned the toolbar off, and line wrap on.

I was going to leave you with a small C++ example since that’s the language I’m currently using the most, but it’s syntax mode is actually kind of lacking. So instead, how about we try doing a PHP program (which has much better syntax support) that uses the accumulation plan.

<?php

$myArray = array(12, 102, -44, 61, 0);
$total = 0;

for($i=0; $i<count($myArray); $i++)
{
	$total += $myArray[$i];
}

echo 'The total amount in my array is ' . $total . '!';

?>
2 Comments »
date Jan 31st 2010
author Mike
category Geek
tags
  2 Comments

on drinkin alone at a bar

Until tonight, I had never sat at a bar by myself and drank. I see movies all the time that glorify it, but also enough drunks at the Cafe doing it to cancel out the cool.

I sit here alone mobile blogging from the bar at City O’ City on 13th and Sherman in Denver. I have a candle, a cup of water, and a glass of Wild Turkey in front of me, in order from left to right.

A super cute late-20-something hipster couple sits to my right reading their own books that they just bought from a used book store, neither of them more than ten pages in, looking up only every few minutes to have small but meaningful conversations with one another.

I have little to do here other than sip and be observant. But I’m happy doing just that.

I watch the bartenders do their work and shoot the shit with the usuals. They occasionally notice me watching, and we just smile at eachother. One bartender, the one that gave me the heavy pour, a girl, tells me that my smile is inviting, and says that every time she sees it she feels compelled to ask if I’m ready for another round or some food. I take it as I look lonely and need someone to be nice to me, but she says it’s a good thing. I believe her because her smile is reassuring.

No Comments »
date Jan 23rd 2010
author Mike
category Life
tags,
 

a word on homelessness, then more bike stuff, but only a little of each

A drunken homeless man fell asleep in the women’s bathroom at my office today.  A little girl in the middle of her piano lesson down the hall found him.  Turns out he wasn’t in too deep of a sleep though, because as soon as the sweet-old-lady-teacher went to investigate, he popped up from his place of slumber and bolted.  Those homeless guys can be fast when they want to be.  They’re kinda like crocodiles in that way, I guess.

I have no idea if what I just said comparing hobos to crocs is true.  Or offensive.  I didn’t intend on either.

Sooooo today was Boulder’s official 2010 Winter Bike to Work Day.  Seeing as how I bike to work most days, today was just like any other except that I got a free bagel at Moe’s.  Thanks, Moe.

Btw, check out Moe’s favicon.  That’s how you know the site was built using Joomla, just like freedtvroom.com (guess who has two thumbs and did all of the content entry aaaannnnnddddd “designed” the facebook link on that bad boy. This guy!).

A very awkward girl talked to me this evening on my ride home from work.  Because of the way the streetlights are timed, I always end up getting stuck at the NE corner of Arapaho and 28th.  Normally I wait on the small pedestrian island there alone, but tonight there was a girl standing there about 8 feet to my right.  I was not within her direct line of sight, nor she in mine, but for some reason I could feel her eyes burning a hole in the side of my head.  I refused to look back, but it was becoming unbearably awkward.  After the longest ten seconds of my life, I hear an oddly matter-of-fact “Hi,” almost like she had been expecting me to say it first or something.  I could practically hear how red and frizzy her bangs were just by the way she said “hi.”

“Hello,” I said back.  ”How’re you?”

“I’m okay.” Super awkward pause where she just looks at me with half of a smirk playing across her mouth.  She then turned around, awkwardly looked at the moon, then mumbled something about it being a nice night.

“Yeah, it’s not too chilly for a bike ride, so that’s a good thing,” I said, trying to stave away the awkwardness.

“Haha!  Chilly is nothing for winter.  Chilly is nothing compared to frost!”

“Um…”

“I’m from Crested Butte.”

And thank god the light changed just then.  I quickly said “Have a great night!” and rode off, never to see her again, yet still surrounded by a cloud of awkward.

No Comments »
date Jan 20th 2010
author Mike
category Life
tags, , ,
 

lots of bike stuff

Want to know what I did today?  I took pictures of a $900 bicycle stem.  You see this guy?  Imagine an $885 better version.

I don’t know how many people know this, but I work for an online retailer of high performance specialty bicycle components.  One of the owners of the company I actually work for started it as a side project about a year ago, and though it’s not a huge operation, it’s a decent second source of income for him and it can sometimes take up a significant amount of our work time.  Though I do little more than product input into our e-commerce website and ship orders, I’ve learned a hell of a lot about bikes.  In fact, I’ve somehow become something of a snob about it.  I guess that comes with the territory of selling $150 skewers (the long pegs you put through your wheels to clamp them onto the bike).  If I see a bike and it doesn’t have a carbon fiber stem top cap that weighs 5g or less, I scoff.

Then I get onto my road bike, with stock components all around, and can’t believe how good it feels to ride it.  It glides like it’s on butter.  When I’m riding it, instead of wishing I had 18-spoke carbon tubular rims on it, I scoff at the people that would spend the two grand on a set of those.  My cheep-by-comparison aluminum clincher rims with their unaerodynamically shallow depth ride better than I could ever ask for.

Granted, if I ever actually rode one of those baller $10,000 all-carbon bikes, I’m sure I’d be singing a different song.  Maybe I’ll just avoid riding one of those for my entire life so that I’ll always appreciate what I have.

Anyway, despite my ravings about it’s awesomeness, my road bike sucks in weather.  I’d never take it out in any kind of precipitation, and it’s tires are slippery (as if they were riding on butter?) so any moisture/ice on the ground is liable to kill me while I’m cornering.  Anytime it snows, I have to stay off of it for a minimum of a week until some of the ice has melted, and the paths and sidewalks aren’t so wet.  Typically during that time I ride my 10-year-old mountain bike which is durable enough to take all the beating and weather I can put it through, and crappy enough that I don’t care if it literally explodes while I’m riding it (idk why it’d do that…).

Unfortunately, though, it’s been going through a tough time these last few months.  The shifters were starting to crack, which is unsurprising since they’re entirely plastic and they often take heavy abuse.  The cable tension started making them slip out of place, allowing the derailer to shift the chain from cog-to-cog, making smooth riding very difficult.  I’d have sore hands after any length ride because I’d have to hold the shifters so tightly to keep them from slipping out of position.

So the natural solution: tear the shifters off the bike.  This caused a chain reaction that resulted in me deciding that the bike should be a single speed.  Without shifters, the derailer isn’t going anywhere, so the chain is always going to stay on the same ring (hence single speed).  This makes the entire cassette (except for the single ring the chain ends up on) just dead-weight (and since I’ve become a weight weenie by association, I won’t allow a single unnecessary gram to be on my bike).  Might as well lop the derailer off while we’re at it.  Then in the front, the middle chain ring has a bent tooth that causes the chain to slip off, so we’ll get rid of that one.  The small chain ring on a mountain bike is so damn small it’s useless unless you’re climbing 45° inclines, so that’s gone.  Front derailer: gone.  All associated cables: gone.

Unfortunately, half way through working towards this, I realized that bikes were made with very specialized tools, and therefore need very specialized tools to take them back apart.  All the tools that I need would end up costing me more than all of the materials I had to buy to make the conversion.  Eff that noise, bra.  So now my bike is laying in pieces (but not the pieces I want it to be in) and all of the parts I took off of it are too destroyed to put back on.  So now it’s single speed or bust.

Since I work with some actual bike enthusiasts (not just posers like me), naturally they have all of the necessary tools and should bring them in for me in the next few days.

Um… that’s all.

There’s no moral to this story.  Any of it.

No Comments »

Australian dreams

I just woke up from another dream about living in Australia. I occassionally have these dreams, but they’re never the same. In fact, few of them are even of the Australia I’m familiar with. There’s always a certain feeling I get during these dreams that immediately tell me I’m in Australia again, though.

Despite their differences in content and “location” each time, they always make me feel so free. Drinking scotch with the owner of a local pub, watching the streets flood with people after a Waratahs game, jogging to downtown, emailing my boss to let her know that I’m not sure when I’m coming back.

Then I wake up and realize I have to be at the office in less than two hours. It was only a dream.

No Comments »
date Jan 11th 2010
author Mike
category Life
tags,