Blog

Posts from January 2012

Quick Django Class Based View Decorator

Posted by Vláďa Macek on January 30, 2012. Filed under django, pro tip

The recommended way to add decorators such as login_required to class based views in Django is a bit verbose. Here’s a little metaclass-producing function you may find handy:

def DecoratedDispatchMethod(actual_decorator):
    """
    If you want to decorate the Class-based View with, say, login_required,
    the recommended way is this:

        @method_decorator(login_required)
        def dispatch(self, *args, **kwargs):
            return super(MyProtectedView, self).dispatch(*args, **kwargs)

    To avoid the need of writing this ugly code again and again, one can use
    this as a metaclass of the class that needs to be protected with a decorator.

        class MyProtectedView(...):
            __metaclass__ = DecoratedDispatchMethod(login_required)
            ...
    """
    class CBVMetaclass(type):
        def __init__(cls, name, bases, attrs):
            type.__init__(cls, name, bases, attrs)
            cls.dispatch = method_decorator(actual_decorator)(cls.dispatch)
    return CBVMetaclass

View comments View full post

Down with 9 to 5

Posted by Peter Baumgartner on January 23, 2012. Filed under business

Development is a creative endeavor. Often developers are creating something where there was once nothing. For most us, the thought of being productive for 8 consecutive hours 5 days a week is laughable. 2–3 hours on a single problem is enough to turn most people’s brains to mush.

As a company, we understand this and have abolished the 9 to 5 work week. People work where and when they feel they’ll be at their best. We don’t require people to be working during business hours. In case of urgent issues, we can call people on the phone, but in practice, that rarely happens. To many traditional companies, this sounds like anarchy. Surprisingly, it isn’t. We still collaborate (usually some combination of IRC, Skype, and Ginger), we still discuss problems as a team, and we can still pair program.

If you’re wondering how we make ...

View comments View full post

Introducing Ginger

Posted by Peter Baumgartner on January 13, 2012. Filed under ginger

Ginger

Our team of 10 is distributed across 8 countries and 3 continents. We have no central office. When we first started, a couple years might go by without ever meeting in person, now we meet in person for at least a week each year. Even if it weren’t for the massive timezone differences making business meetings a challenge, we’d still hate them. Our weekly “state of affairs” calls were at best boring and at worst, a disruptive waste of time.

We rely on the internet to bridge the physical gaps between us. Over the last five years, we’ve tried just about every piece of software out there.

Skype and IRC/Campfire/HipChat/IM are great, but they require everyone to be online at the same time otherwise the conversations just blow past them while they’re sleeping or working.

Basecamp messages are only a small step above ...

View comments View full post

Detecting File Moves & Renames with Rsync

Posted by Vláďa Macek on January 6, 2012. Filed under pro tip, sysadmin

Without patching, the rsync utility lacks support to detect when a file was renamed/moved across multiple directories inside the synced tree. There is a --fuzzy option to save bandwidth by building upon similar files on the target side, but only in the same directory.

You may need to synchronize the large file tree over a slow connection when you’ve done a big reorganization since the last rsync run. A real world example: Joe stores multiple GiBs of family photos and videos at home and periodically backs them up to a remote server.

$ rsync -avHP --delete-after ~/family/Photos remotebox:backups

One day, Joe decides he used the wrong directory layout or the file naming scheme and shuffles these gigabytes under a totally different directory structure, a quick local operation.

Unfortunately, there is no apparent safe and quick way to mirror these changes to the remote backup disk without either ...

View comments View full post