Skip to content

Instantly share code, notes, and snippets.

@tpai
tpai / eslint.md
Last active December 19, 2024 12:27
ESLint Cheatsheet

Install Dependencies

yarn add babel-eslint \
eslint \
eslint-config-airbnb \
eslint-loader \
eslint-plugin-import \
eslint-plugin-jsx-a11y \
eslint-plugin-react
@tpai
tpai / instructions.md
Last active December 19, 2024 06:55
use both Tor and Privoxy on Mac OS

1. install

brew install tor
brew install privoxy

2. copy and modify config file

@tpai
tpai / delayed_http_response.yml
Created October 25, 2024 05:49
kubernetes summit 2024 code snippets
apiVersion: apps/v1
kind: Deployment
metadata:
name: delayed-http-response-deployment
spec:
replicas: 1
selector:
matchLabels:
app: delayed-http-response
template:
@tpai
tpai / stephen_chow_movie_quotes.txt
Created August 2, 2024 07:40
Steven Chow Movie Quotes
《望夫成龍》
娣:流星呀!人地話對住流星許願會好靈ga!
石金水:流星喎!話明「流」ga咋,你都信?
《一本漫畫闖天涯》
阿星表演唱歌﹕老豆有身己…己…己…己…恭喜恭喜。
阿星:話說小明個老豆有三個仔,大仔叫大毛,二仔叫二毛,咁三仔叫咩名?
朱標:三毛!
阿星:錯!
@tpai
tpai / pitr.sh
Last active July 13, 2024 12:33 — forked from LS80/pitr.sh
Demo PostgreSQL 13 Point-in-time Recovery with Docker
#!/bin/bash
VERSION=13
function cleanup() {
docker rm -f master replica >&/dev/null
rm -Rf $(pwd)/data $(pwd)/wal_archive
}
function wait_until_ready() {
@tpai
tpai / boot_notify.sh
Last active July 6, 2024 10:41
Send notification to a Telegram bot from your device (e.g., Raspberry Pi). It will be helpful when the device has a DHCP IP.
#!/bin/bash
telegram_bot_token="xxx" # ask @BotFather for your Telegram bot token
telegram_chat_id="xxx" # type /start on the bot, and `curl https://api.telegram.org/bot${telegram_bot_token}/getUpdates` to retrieve chat_id
telegram_api_url="https://api.telegram.org/bot${telegram_bot_token}/sendMessage"
send_to_telegram() {
local message="$1"
echo $message
curl -s -X POST "${telegram_api_url}" -H "Content-Type: application/json" -d "{\"chat_id\": \"$telegram_chat_id\", \"text\": \"$message\"}"
@tpai
tpai / claude-3-sonnet.md
Last active June 26, 2024 02:46
system prompts of popular GenAI

You are Claude, created by Anthropic.

The current date is Thursday, May 30, 2024.

Claude's knowledge base was last updated in August 2023 and it answers user questions about events before August 2023 and after August 2023 the same way a highly informed individual from August 2023 would if they were talking to someone from Thursday, May 30, 2024.

It should give concise responses to very simple questions, but provide thorough responses to more complex and open-ended questions.

It cannot open URLs, links, or videos, so if it seems as though the interlocutor is expecting Claude to do so, it clarifies the situation and asks the human to paste the relevant text or image content directly into the conversation.

@tpai
tpai / extract-cert-chain.sh
Created June 18, 2024 09:07
Certificate chain extraction script
#!/bin/bash
# Accept stdin as input domain and dump the certificate chain
domain="$1"
openssl s_client -connect "$domain:443" -showcerts </dev/null 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > fullchain.pem
# Split the chain into individual certificates
awk '/BEGIN CERTIFICATE/{n++} {print >("cert-" n ".pem")}' fullchain.pem
# Rename the split files for clarity, handling 2 or 3 certificates
@tpai
tpai / main.py
Created June 17, 2024 16:01
AWS Bedrock API call (Claude 3 Sonnet)
import requests
import json
import boto3
from botocore.auth import SigV4Auth
from botocore.awsrequest import AWSRequest
# AWS credentials
access_key = '<access-key>'
secret_key = '<secret-key>'
region = 'us-west-2'
@tpai
tpai / webpackUMD.js
Last active February 12, 2024 00:06
webpackUMD
(function webpackUniversalModuleDefinition(root, factory) {
if (typeof exports === 'object' && typeof module === 'object') // CommonJS(2)
module.exports = factory(require(__require_module__));
else if (typeof define === 'function' && define.amd) // AMD
define([__require_module__], factory);
else if (typeof exports === 'object') // CommonJS(1)
exports[__module_name__] = factory(require(__require_module__));
else // Global Variable
root[__module_name__] = factory(root[__require_module__]);
})(typeof self !== 'undefined' ? self : this, function() {