Skip to content

Instantly share code, notes, and snippets.

View tpai's full-sized avatar
💭
kumo

tonypai tpai

💭
kumo
View GitHub Profile
@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 / README.md
Last active January 24, 2024 10:35
Upgrading Docker-Compose from V1 to V2 with Ansible

install docker compose v2

mkdir -p /usr/local/lib/docker/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.24.2/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
docker compose version

Ref: https://docs.docker.com/compose/install/linux/#install-the-plugin-manually

@tpai
tpai / README.md
Last active January 9, 2024 10:20
A simple Python script for calling GA4 API
@tpai
tpai / walkthrough.md
Created December 31, 2023 05:15
my walkthrough of clmystery

find all clues with 'CLUE:' prefix in crimescene

Suspect:

  • 6' tall male
  • membership cards: Rotary_Club, Delta SkyMiles, the local library, the Museum of Bash History

Witness:

  • A woman named Annabel
  • blond spiky hair
  • New Zealand accent
@tpai
tpai / README.md
Last active April 16, 2023 15:23
This script allows you to extract English text from images using Python.
  1. Install the required packages by running pip install -r requirements.txt in your terminal.
  2. Run the command export TESSDATA_PREFIX=/usr/local/tessdata in your terminal to set the Tesseract data path.
  3. Download the English language data from here and place it to the tessdata folder above.
  4. Run main.py
@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 / obs.css
Last active June 19, 2022 03:06
OBS YouTube chatroom style with Traditional Chinese font
@charset "UTF-8";
@import url("https://fonts.googleapis.com/css?family=Noto+Sans+TC:400,500&display=swap");
body {
background-color: transparent !important;
font-family: "Noto Sans TC", sans-serif !important;
overflow-y: hidden !important;
}