RSSAmplifier

Blog

Jeremy Satterfield

Coding, Making and Tulsa Life

jsatt.comRSS feed ↗21 posts

Latest posts

Resume

Full-stack engineer with over 19 years of experience building web applications and APIs primarily using Python and Django. Emphasis on high-quality, maintainable code and reliable, modern infrastructure. Proven leadership in designing systems architecture, mentoring teammates and delivering reliable software for complex business needs. Skills Languages & Frameworks: Python, Django, Django REST…

The Pains of MySQL Perfomance Under Docker

Over the course of the last several days I've been plagued with a couple pretty massive performance issues running MySQL under Docker(-compose) in our developer environments. Everyone in our office is running either a Mac or some flavor of Linux. In both cases I spent a couple of days search for a solution, running into several roadblocks, and exhausting many Google search terms. Since I had such…

Python Catalog Data Structures

I recently realized I have several open-source projects I'm a maintainer or owner of which I've never really discussed on this site or on social media. Some of these projects have been pretty specific and tied to the other projects I was working on at the time, but several do have the potential for wider general use. I figured now was a good time to start talking about some of these projects and…

Manage All the Languages Using Python Virtualenv

A couple of years ago I was working with a couple other languages beside Python and began to get frustrated with their virtualenv equivalents. Not that they were doing anything wrong, just that they didn't work the way I was used to with virtualenvs. On top of that, they didn't work well together. I wanted to see if I could get something working that used the workflow I was used to and managed all…

Securing Your Website with Let's Encrypt

This past week I gave a short presentation at the monthly TulsaWebDevs meeting about setting up a secure website using Let's Encrypt . I covered a brief (minimal) overview of how SSL/TLS works and a comparison in the processes of the traditional way to acquire an SSL certificate and acquiring a certificate via the ACME protocol. The slides are now up if you'd like to check them out over on my…

Securing Your Website With Let's Encrypt

Securing Your Website With Let's Encrypt Securing Your Website With Let's Encrypt (In Under 5 Minutes) Jeremy Satterfield http://jsatt.com https://github.com/jsatt @jsatt jsatt@jsatt.com Web developer for over 9 years. Worked for website measuring traffic in the millions/month currently working on internal software in oil industry Primer on Protocols HTTP SSL/TLS HTTPS HTTP/2 HTTP - Hypertext…

Unit Testing Recursion in Python

Today I finally figured out the solution to a problem I've been trying to solve for a while. It's kind of hacky and maybe a bad idea, but now I know it's possible. The problem has always been that I'd like to test that a function recurses, but not needing it to actually have the recursion execute within to test. Just a unit test to assert that recursion is happening. After a little thought about…

Keeping MRO In Mind When Mocking Inherited Methods

So I just spent a couple of hours banging my head on a ridiculous PyMox mocking issue and though I'd share. Here is an example of the existing code. # views.py class MyBaseView(BaseView): def get_stuff(self): # this is doing things class SpecificView(MyBaseView): example = True def send_stuff(self): stuff = self.get_stuff() # do other things # tests.py class SpecificViewTest(TestCase): def…

Mocking a property in Python

Anytime I see someone turning an instance method into a property on a Python object, I always have to step back and rethink whether it's really the right thing to do. While properties certain have valid use cases, I often see them overused and misused. This can result in code that is harder to refactor should you decide you actually do want to accept arguments as well as less straight forward to…

Class-based Celery Tasks

Update 2017-11-02: Celery 4 now adivises against inheriting from Task unless you are extending common functionality. However you can still get similar functionality by creating a new class and calling is from inside a decorated function task. class MyTask(object): def run(self, source): do_stuff() ... @app.task def my_task(source): MyTask().run(source) Original Post: Recently, I've had to write…

Mocking Python's built-in open function

A while back I was working on my podcast client and ran into an issue downloading large files. The root problem was that all of Django's FileField backends store the file (or file-like object) to memory then saves it to disk, and the cubieboard system I was using had limitied memry resources, resulting in "out of memory" errors. After much searching and hacking I finally settled on just storing…

Abusing Django Rest Framework Part 4: Object-level field exclusion

Similar to the object-level readonly field from my previous post , there are some cases where we want to exclude certain fields based on what object the user is trying to access. You could overwrite the views get_serializer method to use a different serializer based on their access, but if nesting serializers is a possiblility this get messy, somewhere in the neighborhood of O(n 2 ) . Another…

Abusing Django Rest Framework Part 3: Object-level read-only fields

DRF has tools to control access in a few ways. Serializers make it easy to select what fields can be accessed and whether or not they are read-only. Permissions are great for restricting access to objects at all or even making certain objects read-only. But there are also cases where you might only want to allow access to a field on a specific object but leave that field restricted on other…

Using Tox with Travis CI to Test Django Apps

Being a fan of good testing, I'm always trying to find ways to improve testing on various projects. Travis CI and Coveralls are really nice ways to set up continuous integration for your open-source projects. A couple months ago I finally started hearing grumblings about tox and how everyone was it using for their Python test automation. Every time I'd try to wrap my head around it, something…

Mocking Context Managers in Python

I've often found Python's context managers to be pretty useful. They make a nice interface that can handle starting and ending of temporary things for you, like opening and closing a file. For example: f = open('myfile.txt', 'w') try: for row in records: f.write(row) finally: f.close() can be replaced with with open('myfile.txt', 'w') as f: for row in records: f.write(row) This last week I was…

Abusing Django Rest Framework Part 2: Non-rate-based Throttling

Anyone running an API that can be reached by the outside world should most definitely be concerned that someone might pummel their server by making a massive amount of requests to that one endpoint that requires a bunch of on-the-fly calculations. Enter Django Rest Framework's throttling. It allows you to easily configure the framework to stop allowing requests from a user once they've made so…

About

I'm a web developer and homebrewer from Tulsa, OK with an affinity toward open-source. I work primarily in Python, Django, Javascript and and related languages such as CoffeeScript, CSS and Stylus. As a member of TulsaWebDevs , CodeforTulsa , and Civic Ninjas , I also work on many civic-minded projects.

Abusing Django Rest Framework Part 1: Non-Model Endpoints

When working with Django Rest Framwork a few months back, there were a few road blocks that we ran into. Rest Framwork is awesome with most models for providing a simple CRUD API, in any (or multiple) serializations, with authentication and permissions. Sometimes, however, things aren't so simple. Things get ugly. Framworks get abused. This is the first of a few posts looking at some of the ways…

Finding Un-mocked HTTP requests in Python tests with Nose

I'm a big fan of proper unit testing with mocking. So I'm pretty disappointed when we run across a unit that is not only not mocked properly, but results in real-world consequences outside the testing environment. One case we've run into couple of times now is tests that are making actual outbound HTTP requests to remote servers. Since clients don't necessarily like getting fake information posted…

Decorators vs Mixins for Django Class-Based Views

I've been huge fan of Django's class-based views (CBVs) since I first tried them out in Django 1.4. While they're much more complicated then the classic function based views, once you understand how they work, they're much more powerful, flexible and allow for DRYer code. I highly recommend anyone who hasn't delved into CBVs take a look at Class Class-based views or GoDjango . However, one of the…

Fresh start

This is going to be a fresh attempt to start blogging again on a regular basis. I plan to share development and brewing experiences, open-sourcing in both cases whenever possible.