Skip to content

Instantly share code, notes, and snippets.

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

Dong Nguyen ndaidong

🏠
Working from home
View GitHub Profile
@ndaidong
ndaidong / EventEmitter.js
Created October 27, 2022 09:10
Minimal event emitter for web
// EventEmitter.js
export class EventEmitter {
constructor () {
this._events = Object.create(null)
}
// add event listener
on (name, handle) {
const handlers = this._events[name] || []
@ndaidong
ndaidong / install-deno.sh
Created April 23, 2021 11:07
Install Go, Node, Deno on Endeavour, Debian, Fedora
#!/bin/bash
export DENO_VERSION=1.9.0
export DENO_DOWNLOAD_URL=https://github.com/denoland/deno/releases/download/v$DENO_VERSION/deno-x86_64-unknown-linux-gnu.zip
export DENO_INSTALL=/opt/deno
export PATH=$DENO_INSTALL/bin:$PATH
sudo mkdir $DENO_INSTALL
sudo chown -R ${USER} $DENO_INSTALL
@ndaidong
ndaidong / sslcheck.py
Created April 23, 2021 10:54
Check SSL certificate expiration with Python
#!/usr/bin/env python3
import ssl
import OpenSSL # pip install pyopenssl
from datetime import datetime
def get_cert_expiration(domain):
cert = ssl.get_server_certificate((domain, 443))
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
2021/04/20 00:05:32 ...c/net/http/server.go:3139:logf() [I] http: superfluous response.WriteHeader call from code.gitea.io/gitea/modules/context.(*Response).WriteHeader (response.go:64)
2021/04/20 00:05:32 ...c/net/http/server.go:3139:logf() [I] http: superfluous response.WriteHeader call from code.gitea.io/gitea/modules/context.(*Response).WriteHeader (response.go:64)
2021/04/20 00:05:32 ...c/net/http/server.go:3139:logf() [I] http: superfluous response.WriteHeader call from code.gitea.io/gitea/modules/context.(*Response).WriteHeader (response.go:64)
2021/04/20 00:05:32 ...c/net/http/server.go:3139:logf() [I] http: superfluous response.WriteHeader call from code.gitea.io/gitea/modules/context.(*Response).WriteHeader (response.go:64)
2021/04/20 00:05:32 ...c/net/http/server.go:3139:logf() [I] http: superfluous response.WriteHeader call from code.gitea.io/gitea/modules/context.(*Response).WriteHeader (response.go:64)
2021/04/20 00:05:32 ...c/net/http/server.go:3139:logf() [I] http: superfluous response.WriteHe
@ndaidong
ndaidong / simple-git-branching-model.md
Created April 6, 2020 07:56 — forked from jbenet/simple-git-branching-model.md
a simple git branching model

a simple git branching model (written in 2013)

This is a very simple git workflow. It (and variants) is in use by many people. I settled on it after using it very effectively at Athena. GitHub does something similar; Zach Holman mentioned it in this talk.

Update: Woah, thanks for all the attention. Didn't expect this simple rant to get popular.

@ndaidong
ndaidong / ip_count_from_netmask.py
Last active October 8, 2019 03:49
Counting number of IP belongs to a subnetmask
#!/usr/bin/env python3
from functools import reduce
from collections import Counter
def ip_count(netmask):
tmp = list(map(lambda x: bin(int(x)), netmask.split('.')))
arr = list(reduce(lambda x, y: x + y, tmp))
counter = Counter(arr)
return counter['1']
@ndaidong
ndaidong / install-go.sh
Last active June 1, 2021 21:34
Install Go on Endeavour, Debian, Fedora
#!/bin/bash
export GO_VERSION=1.16.3
export GO_DOWNLOAD_URL=https://storage.googleapis.com/golang/go$GO_VERSION.linux-amd64.tar.gz
export GOROOT=/opt/go
export GOPATH=$GOROOT/packages
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
sudo mkdir $GOROOT
@ndaidong
ndaidong / install-node.sh
Last active April 23, 2021 10:58
Install Node.js on Endeavour, Debian, Fedora without building
#!/bin/bash
export NODE_VERSION=14.16.1
export NODE_DOWNLOAD_URL=https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz
export NODE_INSTALL=/opt/node
export PATH=$NODE_INSTALL/bin:$PATH
sudo mkdir $NODE_INSTALL
sudo chown -R ${USER} $NODE_INSTALL