Pirnat.com

On second thought, let’s not go to Camelot; it is a silly place

Pirnat.com header image 4

links for 2008-04-26

April 26th, 2008 by Mike
RespondGravatar

Tags: UncategorizedLeave a Comment Print This Post

Hopefully Minimizing Wheel Reinvention

April 23rd, 2008 by Mike
RespondGravatar

Dear Lazyweb:

I have a number of programming itches that I’d like to scratch that are just slightly large enough that I’d really love to just use something that already exists (if available). I’d spend a while digging around, but, well… I’m lazy, and I’m busy. So hopefully some of you have suggestions. I am looking for:

  • an MSN Messenger client library (preferably in Python)
  • a Twitter client library (preferably in Python)
  • a solution for cross-posting between LiveJournal and Wordpress (either direction) that supports (or could be made to support with a minimum of pain) multiple LJ blogs on one end and multiple WP users on a shared blog (not that my wife really posts that much any more) on the other
  • a hosting provider that’s friendly to IM bots and is affordable (for some value of “affordable” that I have yet to precisely define, but which in all likelihood simply means that it won’t cause marital unrest)

I may award bonus points if the MSN and Twitter suggestions are both written against Twisted. I know Twisted’s got some MSN support, but I’ve not looked into it too closely and was a little disappointed by the state of the official docs and examples.

I currently host with WebFaction and though I’m normally entirely satisfied with them, I seem to recall that at one point they frowned on running IM bots on their shared hosting platforms, although I can’t immediately find anything expressly prohibiting it in their terms of service, AUP, knowledgebase, and support forums.

Thanks in advance!

Tags: geekery  python2 Comments Print This Post

Wait, How Old Is My Kid Again?

April 22nd, 2008 by Mike
RespondGravatar

The thing about being a relatively new parent is that life very quickly becomes a complete blur, and after a certain point you’ve no sense of what day it is, let alone how many weeks old your little bundle of joy is. This makes life tricky, since there are certain milestone weeks that are usually the harbingers of sudden shifts into higher levels of fussiness and sleep regression.

So what’s a frazzled dad to do?

Well, I do have Python, and I seem to have Google Reader open an awful lot, and cron jobs are a lot better at remembering to do things than I am… So here’s my fifteen-minute solution that I whipped up the other week in between putting Claire down for her morning nap and getting ready for work. (File names and URLs have been changed to protect the innocent.)

#!/usr/bin/env python
 
import datetime
from dateutil.rrule import rrule, DAILY, WEEKLY, MONTHLY
import PyRSS2Gen as RSS2
 
# You'll want to change all of these values, obviously...
KID_NAME = u'Claire'
BIRTHDAY = datetime.datetime(2007, 9, 10, 21, 57)
FEED_URL = 'http://yoursite/kids_age.xml'
FILENAME = 'your_path/kids_age.xml'
 
def periods_between(freq, start_date, end_date):
    rr = rrule(freq, dtstart=start_date)
    periods = len(rr.between(start_date, end_date))
    return periods
 
def format_entry_body(months, weeks, days):
    body = """<h1>Today, %(kid_name)s Is...</h1>
    <ul>
        <li>%(months)s months</li>
        <li>%(weeks)s weeks</li>
        <li>%(days)s days</li>;
    </ul>
    <p>They grow up so fast!</p>"""
    kid_name = KID_NAME    # so we can cheat with locals()
    return body % locals()
 
def make_rss(body):
    now = datetime.datetime.now()
    # Add a hash component to the item link so that the RSS reader
    # will recognize this as today's new entry...
    item_url = FEED_URL+'#'+now.strftime('%Y%m%d')
    rss = RSS2.RSS2(
        title=u"How Old Is %s?" % KID_NAME,
        link=FEED_URL,
        description=u"How old is %s in months, weeks, and days" \
            % KID_NAME,
        lastBuildDate=now,
 
        items = [
            RSS2.RSSItem(
                title=u"How old is %s today?" % KID_NAME,
                link=item_url,
                description=body,
                guid=RSS2.Guid(item_url),
                pubDate=now,
            )
        ]
    )
    return rss
 
def to_xml(rss):
    xml = rss.to_xml()
    # Make our xml at least a tiny bit human-readable
    xml = xml.replace('><', '>\n<')
    return xml
 
def main():
    now = datetime.datetime.now()
    months = periods_between(MONTHLY, BIRTHDAY, now)
    weeks = periods_between(WEEKLY, BIRTHDAY, now)
    days = periods_between(DAILY, BIRTHDAY, now)
    body = format_entry_body(months, weeks, days)
    rss = make_rss(body)
    xml = to_xml(rss)
    f = open(FILENAME, 'w')
    f.write(xml)
    f.close()
 
if __name__ == '__main__':
    main()

You will, of course, have to install dateutil (via easy_install) and PyRSS2Gen (the old-school tarball way) so that they can do the heavy lifting for you.

Then all that’s left is to cron it to run daily, and point your favorite RSS reader at the feed. Voila! You’re on top of exactly how old your kid is, and quickly on your way to becoming Parent of the Year.

Tags: children  claire  geekery  python6 Comments Print This Post

links for 2008-04-18

April 18th, 2008 by Mike
RespondGravatar

Tags: UncategorizedLeave a Comment Print This Post

links for 2008-04-13

April 13th, 2008 by Mike
RespondGravatar

Tags: UncategorizedLeave a Comment Print This Post

The Shell Meme

April 11th, 2008 by Mike
RespondGravatar

Since everyone else is doing it…

$ history|awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}'|sort -rn|head
145 ls
143 cd
136 vim
108 svn
90 jobs
65 %1
50 %2
47 nosetests
47 less
21 grep

%1 and %2 are usually me hopping back into backgrounded vim sessions. jobs is me trying to remember what all I’ve already got open for editing. The other things should be pretty self-explanatory. :-)

Tags: geekery  linux  memes  pythonLeave a Comment Print This Post

links for 2008-04-11

April 11th, 2008 by Mike
RespondGravatar

Tags: UncategorizedLeave a Comment Print This Post