Greg Aker

Entries Tagged with: Python

Debugging Python with pdb or ipdb

Filed in: Python, VideoBlobbing

April 5, 2012

Python has a wonderful debugger called pdb you should use if you aren't already. If you're like me and prefer to not use an IDE, you could have a mess of print statements as you try to debug things. If you don't know about it, you should be using pdb. It makes debugging a far nicer experience.

Here's a little script I came up with to remove odd numbers from a list.

import unittest

def remove_odd_numbers():
    my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    for item in my_list:
        if item % 2 == 1:
           my_list ...

Read More

oAuth & the 37 Signals API

Filed in: Python, Django

February 25, 2012

I started what was supposed to be a quick and fun Django project using the Basecamp API. The lack of documentation in their API makes me want to punch a litter of puppies. (This is a joke, puppies are the best)

To help prevent you from punching puppies and rather than trudge through their APIs Google Group, here's what I've figured out. I'm using Python Requests because it's fantastic. If you don't use it stop the insanity, and make your life easier by using it. Additionally, my code examples are within the context of Django ...

Read More

Site Updates

Filed in: Python, Nginx, Django, Blobbing

December 16, 2010

I pushed some updates to my site here earlier this week. Updated to Django rev 14870, implemented Xapian with Haystack, ditched categories and moved to django-taggit.

So here's a quick and simple Django template tag I came up with that reads the file modification time of css/javascript files and appends a v=n query string.

from django import template
from django.conf import settings
from os.path import join, getmtime

register = template.Library()

@register.simple_tag
def static_asset(filename):
    """
    {% load static_asset %}
    <link rel="stylesheet" href="{% static_asset "css/main.css" %}" type="text/css">

    Renders a link like:
    <link rel="stylesheet ...

Read More

Migrating Simple Desktops and Making it Rule - Part 1

Project Layout & Nginx

Filed in: Python, sysadmin

December 1, 2010

I worked with Kenny Meyers to move the kick-ass Simple Desktops website over to a new VPS and front static assets on EngineHosting's CDN. Kenny did the Django programming and it was a fun learning experience for us, as we moved from MySQL to Postgres and deployed with Chef, Gunicorn, Nginx and Fabric.

  1. Project Layout & Nginx
  2. Gunicorn & Supervisor
  3. Fabric
  4. Migrating from MySQL to Postgres

Project Layout

I had Kenny shuffle the project directory layout just a bit, we added the project specific configuration files in the config dir, pip requirements to the dependencies.txt file and application source files ...

Read More