Skip to content

Instantly share code, notes, and snippets.

View runlevel5's full-sized avatar

Trung Lê runlevel5

View GitHub Profile
@runlevel5
runlevel5 / nginx_njs_environment_variables.md
Last active February 28, 2024 09:17
Using njs to fetch environment variables

There are many ways to parse in variable into the nginx config file. Some uses set_by_lua which is offered by lua-nginx-module. Some use envstubst to populate varilabes into a template file.

Today I am going to show you how to do that with njs the JS scripting engine for nginx.

## /etc/nginx/fetch_env.js
function fetch_upstream_host(r) {
 return process.env.UPSTREAM_HOST;
@runlevel5
runlevel5 / setup_containerd_for_k8s.sh
Last active January 11, 2024 05:06
Setup containerd for K8S on Alpine Linux
#!/bin/bash
set -e
## CRI containrd
## CNI flannel
# Alpine Edge only! Let's hope alpine 3.13 or 3.14 would have k8s in main tree
echo http://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories
echo http://dl-cdn.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories
@runlevel5
runlevel5 / uber_task.ex
Created April 10, 2016 23:49
A simple Elixir Port wrapper - it is kinda half way to Porcerlain
defmodule Uber.Task do
# this module takes advantage of `Task` to wrap around
# the Port process, it does extra processing in messages
# aggregation and waiting for exit_status message.
#
# example:
# cmd = "ls /"
# Uber.Task.run_async(cmd) |> Uber.Task.get_result()
#
def run_async(cmd) do
@runlevel5
runlevel5 / list_all_versions_grouped_by_package.bash
Last active November 22, 2022 22:50
Just a quick script to create a JSON of which key is the NPM package name and value is the array of all versions
#!/bin/bash
set -euo pipefail
PACKAGE="null"
packages_filepath="packages"
detailed_packages_filepath="detailed_packages"
username="shortlyster"
CLEANUP="false"
main() {
From ea8c5e8b91938abafd79da1ca79b4fdd9ae4635d Mon Sep 17 00:00:00 2001
From: Trung LE <8@tle.id.au>
Date: Mon, 21 Nov 2022 21:41:42 +1100
Subject: [PATCH] Update to version 0.25.0
---
.gitignore | 1 +
changelog | 3 +++
crossterm-fix-metadata.diff | 16 ++++++++++------
rust-crossterm.spec | 2 +-
@runlevel5
runlevel5 / fedora35-uuid-static-rpm.patch
Created November 17, 2022 06:33
This the patch to build RPM with static .a files
Date: Thu, 17 Nov 2022 17:10:48 +1100
Subject: [PATCH] Build static
---
uuid.spec | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/uuid.spec b/uuid.spec
index c99d307..8f39927 100644
--- a/uuid.spec
@runlevel5
runlevel5 / amdgpu_6600xt_kernel_6_1_0_rc3.txt
Created November 9, 2022 23:24
dmesg of amdgpu loaded up for AMD Radeon RX 6600 XT on Linux 6.1.0.rc3 ppc64le 64K pagesize
[ 0.000000] (thread shift is 2)
[ 0.000000] Allocated 3584 bytes for 32 pacas
[ 0.000000] -----------------------------------------------------
[ 0.000000] phys_mem_size = 0x1000000000
[ 0.000000] dcache_bsize = 0x80
[ 0.000000] icache_bsize = 0x80
[ 0.000000] cpu_features = 0x0001b8eb8f5fb187
[ 0.000000] possible = 0x000ffbfbcf5fb187
[ 0.000000] always = 0x0000000380008181
[ 0.000000] cpu_user_features = 0xdc0065c2 0xaef00000
@runlevel5
runlevel5 / amdgpu_6600xt.txt
Created November 8, 2022 08:37
Loading AMDGPU driver (Kernel 6.0.3 ppc64le 64K pagesize) for Radeon 6600 XT card on Raptor Blackbird POWER9 computer
$ uname -ar
Linux shrimp-paste 6.0.6-300.fc37.ppc64le #1 SMP Tue Nov 1 19:24:50 UTC 2022 ppc64le ppc64le ppc64le GNU/Linux
$ lspci | grep ATI
0000:01:00.0 PCI bridge: Advanced Micro Devices, Inc. [AMD/ATI] Navi 10 XL Upstream Port of PCI Express Switch (rev c1)
0000:02:00.0 PCI bridge: Advanced Micro Devices, Inc. [AMD/ATI] Navi 10 XL Downstream Port of PCI Express Switch
0000:03:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Navi 23 [Radeon RX 6600/6600 XT/6600M] (rev c1)
0000:03:00.1 Audio device: Advanced Micro Devices, Inc. [AMD/ATI] Navi 21/23 HDMI/DP Audio Controller
$ sudo modprobe amdgpu
@runlevel5
runlevel5 / puma.sh
Last active July 18, 2022 17:37
pumactl is very broken, @nemshilov and @joneslee85 wrote this bash script replacement and it works so reliably on production server. So here it is, share with the world!
#!/usr/bin/env bash
# Simple move this file into your Rails `script` folder. Also make sure you `chmod +x puma.sh`.
# Please modify the CONSTANT variables to fit your configurations.
# The script will start with config set by $PUMA_CONFIG_FILE by default
PUMA_CONFIG_FILE=config/puma.rb
PUMA_PID_FILE=tmp/pids/puma.pid
PUMA_SOCKET=tmp/sockets/puma.sock
@runlevel5
runlevel5 / destroy_untagged_docker_containers.sh
Created June 19, 2014 03:59
Destroy untagged docker images
#!/bin/bash
IMAGE_IDS=$(docker images | grep "^<none>" | awk "{print $3}")
if [ -n "$IMAGE_IDS" ]; then
docker rmi $IMAGE_IDS > /dev/null 2>&1
fi