Author Archives: James Lin

DIY Bike Rack

When faced with the high cost of a $1500 bike rack, it’s time to get creative and make your own. I started this project late last year, and it has undergone a few design changes, particularly in how the bike is positioned. One challenge was figuring out how to keep the bike upright while also… Read More »

Use “get” methods to help writing more testable code

Imagine you have the following code def do_something(): users = User.objects.filter(dob__gte='1980-01-01') for user in users: # do something to user If you were writing unit test against do_something(), you would need to do some complex mocking on User.objects.filter() to return some mock up data. But this can be easily prevented by refactoring into a separate… Read More »

Minimal Django script setup

import os, sys, pathlib # if script is in on 1 level deep # sys.path.append(str(pathlib.Path(__file__).parents[1].absolute())) sys.path.append(str(pathlib.Path(__file__).absolute())) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings") import django django.setup() # import your django models # do your django work