Wireless Friday, January 23, 2009

Got to love wireless!

ping www.google.com
...
Reply from 74.125.19.99: bytes=32 time=346ms TTL=249
Reply from 74.125.19.99: bytes=32 time=425ms TTL=249
Reply from 74.125.19.99: bytes=32 time=641ms TTL=249
Request timed out.
Request timed out.
Request timed out.
Reply from 74.125.19.99: bytes=32 time=212ms TTL=249
Reply from 74.125.19.99: bytes=32 time=992ms TTL=249
Request timed out.
Request timed out.
Reply from 74.125.19.99: bytes=32 time=428ms TTL=249
Reply from 74.125.19.99: bytes=32 time=587ms TTL=249
Request timed out.
Reply from 74.125.19.99: bytes=32 time=166ms TTL=249
Reply from 74.125.19.99: bytes=32 time=526ms TTL=249
Reply from 74.125.19.99: bytes=32 time=324ms TTL=249
...
Ping statistics for 74.125.19.99:
    Packets: Sent = 760, Received = 626, Lost = 134 (17% loss),
Approximate round trip times in milli-seconds:
    Minimum = 8ms, Maximum = 1061ms, Average = 235ms

OK, to be fair, that was the free wireless in Mountain View provided by Google. Perhaps not the best internet connection one might find. "You get what you pay for" and all that. And it allowed me to read the news while waiting for the Caltrain!

New look Thursday, January 22, 2009

The blog has a new look. It's a bit basic, but better than it was.

Now that I've finally got it working reasonably after playing around with the CSS for some time (not something I ever enjoy) I don't have the energy left to write anything else.

A blogger workflow Saturday, January 17, 2009

I wanted an easy way to write Blogger entries in my usual editor that gave me the ability to do simple formatting and code syntax highlighting. I've basically ported my old on-line workflow from Wordpress: using Markdown and a syntax highlighter (now Pygments, was previously something else in PHP). It's not perfect but good enough for me.

Step 1: Download Pygments and Markdown

Step 2: add Pygments CSS:

./pygmentize -S borland -f html > style.css

Then copy and paste the contents of style.css into your HTML template.

Step 3: Use Sam's crappy Python script

Here is a little script that that integrates the two tools; reads text from stdin and writes HTML to stdout. Copy and paste the HTML into Blogger.

import sys, re
sys.path.append("pylib")

import markdown2 as markdown
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter

def main():
  NORMAL, IN_PRE = 0, 1
  state = NORMAL

  p_lines = []
  n_lines = []
  lang = "python"

  for line in sys.stdin:
    line = line.rstrip()
    if state == NORMAL:
      m = re.match(r'\s*<pre lang="(.*)">', line)
      if m:
        state = IN_PRE
        lang = m.group(1)
      else:
        n_lines.append(line)
    elif state == IN_PRE:
      m = re.match(r'\s*</pre>', line)
      if m:
        state = NORMAL
        n_lines.append( highlight("\n".join(p_lines), get_lexer_by_name(lang),
            HtmlFormatter()) )
        p_lines = []
      else:
        p_lines.append(line)


  if len(n_lines) > 0:
    print markdown.markdown("\n".join(n_lines))

  if len(p_lines) > 0:
    print "Error in <pre>"

if __name__ == '__main__':
  main()

Step 4: Just go back and use Wordpress

Well, maybe. I like not having to maintain a Wordpress blog though.