Skip to content

Instantly share code, notes, and snippets.

@khoahuynhdev
khoahuynhdev / PostgreSQL-EXTENSIONs.md
Created September 4, 2023 03:13 — forked from joelonsql/PostgreSQL-EXTENSIONs.md
1000+ PostgreSQL EXTENSIONs

🗺🐘 1000+ PostgreSQL EXTENSIONs

This is a list of URLs to PostgreSQL EXTENSION repos, listed in alphabetical order of parent repo, with active forks listed under each parent.

⭐️ >= 10 stars
⭐️⭐️ >= 100 stars
⭐️⭐️⭐️ >= 1000 stars
Numbers of stars might not be up-to-date.

@khoahuynhdev
khoahuynhdev / README.md
Created May 23, 2023 15:17 — forked from nymous/README.md
Logging setup for FastAPI, Uvicorn and Structlog (with Datadog integration)

Logging setup for FastAPI

This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.

Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!

Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly). All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented. This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog. You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom

@khoahuynhdev
khoahuynhdev / gist:974282a5e06254977d7079ef94e8b323
Created March 20, 2023 06:38 — forked from dobesv/gist:4f76a2095a3aa8bc20eda6b3a8e455b3
Example of a kubernetes cron job that dumps a postgres database and copies it to s3
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: postgres-backup
spec:
schedule: "0 12 * * *"
jobTemplate:
spec:
backoffLimit: 0
template:
@khoahuynhdev
khoahuynhdev / main_test.go
Created February 10, 2022 09:55 — forked from alexedwards/main_test.go
MaxOpenConns benchmark
package main
import (
"database/sql"
"testing"
"time"
_ "github.com/lib/pq"
)
Go 19 hrs 25 mins ██████████████▏░░░░░░ 67.3%
Bash 2 hrs 53 mins ██░░░░░░░░░░░░░░░░░░░ 10.0%
JSON 2 hrs 16 mins █▋░░░░░░░░░░░░░░░░░░░ 7.9%
JavaScript 1 hr 52 mins █▎░░░░░░░░░░░░░░░░░░░ 6.5%
Makefile 1 hr 37 mins █▏░░░░░░░░░░░░░░░░░░░ 5.6%
@khoahuynhdev
khoahuynhdev / nginx-tuning.md
Created October 3, 2021 10:47 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@khoahuynhdev
khoahuynhdev / dotvimrc
Last active December 10, 2021 03:25
minimal vim config for server monitoring
" Maintainer: Khoa <khoa.hd96@gmail.com>
" We want the latest vim settings/options, it must be first because it changes other options as a side effect
set nocompatible
" Vim plug settings ------------------- {{{
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $HOME/.vimrc

1. Separation of immutable and mutable logic

Quite a lot of different people have been on the same trail of thought. Gary Bernhardt's formulation of a "functional core, imperative shell" seems to be the most voiced.

"Boundaries" - Gary Bernhardt

"Imperative shell" that wraps and uses your "functional core".. The result of this is that the shell has fewer paths, but more dependencies. The core contains no dependencies, but encapsulates the different logic paths. So we’re encapsulating dependencies on one side, and business logic on the other side. Or put another way, the way to figure out the separation is by doing as much as you can without mutation, and then encapsulating the mutation separately. Functional core — Many fast unit tests. Imperative shell — Few integration tests

https://www.youtube.com/watch?v=yTkzNHF6rMs

@khoahuynhdev
khoahuynhdev / corona.vim
Last active March 30, 2020 13:17
Check corona update in Vim
function! s:corona_stats() abort
let l:lines = []
let l:keys = [
\ ['country', 'Quốc gia'],
\ ['cases', 'Số ca'],
\ ['todayCases', 'Số ca (hôm nay)'],
\ ['deaths', 'Tử vong'],
\ ['todayDeaths', 'Tử vong (hôm nay)'],
\ ['recovered', 'Hồi phục'],
\]
@khoahuynhdev
khoahuynhdev / rm_mysql.md
Created June 12, 2019 04:32 — forked from vitorbritto/rm_mysql.md
Remove MySQL completely from Mac OSX

Remove MySQL completely

  1. Open the Terminal

  2. Use mysqldump to backup your databases

  3. Check for MySQL processes with: ps -ax | grep mysql

  4. Stop and kill any MySQL processes

  5. Analyze MySQL on HomeBrew:

brew remove mysql