Skip to content

Instantly share code, notes, and snippets.

@leongkui
leongkui / running-docker.dockerfile
Created April 14, 2025 00:44
Run a command to allow docker container to stay alive
CMD ["tail", "-f", "/dev/null"]
@leongkui
leongkui / Next.js setup
Last active February 27, 2025 06:30
NextJS setup
nvm current > .nvmrc
yarn dlx @yarnpkg/sdks vscode
yarn add --dev eslint-config-airbnb eslint-config-airbnb-typescript eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks @typescript-eslint/eslint-plugin @typescript-eslint/parser husky lint-staged @next/eslint-plugin-next @tailwindcss/postcss postcss autoprefixer yarn-upgrade-all
yarn yarn-upgrade-all
Prompt for Aider:
This is a frontend repo, scaffolded with Next.JS (page router), with typescript, eslint, tailwindcss support. It is using `yarn` as package manager.
@leongkui
leongkui / aws-secret-manager.js
Created May 23, 2024 08:33
AWS Secret Manager - Sample code - JS
// Use this code snippet in your app.
// If you need more information about configurations or implementing the sample code, visit the AWS docs:
// https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/getting-started.html
import {
SecretsManagerClient,
GetSecretValueCommand,
} from "@aws-sdk/client-secrets-manager";
const secret_name = "docdb/master/password";
@leongkui
leongkui / faf.ts
Created April 11, 2024 08:22
Next.JS FireAndForget background long running
import { getLogger } from '@core-ui/lib/logger';
import { NextApiRequest, NextApiResponse } from 'next';
import { apiHandler } from '@core-ui/lib/apiHandler';
import { internal_runWithWaitUntil as waitUntil } from 'next/dist/server/web/internal-edge-wait-until';
// WARNING: This api handler uses next internal function that is not designed for production
// https://github.com/vercel/next.js/issues/50522#issuecomment-1838593482
const getHandler = async (req: NextApiRequest, res: NextApiResponse): Promise<NextApiResponse> => {
const logger = getLogger('/api/sitemap.ts:GET');
@leongkui
leongkui / test_concurrent.py
Created October 3, 2023 01:15
Python Concurrent
import requests
import asyncio
from timeit import default_timer
from concurrent.futures import ThreadPoolExecutor
START_TIME = default_timer()
def request(session, i):
url = "http://localhost:3100/expert/?searchQuery=product+management&limit=20&offset=0&sortBy=recommended&sortOrder=DESC&responseTime=48&categories=Marketing&topics=Product+Marketing&domains=Venture Capital&countries=Singapore"
with session.get(url) as response:
@leongkui
leongkui / fuzzy_remove.py
Last active July 6, 2023 23:44
Fuzzy String Matching and Removal
# fuzzy_removal will scan through the text and replace the text with replacement if the text is similar to the target
# default replacement is <Patient Name>
# default similarity score is 80
def fuzzy_removal(
text: str,
target: str,
replacement: str='<Patient Name>',
min_score: int=80,
debug: bool=False,
) -> str:
@leongkui
leongkui / bigram.py
Last active July 4, 2023 01:15
Python Bigram
# replace all punctuations with spaces in plain_text and store in `cleaned` variable
cleaned = re.sub(r'[^\w\s]', ' ', plain_text)
# replace all whitespace with single space in `cleaned` variable
cleaned = re.sub(r'\s+', ' ', cleaned)
# split the cleaned text into a list of words
words = cleaned.split()
# create a list to store bigrams
@leongkui
leongkui / sql-csv
Created April 12, 2023 02:21
SQL to dump to CSV format with header
SELECT GROUP_CONCAT(CONCAT("'", COLUMN_NAME, "'"))
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'patient'
AND TABLE_SCHEMA = 'db2'
order BY ORDINAL_POSITION
INTO OUTFILE '/Users/leongkui/Downloads/db2-header.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n';
@leongkui
leongkui / sudo-touch-id.sh
Created September 23, 2022 03:11
sudo with touch ID
#!/bin/bash
#
# credit to machupicchubeta/dotfiles/bin/enable_to_sudo_authenticate_with_touch_id.sh
set -eu
set -o pipefail
sudo chmod +w /etc/pam.d/sudo
if ! grep -Eq '^auth\s.*\spam_tid\.so$' /etc/pam.d/sudo; then
( set -e; set -o pipefail
# Add "pam_tid.so" to a first authentication
@leongkui
leongkui / googlebot.sh
Created June 30, 2022 09:42
CURL as Googlebot
curl -w 'nLookup time:t%{time_namelookup}nConnect time:t%{time_connect}nPreXfer time:t%{time_pretransfer}nStartXfer time:t%{time_starttransfer}nnTotal time:t%{time_total}n' -A "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" https://speedoc.com/sg/