Skip to content

Instantly share code, notes, and snippets.

View dongnguyenltqb's full-sized avatar
🏠
Working from home

Dong Nguyen dongnguyenltqb

🏠
Working from home
View GitHub Profile
@dongnguyenltqb
dongnguyenltqb / rust_state_pattern.rs
Created February 19, 2022 09:20
rust: state pattern
struct Draft {}
struct PendingReview {}
struct Published {}
struct Post {
state: Option<Box<dyn State>>,
content: String,
}
// self: Box<Self> "This syntax means the method is only valid when called on a Box holding the type."
trait State {
@dongnguyenltqb
dongnguyenltqb / Dockerfile
Created January 28, 2022 05:20
jenkins docker
FROM jenkins/jenkins:2.331-jdk11
USER root
RUN apt-get update && apt-get install -y lsb-release zip unzip
RUN curl -fsSLo /usr/share/keyrings/docker-archive-keyring.asc \
https://download.docker.com/linux/debian/gpg
RUN echo "deb [arch=$(dpkg --print-architecture) \
signed-by=/usr/share/keyrings/docker-archive-keyring.asc] \
https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list
RUN apt-get update && apt-get install -y docker-ce-cli

Local Development Techniques with Kubernetes

This talk is all live demos of tools developers can use in their inner-loop, at development time to be more productive with containers.

Start Easier

Docker Compose captures the build arguments and run arguments so we can focus on our coding.

@dongnguyenltqb
dongnguyenltqb / kafka-docker-compose.yml
Created January 13, 2022 10:43
kafka-docker-compose.yml
version: "2"
services:
zookeeper:
image: docker.io/bitnami/zookeeper:3.7
networks:
- kiko
ports:
- "2181:2181"
volumes:
@dongnguyenltqb
dongnguyenltqb / handle postgres json with gorm.go
Created December 27, 2021 04:03 — forked from jinzhu/main.go
handle postgres json with gorm
package main
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/lib/pq"
)
func main() {
@dongnguyenltqb
dongnguyenltqb / docker-compose.yml
Last active December 20, 2021 06:14
gitlab-ce-docker
web:
image: 'gitlab/gitlab-ce:latest'
restart: always
hostname: 'git.dongnguyen.dev'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'https://git.dongnguyen.dev'
nginx['listen_port'] = 80
nginx['listen_https'] = false
gitlab_rails['gitlab_shell_ssh_port'] = 24
@dongnguyenltqb
dongnguyenltqb / ssh_tunnel.service
Last active December 14, 2021 04:16
setup an secure tunnel via ssh
[Unit]
Description=Setup a secure tunnel
After=network.target
[Service]
ExecStart=/usr/bin/ssh -NT -v -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -i /home/dong/key.pem -R 0.0.0.0:22:localhost:22 dong@dongnguyen.dev
# Remote Burst, restart to die
StartLimitBurst=500000
StartLimitIntervalSec=10000
@dongnguyenltqb
dongnguyenltqb / go build command
Created December 11, 2021 15:12
# Golang - Building Executables for Different Architectures
# Golang - Building Executables for Different Architectures
env GOOS=**target-OS** GOARCH=**target-architecture** go build **package-import-path**
```sh
# Example
env GOOS=darwin GOARCH=amd64 go build
env GOOS=darwin GOARCH=amd64 go build main.go
env GOOS=darwin GOARCH=amd64 go build github.com/zoo/york/foo/bar
@dongnguyenltqb
dongnguyenltqb / gist:9171a87d4fb78cd04447d5bdee5baf29
Created October 23, 2021 07:13
Performing UDP tunneling through an SSH connection
# Performing UDP tunneling through an SSH connection
------
## Intro
The Swiss ISP [Bluewin](http://www.bluewin.ch/) sucks. Their DNS are often down. A friend even received advice from Bluewin technicians to not use their own DNS!... But then, it is quite hard to gain access to another DNS for free, if you don't have access to a co hosted machine.
In this document, we'll access another machine's network internal DNS services (UDP port 53) with only SSH access to it. We will forward local UDP/53 traffic to TCP, then TCP traffic with the port-forwarding mechanism of SSH to the other machine, then TCP to UDP/53 on the other end. Typically, you can do it with [openvpn](http://openvpn.net/). But here, we'll do it with simpler tools, only [openssh](http://www.openssh.com/) and [netcat](http://m.nu/program/util/netcat/netcat.html).
@dongnguyenltqb
dongnguyenltqb / pg-try-advisory-xact-lock.js
Last active July 26, 2021 10:34
pg try advisory xact lock with retry
const { Pool } = require("pg");
const connectionString = process.env.db_uri || "postgres://localhost:5432/postgres";
const pool = new Pool({ connectionString });
function Locker(key, timeout, retryCount) {
this.key = key;
this.timeout = timeout || 200;
this.retryCount = retryCount || 5;
this.getClient = getClient;
this.aquireLock = aquireLock;