Continuing my whirlwind tour through scripting languages, Here are the main parts of my site generator redone in Python:
os.chdir("entries") entries = os.listdir(".") entries.sort() entries.reverse() posts = "" for e in entries: cmd = "markdown %s" % e post = os.popen(cmd).read() date = e post_html = template_post % (date,date,post) posts += post_html main_page = template_master % posts print main_page
Table of Contents
#!/usr/bin/env python import os import sys import re output =  for arg in sys.argv: with open(arg) as f: for line in f: if (re.search(r"^###", line)): date = arg line = re.sub(r"### ", "", line) line = re.sub("\n", "", line) output_line = '<a href="index.html#%s">%s</a><br>' % (date, line) output += [output_line] output.reverse() for line in output: print line
Also serving the site using the below code utilizing Python’s included SimpleHTTPServer package.
import SimpleHTTPServer import SocketServer import os import grp import sys PORT = int(sys.argv) user = int(sys.argv) group = int(sys.argv) Handler = SimpleHTTPServer.SimpleHTTPRequestHandler httpd = SocketServer.TCPServer(("", PORT), Handler) os.setgid(group) os.setuid(user) print "dropped privileges to user: %s group: %s" % (os.getuid(), os.getgid()) print "Serving at port", PORT httpd.serve_forever()
Favorite Programming Languages
Currently the list of languages that I am most attracted to is:
This is different from the languages that I would actually claim to be somewhat competent in:
- C (would like to be more so)
- PHP (somewhat)
I feel like I’m becoming competent in Perl, and I am working to become competent in C# and possibly F# since those are languages that are used or potentially used at work.
Setting up yet another emacs instance:
Here are the entries in .emacs that I have to have:
(setq-default indent-tabs-mode 'nil) (global-set-key [(control h)] 'delete-backward-char)