Skip to content

Instantly share code, notes, and snippets.

View albscui's full-sized avatar

Albert Cui albscui

View GitHub Profile
@albscui
albscui / k8s_vs_docker_command_entrypoint.md
Created October 8, 2024 02:53
K8s command vs Docker ENTRYPOINT

K8s command vs Docker ENTRYPOINT

Summary

  • command in K8s is analogous to ENTRYPOINT in Docker
  • args in K8s is analogous CMD in Docker

In Docker:

CMD has three forms

@albscui
albscui / how-to-postgres-listener.md
Last active July 9, 2025 16:28
Postgres trigger and listener mechanism (Go)

How to listen to events in Postgres (with a bit of Go)

Postgres has built-in mechanism for notifying clients (listeners) of events such as INSERT, UPDATE, and DELETE on tables.

Note that for this to work, a listener must have a dedicated direct connection to Postgres. Connection poolers like pgbouncer would not work.

First, lets go over some key Postgres components:

  • triggers - automatically executes some function when an event on a table occurs
  • channels - a communication mechanism identified by a string in postgres
@albscui
albscui / go-testing.md
Last active August 21, 2025 23:08
How to test in Go

Testing code with dependencies in Go

A list of patterns for stubbing out dependencies in unit tests.

Pattern 1: Simple stub struct

Problem: We have a dependency that we don't want to actually run in our unit tests.

Define an interface that abstracts this dependency, and implement a stub struct that implements this interface, then swap this into your struct at test time.

@albscui
albscui / python_coroutine_example.py
Last active May 22, 2025 19:51
Concurrency with coroutines in Python
"""
Credit: https://youtu.be/MCs5OvhV9S4
Example concurrent server impelmented with coroutines not threads.
Main idea is to avoid being blocked by IO. Although we can achieve this with threads,
we want to use coroutines instead, because threads are expensive.
A coroutine is a function that yields control to the caller before a blocking call.
An event loop continuously polls for coroutines and runs them.
@albscui
albscui / linux-setup.sh
Last active April 18, 2023 23:09
Linux dev machine config
# First install requirements:
# zsh
# oh-my-zsh
# fzf
git clone --bare [email protected]:albscui/dotfiles.git $HOME/.dotfiles
alias dotfiles='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
dotfiles config status.showUntrackedFiles no
@albscui
albscui / gitflow.md
Last active September 28, 2017 04:07

GitHub Flow Tutorial vNoBS

Here is a high-level explanation of the GitHub branch-based workflow.

Below, are step by step instructions for implementing this workflow.

1. Create a branch

You can create branches either remotely or locally.