Monday, January 13, 2020

Django - ChoiceField Display Text

I made a repo to demonstrate how to get a django ChoiceField's current selection's display text: https://github.com/pawl/django_choicefield_display_example/

I came across a few other examples, but they didn't do a good job of displaying the initial value or handling choices with integer values.

Friday, December 20, 2019

Python - Pipenv to pip-tools

I've been using Pipenv for the last few months and my biggest issue is that "--keep-outdated" has been broken in the latest release (2018.11.26) for a while. I've needed to install Pipenv from the master branch to make it functional. However, the last time I used "--keep-outdated" from the master branch, it wouldn't automatically update the hash of the dependency being updated.

Updating specific requirements is something I need to do pretty often, and it's not fun to explain all the Pipenv quirks to the team.

Pip-tools looks like it does everything I need and has fewer quirks, so I ended up making the switch.

Pipenv uses pip-tools under the hood, so the migration to pip-tools was very smooth. The migration process was:
  1. Copy the dev-packages and packages sections of the Pipfile to their own requirements.in files.
  2. Run pip-compile
  3. Copy over the specific versions and hashes from the Pipfile.lock to the generated requirements.txt. 
I did have a small issue where updating a specific package with pip-tools removed a bunch of dependencies from the requirements.txt unexpectedly, but running pip-compile with "--rebuild" fixed it.

Wednesday, July 24, 2019

HTML5 - video playsinline

I added "autoplay muted" to my <video> tag to make a video autoplay in a carousel. It worked on desktop Chrome or Firefox, but didn't work on iOS Chrome or Safari.

I learned about the "playsinline" fix from here: https://webkit.org/blog/6784/new-video-policies-for-ios/

Adding "playsinline" to my video tag fixed it.

Thursday, July 11, 2019

ESP32 Plant Sensor

I set up a ESP32 houseplant soil water + temperature + humidity + light sensor that sends me a daily status update message.






Wednesday, July 10, 2019

AWS - redirecting domain to url using a 302 redirect (without running a server)

I wanted to make a domain name (heckingoodboys.com) redirect to a multisubreddit for dog pictures, but I didn't want to run a web server for it.

Here's what I did:
  1. Purchase the domain using Route53.
  2. Create two public s3 buckets (www.heckingoodboys.com and heckingoodboys.com)
  3. Enable "Static website hosting" on www.heckingoodboys.com and redirect to heckingoodboys.com.
  4. Enable "Static website hosting" on heckingoodboys.com, select "use this bucket to host this website", and use routing rules similar to this:
    <RoutingRules>
      <RoutingRule>
        <Redirect>
          <Protocol>https</Protocol>
          <HostName>www.reddit.com</HostName>
          <HttpRedirectCode>302</HttpRedirectCode>
          <ReplaceKeyPrefixWith>user/heckingoodboys/m/heckingoodboys/</ReplaceKeyPrefixWith>
        </Redirect>
      </RoutingRule>
    </RoutingRules>
  5. Back to Route53 - Create an A record for both www.heckingoodboys.com and heckingoodboys.com using the alias to their respective buckets. (this will be the first option in autocomplete)
For more details: https://medium.com/@P_Lessing/single-page-apps-on-aws-part-1-hosting-a-website-on-s3-3c9871f126

Why not just use a CNAME from www.heckingoodboys.com to heckingoodboys.com? AWS says they don't charge for aliases, but they do charge for CNAMEs. So, I used an alias to a bucket instead.