Flask or Django? Which to Choose for your Project

🔖 code  django  flask  python 

Often I get asked by fellow python developers why I chose Django/Flask for a particular project (usually by someone who prefers the framework I didn’t choose 😉). I think both frameworks are excellent and are well suited for a variety of use cases.

So how do I decide which to use for a new project? I found a simple heuristic to get 90% of the way to a final decision, and it’s pretty easy to follow:

Read more...

Essential Django Apps for Every Project

🔖 code  django  python 

Django projects have the ability to install apps, which are analogous to plugins in other frameworks.

Some of these apps provide simple functionality: django-gravatar installs a template tag for displaying a user’s gravatar in a template. Other apps are large, like Mezzanine which provides an entire CMS framework to your project.

No matter what you are building, you should consider the following apps. I use them in almost all of my projects.

Read more...

Redefining Productivity

🔖 life 

After nearly 5 years I’ve left my position at Las Cumbres Observatory. During my time there I got to work with scientists on interesting problems in Astronomy. I wrote a lot of code, most of it open source. Without going into too much detail, it was most everything I wanted in a job and probably the best one I’ve ever had.

I can go into details about why I left and my thoughts on full-time vs part-time employment in another post.

For now I’d like to start the new month, and my new “career” by laying out some goals and how I’d like to achieve them. This is for my own benefit: a soft of self evaluation to nobody in particular except myself.

Read more...

Does Strava Encourage Illegal Trail Riding?

🔖 cycling 

I recently received the following email in my Trail Care inbox (names and locations removed):

Hi, I am a long time mtb rider. I am also on the Board of Directors for the local open space advocacy/trails stewardship group. The actual owner of the surrounding open space is the county. Like other areas, we have a ton illegal trails. Many of the authorities see Strava as a negative in that riders publicly post their illegal trail rides which leads others to follow. There is also the perception that Strava motivates riders to break speed limits to get KOMs. Have you run into this anywhere else and how do you get around this?

This is a controversial subject within the mountain biking community, especially within the advocacy circles. Pretty much everyone has an opinion about Strava. Some people love it, some hate it, any everyone has their theories.

Read more...

Reliable California Wildfire Information

🔖 other 

November is wildfire season in California, and this year has been no exception. Just when we thought it couldn’t get worse than 2017 / 2018, it did.

Unfortunately it can be super hard to get good information about wildfires while they are happening. This is mainly due to every local news station eagerly exploiting tragedy for readership. Googling a fire returns pages of poorly and hastily written articles that contain, at best, out of date information (but plenty of shocking cell phone video) and at worst no information at all.

Read more...

Simple Virtualenv Auto Activation With ZSH.

🔖 linux 

Since I moved from fish to zsh, one of the main things I missed was virtualfish. I’m not sure how any serious python developer lives without auto activation, as in automatically activating the virtualenv for your project when you open a terminal or cd to it.

Here is a script you can use to achieve auto activation. It doesn’t require virtualenvwrapper, pyenv, or anything like that. Just use python3’s built in python -m venv to create a virtualenv in ~/.virtualenvs/, use the provived venvconnect function to connect the activated env with the current directory, and you’re done.

#!/bin/zsh
#
# Auto activate a python virtualenv when entering the project directory.
# Installation:
#   source virtualenv-auto-activate.sh
#
# Usage:
#   Function `venvconnect`:
#       Connect the currently activated virtualenv to the current directory.
#
VENV_HOME=$HOME/.virtualenvs

function _virtualenv_auto_activate() {
    if [[ -f ".venv" ]]; then
        _VENV_PATH=$VENV_HOME/$(cat .venv)

        # Check to see if already activated to avoid redundant activating
        if [[ "$VIRTUAL_ENV" != $_VENV_PATH ]]; then
            source $_VENV_PATH/bin/activate
        fi
    fi
}

function venvconnect (){
    if [[ -n $VIRTUAL_ENV ]]; then
        echo $(basename $VIRTUAL_ENV) > .venv
    else
        echo "Activate a virtualenv first"
    fi
}

chpwd_functions+=(_virtualenv_auto_activate)
precmd_functions=(_virtualenv_auto_activate $precmd_functions)

Source the above script in your ~/.zshrc and you should get auto activation of python virtualenvs.