Skip to content


My crocus is blooming

As far as I can tell, force blooming has nothing in common with force choking, but this is the first year I’ve tried it, so I’m still learning.

Anyhow, so far the experiment is a success. The picture below show one of my crocus bulbs pushing out a flower.

crocus bulb

crocus bulb

Posted in gardening.

Help me prep my new 8 x 16 garden bed

I’ve already got one 8×16 bed that I’ve been growing vegetables in for the last four years, and I want to expand. So I set up 2″x12″ boards around a new 8′x16′ section of my backyard that I intend to use for a new garden.

Right now, the space is a big mess. Imagine a yard that nobody mowed for 15 years and you’ll have a fairly good picture.

My soil is dense clay with lots of really nasty roots throughout. It drains poorly and is very compacted.

Here’s what I’m thinking about doing:

  1. Cut everything down as close as possible.
  2. Double dig the area and mix in compost and straw.
  3. Plant a cover crop.
  4. Dig in the cover crop in the early summer
  5. Grow some vegetables, mostly stuff that can handle dense clay soils.

What kind of cover crop should I use? I need something cold-tolerant. I’m more concerned with improving soil structure and adding more humus to the soil rather than boosting nitrogen levels right now.

Side note: I know all about the idea of just turning this into a raised bed, filled with a truckload of fancy store-bought dirt. There’s something about that idea that just doesn’t appeal to me. I want to enrich what I have, not just import the finished product from somewhere else.

Sure, this idea doesn’t really withstand scrutiny; after all, the straw I’ll be mixing in and mulching with later is purchased.

But somehow buying an $8 bale of straw, and $40 worth of composted horse shit to mix in seems more in the spirit of sustainability than spending hundreds of dollars on a truck load of topsoil shipped in from who knows where.

Posted in Cleveland Life, gardening.

Fear the Boom and Bust

brain. exploded.

Posted in Economics.

New year’s python meme

Doing this after reading about it on Ben’s blog.

1. What’s the coolest Python application, framework or library you have discovered in 2009 ?

I love the restructured text tools. I use rst2pdf at least once a week.

2. What new programming technique did you learn in 2009?

This was a year of giving up on techniques, paradigms, development methods, frameworks, and fanciness in general and going back to basics. I’m like Rocky Balboa in Rocky IV — jogging in the snow and chopping wood with an axe.

3. What’s the name of the open source project you contributed the most in 2009? What did you do?

I’ve been working on pitz for about 15 months now. I’ve learned about a lot of stuff that I didn’t expect to learn when I decided to build a to-do manager. Because of that project, I’ve learned about how templating systems like jinja2 work internally, how to use cProfile, how to write tests for all sorts of weird situations, how to write a simple querying system, etc.

4. What was the Python blog or website you read the most in 2009?

I just went through my bookmarks tagged with python and didn’t see an obvious pattern. These days, the hundred or so people I follow on twitter keep me supplied with too much to read.

5. What are the three top things you want to learn in 2010 ?

psycopg2 internals, datetime module internals (it is written in C and there is a patch I want to submit), and maybe stuff like ast.

Posted in Programming, Python.

Add an option for your script to drop into the debugger

I like using the python debugger to, umm, debug stuff. Just recently I wanted to use pdb to poke around in a script that would intermittently crash. I wanted to add an option to my script that would drop me into pdb when the script dies.

This turned out to be trivial to write. The script scratch.py doesn’t do much, but if you add the --drop-into-debugger option, you’ll get dumped into a pdb session, where you can study the problem more closely, like this:

$ python scratch.py --drop-into-debugger
> /home/matt/scratch.py(15)main()
-> 1/0
(Pdb) 

When I don’t add the --drop-into-debugger option, then of course the uncaught exception just crashes the script:

$ python scratch.py
Traceback (most recent call last):
  File "scratch.py", line 23, in <module>
    main()
  File "scratch.py", line 15, in main
    1/0
ZeroDivisionError: integer division or modulo by zero

The code involved was really easy to write. I wrote a decorator called into_decorator with the decorator module, but that’s not strictly necessary. Here’s the code:

# vim: set expandtab ts=4 sw=4 filetype=python:

import pdb, sys
from decorator import decorator

@decorator
def into_debugger(f, *args, **kwargs):
    try:
        return f(*args, **kwargs)
    except:
        pdb.post_mortem()

def main():
    x = 99
    1/0 
    
if __name__ == '__main__':
    if len(sys.argv) > 1 and sys.argv[1] == '--drop-into-debugger':
        into_debugger(main)()
    else:
        main()

That pdb.post_mortem function does the interesting work of inspecting the most recently caught exception. The pdb documentation is pretty dang sparse, but in this case, I got what I needed.

Anyhow, I hope this helps somebody out. I’ll probably be adding a –drop-into-debugger option on every script I write from now on.

Posted in Programming, Python.

The postgreSQL crosstab function is really powerful

I’m just beginning to wrap my brain around it. I’ve got some data that looks like this:


select rr as row_name, dt, c from mm limit 3;
+----------+----------+------+
| row_name |    dt    |  c   |
+----------+----------+------+
| xxx      | 2009 mar |  552 |
| xxx      | 2009 nov | 2179 |
| xxx      | 2009 jun | 1101 |
+----------+----------+------+
(3 rows)

And now I’m going to transpose it like this:

select * from crosstab('select rr as row_name, dt, c from mm limit 3')
as foo(row_name text, dt_1 bigint, dt_2 bigint);
+----------+------+------+
| row_name | dt_1 | dt_2 |
+----------+------+------+
| xxx      |  552 | 2179 |
+----------+------+------+
(1 row)

Neat, right?

Posted in PostgreSQL, Programming, SQL.

What’s wrong with using somebody else’s framework

“I wish that you, oh exalted one, would not be angry with me,” said the
young man. “I have not spoken to you like this to argue with you, to
argue about words. You are truly right, there is little to opinions.
But let me say this one more thing: I have not doubted in you for a
single moment. I have not doubted for a single moment that you are
Buddha, that you have reached the goal, the highest goal towards which
so many thousands of Brahmans and sons of Brahmans are on their way.
You have found salvation from death. It has come to you in the course
of your own search, on your own path, through thoughts, through
meditation, through realizations, through enlightenment. It has not
come to you by means of teachings! And–thus is my thought, oh exalted
one,–nobody will obtain salvation by means of teachings! You will not
be able to convey and say to anybody, oh venerable one, in words and
through teachings what has happened to you in the hour of enlightenment!
The teachings of the enlightened Buddha contain much, it teaches many to
live righteously, to avoid evil. But there is one thing which these so
clear, these so venerable teachings do not contain: they do not contain
the mystery of what the exalted one has experienced for himself, he
alone among hundreds of thousands. This is what I have thought and
realized, when I have heard the teachings. This is why I am continuing
my travels–not to seek other, better teachings, for I know there are
none, but to depart from all teachings and all teachers and to reach my
goal by myself or to die. But often, I’ll think of this day, oh exalted
one, and of this hour, when my eyes beheld a holy man.”

From Siddhartha by Herman Hesse.

Posted in Uncategorized.

pitz has a CLI

I’ve exposed lots and lots of pitz functionality as command-line scripts. Here’s the list so far:


$ pitz-help
    pitz-abandon-task          Abandon a task
    pitz-add-task              Walks through the setup of a new Task.
    pitz-components            All components in the project
    pitz-estimates             All estimates in the project
    pitz-everything            No description
    pitz-finish-task           Finish a task
    pitz-milestones            No description
    pitz-my-tasks              List my tasks
    pitz-people                All people in the project
    pitz-prioritize-above      Put one task in front of another task
    pitz-prioritize-below      Put one task behind another task
    pitz-recent-activity       10 recent activities
    pitz-setup                 No description
    pitz-shell                 Start an ipython session after loading in a ...
    pitz-show                  Show detailed view of one entity
    pitz-start-task            Begin a task
    pitz-statuses              All statuses in the project
    pitz-tasks                 All tasks in the project
    pitz-todo                  List every unstarted and started task in the...
    pitz-unassign-task         Take this task off somebody's list of stuff ...

Posted in Programming, Python, pitz.

A few iPhone or android app ideas

Just like my post with some web app ideas, feel free to steal any of these.

A fake lottery game

This has already been done several times. You would start with some money (fake money) then buy some tickets and scratch them off. Some would win (more money) and most would lose. Maybe I would hide silly messages in the tickets. The gimmick would be the activity of scratching off the tickets, or maybe spending money on other side treats. Like cigarettes. While smoking, maybe the screen would be hazy. Or maybe you could buy crystal meth, too, and you could scratch tickets really really fast.

And so forth. On to idea number two!

Pick a scab

If you want high-brow, go somewhere else. So, the idea here is obvious, right? The screen shows an ugly scab. You can pick at it. Then it bleeds. Then maybe it heals, and the cycle starts again. Probably been done before.

AWESOME RIGHT?

Pop the pimple

Yeah, so apparently this has already been done too, damnit. But what if the pimples could be superimposed on top of the photos in your album?

Posted in Programming, startup life.

Help me rewrite some repetitive scripts

I have about a dozen functions (that are run as scripts) that have very similar sections interleaved with specialized code. I copied two of the scripts below. Here’s the first:

def pitz_estimate_task():

    p = optparse.OptionParser()

    p.add_option('--version', action='store_true',
        help='Print the version and exit')

    # This script requires these arguments.
    p.set_usage("%prog task [estimate]")
    options, args = p.parse_args()
   
    if options.version:
        print_version()
        return

    # This is unique to this script.
    if not args:
        p.print_usage()
        return

    # And now we're back to boring generic stuff.
    pitzdir = Project.find_pitzdir(options.pitzdir)
    proj = Project.from_pitzdir(pitzdir)
    proj.find_me()

    # This section is specific to this script.
    t = proj[args[0]]
   
    if len(args) == 2:
        est = proj[args[1]]
   
    else:   
        est = Estimate.choose_from_already_instantiated()
   
    t['estimate'] = est
    # That was the last thing that was specific to just this script.

    # Save the project (generic).
    proj.save_entities_to_yaml_files()

That script does some “generic” stuff to build an object p, then adds on some extra tweaks to p, and uses p to build an options object and an args object.

Then the script does some generic stuff to build a proj object based on the data in the options.pitzdir object, and does some various method calls on the proj object.

And here’s another script:

def pitz_attach_file():

    p = optparse.OptionParser()

    p.add_option('--version', action='store_true',
        help='Print the version and exit')

    # Notice this line is different than the one in pitz_estimate_task.
    p.set_usage("%prog entity file-to-attach")
    options, args = p.parse_args()

    if options.version:
        print_version()
        return

    # This section is different too.
    if len(args) != 2:
        p.print_usage()
        return

    # Back to the generic code to build the project.
    pitzdir = Project.find_pitzdir(options.pitzdir)
    proj = Project.from_pitzdir(pitzdir)
    proj.find_me()

    # Some interesting stuff that is specific just for this script.
    e, filepath = proj[args[0]], args[1]
    e.save_attachment(filepath)

    # Save the project. (Generic).
    proj.save_entities_to_yaml_files()

So, the pattern in every script is: generic code, specific code, generic code, specific code, generic code. And each step depends on the previous step.

I know I could do stuff like wrap all the generic stuff into functions, but I’m not really a fan of that approach. I’m looking for an interesting way to reduce all repetition, but keep the legibility. I’m thinking some nested context managers or decorators might be the way to go. I like to hear ideas from other people, so, please, let me hear them.

By the way, all this code is from the command-line module of pitz, available here. That’s where you can see all the different variations on the same theme.

Posted in Programming, Python, pitz.