Skip to content

Instantly share code, notes, and snippets.

View PatrickChoDev's full-sized avatar
🎯
Focusing

Thanapat Chotipun PatrickChoDev

🎯
Focusing
View GitHub Profile
@PatrickChoDev
PatrickChoDev / cuid2.sql
Last active December 18, 2024 10:52
Generating CUID2 with PostgreSQL
CREATE OR REPLACE FUNCTION generate_cuid2(target_length INT DEFAULT 24)
RETURNS TEXT AS $$
DECLARE
timestamp_part TEXT; -- Encoded timestamp in base36
random_part TEXT; -- Random string for uniqueness
random_length INT; -- Length of the random part
characters TEXT := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; -- Alphanumeric characters
result TEXT; -- Final result to return
BEGIN
-- Validate input length
@PatrickChoDev
PatrickChoDev / gitprofile.sh
Created December 13, 2024 18:02
gitprofile is the manager of git profile for switching quickly between config
#!/bin/zsh
# This script is used to switch between different git profiles
# Read the profile name from the command line argument
profile_name=$1
if [ "$profile_name" = "-h" ] || [ "$profile_name" = "--help" ]; then
echo "Usage: gitprofile <profile_name> [-c|--config <config_file>]"
echo "Switch between different git profiles"
@PatrickChoDev
PatrickChoDev / qmultiply.py
Created December 12, 2024 14:01
Binary multiplication on circuit based Quantum computer (Qiskit)
#Please run this inside the Jupyter notebook, It'll be quite straight forward.
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, transpile
from qiskit_aer import AerSimulator
from math import pi
from matplotlib import pyplot as plt
%matplotlib inline
def create_input_state(qc, reg, n, pie):
@PatrickChoDev
PatrickChoDev / devcontainer.json
Created November 10, 2023 18:26
PNPM devcontainer multiple project setup
{
"name": "Multiple PNPM projects",
// recommend using microsoft default image
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye",
// !!!! MAGIC STARTS HERE!!!
"mounts": [
"source=global-pnpm-store,target=${containerWorkspaceFolder}/.pnpm-store,type=volume"