Skip to content

Instantly share code, notes, and snippets.

@piihuynh
piihuynh / install-mariadb-10.6.sh
Last active January 10, 2022 09:09
Install MariaDB 10.6 programmatically on Ubuntu
#!/bin/sh -e
# Credit: https://gist.github.com/coderua/5592d95970038944d099, https://gist.github.com/Mins/4602864
# Usages:
# wget -O - https://gist.githubusercontent.com/piihuynh/xxx/raw/xxx/install-mariadb-10.6.sh | bash -s newpassword
# bash -c "$(wget -qO - 'https://gist.githubusercontent.com/piihuynh/xxx/raw/xxx/install-mariadb-10.6.sh')" '' newpassword
# Check the bash shell script is being run by root
if [[ $EUID -ne 0 ]]; then
@piihuynh
piihuynh / add-user-on-ubuntu.sh
Last active January 10, 2022 05:04
Add user with a generated pem on Ubuntu
#!/bin/sh -e
# Usages:
# wget -O - https://gist.githubusercontent.com/piihuynh/xxx/raw/yyy/add-user-on-ubuntu.sh | bash -s username
# bash -c "$(wget -qO - 'https://gist.githubusercontent.com/piihuynh/xxx/raw/587yyy/add-user-on-ubuntu.sh')" '' username
[ $EUID -ne 0 ] && echo "This script must be run as root" 1>&2 && exit 1
[ -z "$1" ] && echo "Please provide a username in 1st param" && exit 1
# Define username from param
@piihuynh
piihuynh / sane-caching.nginx.conf
Created December 6, 2021 15:29 — forked from philipstanislaus/sane-caching.nginx.conf
Sample Nginx config with sane caching settings for modern web development
# Sample Nginx config with sane caching settings for modern web development
#
# Motivation:
# Modern web development often happens with developer tools open, e. g. the Chrome Dev Tools.
# These tools automatically deactivate all sorts of caching for you, so you always have a fresh
# and juicy version of your assets available.
# At some point, however, you want to show your work to testers, your boss or your client.
# After you implemented and deployed their feedback, they reload the testing page – and report
# the exact same issues as before! What happened? Of course, they did not have developer tools
# open, and of course, they did not empty their caches before navigating to your site.
@piihuynh
piihuynh / portainer.yml
Last active November 25, 2021 14:33
Portainer-CE swarm mode with Traefik
version: '3.2'
services:
agent:
image: portainer/agent:2.9.2
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/lib/docker/volumes:/var/lib/docker/volumes
environment:
AGENT_CLUSTER_ADDR: tasks.agent
@piihuynh
piihuynh / traefik-host.yml
Last active January 4, 2022 08:47
Traefik v2.5 Swarm mode with "host" mode
version: '3.7'
services:
traefik:
# Use the latest Traefik image
image: traefik:v2.5
ports:
# Listen on port 80, default for HTTP, necessary to redirect to HTTPS
- target: 80
@piihuynh
piihuynh / parse_dotenv.bash
Created August 26, 2021 22:49 — forked from judy2k/parse_dotenv.bash
Parse a .env (dotenv) file directly using BASH
# Pass the env-vars to MYCOMMAND
eval $(egrep -v '^#' .env | xargs) MYCOMMAND
# … or ...
# Export the vars in .env into your shell:
export $(egrep -v '^#' .env | xargs)
@piihuynh
piihuynh / jspdf-import-fonts.js
Last active February 23, 2021 09:30
Import Japanese fonts functions for jsPDF
This file has been truncated, but you can view the full file.
function importFontNotoSansCJKjpRegular(jsPdfDoc) {
if (!jsPdfDoc) return;
jsPdfDoc.addFileToVFS('NotoSansCJKjp-Regular.ttf','AAEAAAANAIAAAwBQRkZUTXas8jIADxLYAAAAHEdERUYAKRA8AA8SuAAAAB5PUy8ywjboQwAAAVgAAABWY21hcM+tTs8AACQgAABX2mdhc3D//wADAA8SsAAAAAhnbHlmHuJx0gAAvNgADVUsaGVhZAe8do4AAADcAAAANmhoZWEH2APCAAABFAAAACRobXR4AmrW+gAAAbAAACJubG9jYV+I4xgAAHv8AABA3G1heHAQjADLAAABOAAAACBuYW1li6KVSAAOEgQAAAGhcG9zdBcZx50ADhOoAAD/BQABAAAAAQAAF3dSEl8PPPUACwPoAAAAANJwmYAAAAAA0nCZgP/U/ukD6AO/AAAACAACAAEAAAAAAAEAAAO//ukAWgP2/9T/4QPoAAEAAAAAAAAAAAAAAAAAAAEBAAEAABA2AMgAFAAAAAAAAgAAAAEAAQAAAEAAAAAAAAAAAQHSAZAABQAAAooCvAAAAIwCigK8AAAB4AAxAQIAAAIABQMAAAAAAACAAAKDCAdo6AAAABAAAAAAUGZFZAAAACD/5QMg/zgAWgSIAUAAEgAEAAAAAAAAA+gAAAAAAAABTQAAAOAAAAFDAF8CKwAoAisAOgOZACcCqAAkARYAWgFSAFwBUgArAdMAQAIrACYBFgA1AVsALgEWAEkBiAALAisAMQIrAFgCKwAoAisAHQIrABQCKwAcAisAOAIrADECKwAtAisALAEWAEkBFgA1AisAJgIrACYCKwAmAdoAKwOyADgCXwADApEAZAJ+ADoCrwBkAkwAZAIoAGQCsQA6AtgAZAElAGQCGAAjAoYAZAIeAGQDLABkAtIAZALmADoCeABkAuYAOgJ7AGQCVQAvAlcAHwLRAGECPwABA24AGQI9ABECE
@piihuynh
piihuynh / .gitlab-ci.yml
Created February 22, 2021 07:02 — forked from superjose/.gitlab-ci.yml
This is an example of a .gitlab-ci.yml that is required for Continuous Integration on GitLab projects.
# Reference: https://www.exclamationlabs.com/blog/continuous-deployment-to-npm-using-gitlab-ci/
# GitLab uses docker in the background, so we need to specify the
# image versions. This is useful because we're freely to use
# multiple node versions to work with it. They come from the docker
# repo.
# Uses NodeJS V 9.4.0
image: node:9.4.0
# And to cache them as well.
# Ask for the user password
# Script only works if sudo caches the password for a few minutes
sudo true
# =============================
# Install docker
# -----------------------------
# Option 1
# -----------------------------
# Install kernel extra's to enable docker aufs support
@piihuynh
piihuynh / docker-cleanup
Created August 8, 2020 11:47 — forked from wdullaer/docker-cleanup
Cleanup unused Docker images and containers
#!/bin/sh
# Cleanup docker files: untagged containers and images.
#
# Use `docker-cleanup -n` for a dry run to see what would be deleted.
untagged_containers() {
# Print containers using untagged images: $1 is used with awk's print: 0=line, 1=column 1.
# NOTE: "[0-9a-f]{12}" does not work with GNU Awk 3.1.7 (RHEL6).
# Ref: https://github.com/blueyed/dotfiles/commit/a14f0b4b#commitcomment-6736470
docker ps -a | tail -n +2 | awk '$2 ~ "^[0-9a-f]+$" {print $'$1'}'