crabdul.com
BlogTIL
About
  • abc.Sequence vs. abc.Iterable

    July 12, 2023

    When needing to get the len() of an input, use Sequence. Iterable allows the caller to pass in an endless sequenece generator rather than a pre-built sequence. Most importantly, Sequence and Iterable are best used as a parameter types. There are too vague as a return type. A function should be more precise about the concrete type it returns.

  • Transactionally staged job drains

    July 11, 2023

    Queuing celery tasks on commit runs the risk of them not being queued properly if the program crashes after the transaction commits and before the task is queued. The solution is to use a transactionally staged job drain as outlined in this article. With this pattern, jobs aren’t immediately sent to the job queue. Instead, they’re staged in a table within the relational database itself, and the…

  • Check whether a file or path exists

    July 11, 2023

    Using the EAFP (Easier to Ask Forgiveness than Permission) principle, we can check whether a file or path exists by attempting to open it and catching the exception if it doesn't exist. This will also avoid race-conditions if another proces deleted the file between the check and when it is used.

  • NAT Instances for your hobby project

    May 09, 2021

    AWS NAT Gateways are bloody expensive (for a hobby project that is). My bill for last month was over 40 squid due to just the NAT Gateway. I ended up replacing the NAT Gateway in my project with a NAT instance uisng this terraform module. It advises users not to use it in a production environment but my servers in the private subnets don't need outbound internet connectivity all the time. My RDS…

Github: crabdul / LinkedIn

2023