Skip to content

Instantly share code, notes, and snippets.

View bouroo's full-sized avatar
🏠
Remote Working

Kawin Viriyaprasopsook bouroo

🏠
Remote Working
View GitHub Profile
@bouroo
bouroo / rewrite.js
Last active June 15, 2025 13:49
AWS CloudFront function for static web app on Amazon S3
async function handler(event) {
const request = event.request;
const uri = request.uri;
// Determine if the URI has a query string.
const hasQuery = uri.indexOf('?') !== -1;
// Determine if the URI has a file extension.
// An extension is considered present if there's a dot, and the last dot
// appears after the last slash (indicating it's part of a filename, not a directory).
@bouroo
bouroo / convert_latin1_to_utf8mb4.sql
Last active May 12, 2025 04:18
A script that performs the conversion of `latin1` encoded strings to `utf8mb4` for all columns in all tables of a specific mariadb database. Make sure to back up your data before running scripts that modify it.
DELIMITER //
-- Drop the procedure if it already exists
DROP PROCEDURE IF EXISTS convert_chars_to_utf8mb4 //
-- Create the procedure to convert character set of columns
CREATE PROCEDURE convert_chars_to_utf8mb4(IN db_name VARCHAR(255))
BEGIN
-- Declare variables for cursor and loop control
DECLARE done INT DEFAULT FALSE;
@bouroo
bouroo / update-litespeed-cache.sh
Last active August 24, 2024 06:00
updates the LiteSpeed Cache plugin for all WordPress installations on a DirectAdmin server
#!/usr/bin/env bash
# ------------------------------------------------------------------------------
# Script Name: update-litespeed-cache.sh
# Description: This script updates the LiteSpeed Cache plugin for all WordPress
# installations on a DirectAdmin server. It checks for the WP-CLI
# tool and installs it if not found, then updates the specified plugin
# for each user's domains.
#
# Author: Kawin Viriyaprasopsook
@bouroo
bouroo / yum.repos.sh
Last active June 15, 2025 13:50
vault centos 6
#!/usr/bin/env bash
# Ensure the target directory exists before writing the repository file.
# This makes the script more robust, especially in minimal environments
# where /etc/yum.repos.d might not be pre-created.
mkdir -p /etc/yum.repos.d/
# Write the CentOS 6.10 repository configuration to the specified file.
# Using a 'here document' (heredoc) with quoted EOF ('-EOF') ensures
# the content is written verbatim, preserving '$basearch' for yum
@bouroo
bouroo / config.spa.unit.json
Last active May 12, 2025 04:20
simple nginx/unit config to serve SPA
{
"listeners": {
"*:8080": {
"pass": "routes/main"
}
},
"routes": {
"main": [
{
"action": {
@bouroo
bouroo / docker-compose.yaml
Last active June 15, 2025 13:54
pgcat and postgresql replication with docker compose
# Environment variables for PostgreSQL containers
x-default-pg-env: &default-pg-env
# Set the timezone to Asia/Bangkok
TZ: Asia/Bangkok
# Username for the PostgreSQL administrative account
POSTGRESQL_USERNAME: postgres
# Name of the default PostgreSQL database
POSTGRESQL_DATABASE: postgres
# Password for the PostgreSQL administrative account
POSTGRESQL_PASSWORD: mysecretpassword
@bouroo
bouroo / TurtleTrading.pine
Last active June 15, 2025 13:55
Turtle Trading Strategy with Supertrend Confirmation
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © bouroo
//@version=5
strategy("Turtle Trading Strategy with Supertrend Confirmation", overlay=true, pyramiding=0) // Pyramiding set to 0 to prevent multiple entries for the same direction
// --- Strategy Parameters ---
// Turtle Trading Parameters
length1 = input.int(20, title="Donchian Channel Length (Breakout)", minval=1)
length2 = input.int(10, title="Donchian Channel Length (Exit)", minval=1)
@bouroo
bouroo / speedtest.sh
Created May 30, 2024 11:22
speedtest-cli script
#!/usr/env/bash
# Thailand
speedtest -s 27203
# Singapore
speedtest -s 2054
@bouroo
bouroo / resize_disk.sh
Last active June 15, 2025 14:00
linux extend disk partition script
#!/usr/bin/env bash
# Exit immediately if a command exits with a non-zero status.
set -e
# Find the device containing the root filesystem (e.g., /dev/sda3 or /dev/mapper/vg-root)
ROOT_FS_DEVICE=$(findmnt -n -o SOURCE /)
# Check if ROOT_FS_DEVICE was found
if [ -z "$ROOT_FS_DEVICE" ]; then
echo "Error: Could not determine root filesystem device."
@bouroo
bouroo / thai-id-card.rs
Last active June 1, 2025 11:22
Thai ID card reader in Rust
use std::{
fs::File,
io::{self, Write},
str,
};
use pcsc::{Attribute, Card, Context, Error, Scope, ShareMode};
use charmap::WINDOWS_874;
// Data field commands (label, command APDU)
const FIELDS: &[(&str, [u8; 7])] = &[