Latest Post
Substack's UI and 1Password just cost me $2,023
A quick guide on how to accidentally spend $2k in two clicks live on a client Zoom call.
What Saturday on Hacker News Looks Like
Yesterday, a post I had submitted to Hacker News got pushed up to the front page. Outside of retiring and basking in my new-found internet fame, I wanted to show what a few hours on the front-page looks like.
Home Made Standing Desk Raspberry Pi Controller
One of my lockdown projects was to make my sit/stand controller smart. I used a Raspberry Pi to create a custom controller that could control the motor on my desk and allow me to rise and lower it over the network as well as via a touch-interface.
Django Pagedown Image Uploads
It only took 5 years. After years of dithering you can upload images with Django Pagedown.
Django and CircleCI 2.0
Most of the time, deployment sucks. Using a continuous integration app can help automate your deployments so you can focus on writing code and buildings things. In this post I'll show you how to set up a basic Django project with CircleCI so that publishing your code is as simple as pushing to GitHub.
Ember Ajax and Ember Simple Auth
It can be tricky to properly configure
ember-ajax
to play nicely withember-simple-auth
. You will need to manually configure a service to mimic the authorisation functionality you get for free when using Ember Simple Auth with Ember Data. This post will show you how to get up and running properly.Sending Ember actions down to components
/"Data down, actions up/" is an often repeated mantra of the Ember community, and for good reason. Sometimes though, you need to call actions on components in a "downward" direction. In this post I'll give you an approach for breaking this DDAU rule.
'Route variable' pattern with Ember
There are a couple of different libraries for Ember that add the ability to set the page title for each page in your application by simply creating a
title
property on each route. This is a great general purpose pattern for declarative information that needs to be set across routes. For example you might want to add breadcrumbs, or just a different heading on each page. This post will outline how to go about creating this pattern yourself.A simple pagination component with Ember
Ember's ethos of 'components everywhere' makes it really quick and easy to make reuseable widgets. This takes the tedium out of implementing some of the more basic features of web sites and applications. An example of this is pagination. This post shows you how to create a very basic pagination component that allows you to page through a list of items.
Making a draggable Ember component
HTML5 makes it really easy to create elements that can be both dragged and dropped. This is a really powerful API to add rich functionality to your application. In this post we'll use this API to make a simple Ember component that can be repositioned on the screen by dragging it with the mouse.
Making USB Push Buttons
Using a 'Teensy' microcontroller/USB HID you can easily create physical push buttons for your project that, when pressed, will appear as key strokes in your application. This is a really flexible approach to adding physical buttons to an array of different web, desktop or even mobile applications. This post will show you how to do it.
Twitter controlled power switches with a Raspberry Pis
Using off-the-shelf parts with a Raspberry Pi, you can make a remote controlled power switch to turn appliances on/off. I've used this approach to create Twitter controlled snowblowers, remote controlled car headlights, a Twitter activated Christmas trees ... the possibilities are endless. This post will show you how to set up a power switch that will activate when a certain hashtag is posted to Twitter.
Adding labels to Ember Leaflet markers
This post shows you how to create a custom marker component that integrates the Leaflet.label add-on to get nice pop-up labels on your ember-leaflet maps.
Django access mixin for active users only
As of Django 1.9, there are a number of new permission mixins you can use with your views to make access control easier. One that isn't included by default is a mixin allowing you to only permit users who have activated their account (
user.is_active = True
)Updating your cert_fingerprint for offlineimap with Fastmail.fm
Fastmail recently updated their SSL certificate, breaking my offlineimap email backups. This post has the updated cert_fingerprint value you need to add to get it back running
The Missing Manager for Django Models with GFK Relationships
Save yourself writing the same queries time and time again by creating a simple model manager with common queries for your generic foreign keys
Importing Big Databases with MAMP & phpMyAdmin on OSX
When you are using phpMyadmin on MAMP or MAMP Pro out of the box, you might run into trouble trying to import large databases due to PHP's default upload and timeout settings. This post explains the quick-fix needed to get it working.
Uploading and validating an image from an URL with Django
This post outlines a simple Django app that allows the user to upload an image via an URL while making sure the image file is valid.
Understanding, setting up, accessing and serving media files and static files in Django
One of my most popular Stackoverflow answers is to a question regarding the confusion between static and media files in Django. This post elaborates on that theme.
An Updated General Django Project Structure or Folder Layout
In a previous post I outlined a sane folder structure for a new Django project. Since then Django 1.5 (and 1.6) has been released along with an updated default folder structure. This post goes through some further tips on keeping your django project layout sensible.
Autodeploy Jekyll using bitbucket post-commit service hooks and Flask
A very nice and clean way to deploy a Jekyll (or any other static generated site) is to setup a very small application on your sites webserver to listen for post commit hooks from Bitbucket. This allows you to have your site automatically updated and regenerated every time you push to your repository. This post shows you how.
SuspiciousOperation Invalid HTTP_HOST header with Django
I was recently getting this error while trying to deploy a new project to production. It turns out that due to a recent security update, you need to make sure that the incoming host name in your request is valid.
A Custom Cropping Engine With sorl-thumbnail
Sorl-thumbnail has a sensible crop function in the default engine, but sometimes you need a little more control over the results. This post provides a custom cropping PIL engine that can be used to return specific, i.e. from (x1, y1) to (x2, y2), cropped thumbnails
Using Django's request after updating POST or GET attributes
If you update
request.POST
orrequest.GET
in a view (or else where), any subsequent calls torequest.REQUEST
will still return values from the old, outdatedGET
andPOST
dictionaries.Automatically generating admin URLs for your objects
It's very easy to generate URLs to your django models using get_absolute_url(), but you can also use this pattern to just as easily create URLs to the admin page for your django models too. This post shows you how to make a get_admin_url() model method that generates links to give you quick access to your admin.
Reversing a unique Generic Foreign Key with Django
When using GenericRelations with Django to create unique generic foreign keys between objects, it can become tiresome having to navigate the RelatedManager every time you need to retrieve the single instance of the one-to-one relationship. This post shows how creating a quick
Mixin
can help overcome this inconvenience.Filtering on annotations in Django
Django's annotate method can be useful for counting particular attributes on every member of a queryset (i.e. count the number of books an author has). Unfortunately you can't use the ORM to do any filtering on those attribute. This would be useful for only considering an attribute if it were above a certain value, or belonged to a certain object (i.e. count the number of books with the tag 'Horror'). This post shows how to make use of the
extra
method Django provides to create filtered annotationsMiddleware to ensure Facebook Auth on all views with Fandjango
Fandjango is a great application for getting a Facebook Canvas application up and running. It provides a nice view decorator to ensure a user is authorised with Facebook before allowing them access to that view. This post provides a piece of middleware that makes use of that decorator, allowing you to enforce Facebook authorisation on all views in your application.
A General Django Project Structure or Folder Layout
When beginning with Django I always found it difficult to decide on basic project layouts. What should go where and why? Having read many of the great articles on the topic already out there this post outlines how I have come to manage the folder structure of most of my new Django projects, making sure everything is tidy and safe
Create automatic redirects upon changing an URL dependent field in your Django Models
When the generated URLs of your objects depends on a field in your model that could potentially change (for example a slug field that is generated from a title which your editor just changed), you can get yourself into trouble with Google as your old URL will now return a 404. This posts outlines an approach to dynamically create redirects whenever an objects changes an url dependant field.
Don't keep sensitive information in your Django settings
If you are checking your settings.py into Git, make sure you aren't including any potentially sensitive information such as database passwords, secret keys and so on. A quick and easy way to avoid this is to create a separate
sensitive.py
file.Misconceptions with "select_related" in Django
Django's select_related QuerySet method is a great way to reduce the query count when joining tables but it should come with small print in the documentation. This post goes over that small print.
Using sorl thumbnail and easy thumbnails in the same template
At times you need to use both sorl.thumbnail and easy_thumbnails in the same template. Both of these apps define a thumbnail template tag from a thumbnail template module meaning that you will be able to use one or the other but not both. To get around this, you can install a great app called django-smart-load-tag
Using a virtualenv with CodeRunner.app
I'm a big fan of using Virtualenv (and virtualenvwrapper) where possible. It allows you to cleanly manage multiple Python environments. I also occasionally use CodeRunner to test, debug and run standalone scripts. It wasn't immediately clear to me how to make CodeRunner run inside one of my virtualenvs so this post gives a quick outline on how to get the two to work nicely together.
Django CMS Urls not reversing properly
I encountered a strange problem when making use of a custom AppHook with django-cms. When I mounted a custom app on a cms page, reversing the urls in the template for that app (using get_absolute_url) was producing incorrect urls.