Arduino - Oven Thermometer
Parts:
- HiLetgo DC 3-5V MAX6675 Module + K Type Thermocouple Temperature Sensor
- UCTRONICS 0.96 Inch OLED Module 12864 128x64 Yellow Blue SSD1306 Driver I2C
- ESP32
Code: https://gist.github.com/pawl/73a1ccfbf2b2be6f934e651b39c51082
Linux - Sparse Files
Found a massive faillog/lastlog file recently and thought it was responsible for using up all my disk space. Turns out it's actually a sparse file and doesn't take up that much physical space: https://unix.stackexchange.com/a/530157
Arduino - Coffee Roasting Monitor
Parts:
- Arduino Uno
- 2x MAX6675 w/ thermocouple
Code: https://gist.github.com/pawl/5ed1f61e0b0b27aa839fc2b4499a92c2
Django - Duplicate Unformatted Logs
Recently I worked on a bug that was causing duplicate unformatted log messages to appear in a Django app's logs. I made a repository that demonstrates the issue: https://github.com/pawl/django_duplicate_unformatted_logs_example
The problem was caused by an accidental call to logging.info
(without using logging.getLogger
to get a specific logger) while the root logger isn't already configured.
The solution ended up being to get rid of the accidental calls to logging.info
and configuring the root logger to prevent it from accidentally happening again. I go into more details in that repo.
Vue - vue-custom-element
Vue-custom-element seems like the best way to integrate vue into an existing application that uses server side templates.This approach allows you to use vue components (built with the build pipeline) in your existing html without making your entire application a SPA.
Initially I started following this guide: https://robinverton.de/blog/2018/06/22/django-vue.js-integration-as-a-widget/
Vue-custom-element turned that code into 3 lines and allowed using components like normal (without the data attributes).
This approach seems much better than: https://vsupalov.com/vue-js-in-django-template/ Which doesn't allow for using a build pipeline for babel, linting, testing, single page components, live reload, modules with import/require, etc.
Targeting your builds for web components might do the same thing: https://cli.vuejs.org/guide/build-targets.html#web-component It says it's not compatible with IE11, but that might not be a big deal in most situations.
Django - Requiring Prefetching
https://github.com/pawl/django_require_prefetch_select_related_exampleI made a repository to try to figure out the best way to require prefech_related/select_related when fetching a model's related objects. I also want to figure out a good pattern for avoiding duplicated prefetch_related/select_related for multiple places in a codebase that need the related objects eager loaded in the same way.
Nginx - WebDAV
Just learned Nginx has WebDAV support: https://nginx.org/en/docs/http/ngx_http_dav_module.htmlIt's a lot faster than the Python package I was using: https://github.com/mar10/wsgidav
Wsgidav is great though. It's super customizable and the documentation is great too.
Django - ModelChoiceField queryset caching
It would be nice to know a better way to cache the ModelChoiceField’s queryset when it’s used in a form that runs “is_valid()” in a loop (like Formsets do). The best way I know how at the moment is by not using a ModelChoiceField at all. The solution requires using a ChoiceField, running the query for choices outside of the loop, then passing the choices into the form to override the ChoiceField choices.
Here’s an example:
Django API Forms
Just found a really cool library for using Django's built-in forms to validate JSON: https://github.com/Sibyx/django_api_formsI made a small example with it to show how it works with ModelChoiceFields: https://github.com/pawl/django_api_forms_modelchoicefield_example
Seems like a more lightweight version of DRF's serializers (but only for deserializing and validating) and with a similar API to Django's built-in forms.