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

    July 12, 2023
    TIL

    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
    TIL

    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
    TIL

    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
    TIL

    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…

  • Types or Interfaces

    May 02, 2021
    Blog

    Types in TypeScript can be defined by both type and Interface aliases. They have many similarities and in many cases, they can be used interchangeably. But engineers like conventions and rules, which one should we stick to? Before digging into why you might want to use one or other, let's quickly discuss the difference between type and interface. Most of the time, an object type can be similarly…

  • Xstate

    April 04, 2021
    Blog

    #Transitions A state transition defines what the next state is, given the current state and event. State transitions are defined on state nodes, in the on property

Github: crabdul / LinkedIn

2023