Skip to content

Instantly share code, notes, and snippets.

@tommyjtl
tommyjtl / pdf-compress.sh
Created January 26, 2024 17:48
PDF compression CLI with Ghostscript.
pdf-compress() {
QUALITY=150
INPUT_PDF=""
GS_BIN=$(command -v gs)
print_usage() {
echo "Usage: pdf-compress [-q|--quality <res>] <file>"
echo " Where:"
echo " -q|--quality <res> is the resolution for the PDF (default: 150)"
echo " <file> is the PDF file to compress"
@tommyjtl
tommyjtl / enter.sh
Created January 14, 2024 19:01
A bash function command that quickly takes me to certain directory.
enter() {
local config_dir="$HOME/.config/enter"
local config_file="$config_dir/enter.yml"
# Initialize configuration
if [ ! -d "$config_dir" ]; then
mkdir -p "$config_dir"
fi
if [ ! -f "$config_file" ]; then
local user_root=$(pwd )
@tommyjtl
tommyjtl / python-arm.sh
Created October 27, 2023 19:05
Bash function to quickly launch the arm64 version of Python on macOS with Apple Silicon.
python-arm() {
# Get the platform information
platform=$(uname -m)
# Check if the platform is darwin arm
if [[ "$platform" == "arm64" ]]; then
# Run the desired command if on darwin arm platform
/opt/homebrew/opt/python@3.9/bin/python3.9 "$@"
else
# Exit if not on darwin arm platform
@tommyjtl
tommyjtl / README.md
Last active August 15, 2023 16:10
Serving Secured WebSocket Server (wss://) via Nginx and PM2.

This gist demonstrated the example use of serving secured WebSocket server (wss://) using Python's websockets via Nginx and PM2 the process manager. Have not tested thoroughly on production, so this is only for development use.

  • For fullchain.pem and privkey.pem, you will need use cerbot to generate them.
  • For pm2.json, run pm2 start pm2.json to run the WebSocket server in the background.
@tommyjtl
tommyjtl / yosemite_reservation_check.py
Created June 4, 2022 07:23
Periodically checking reservation slots for Yosemite National Park Ticketed Entry.
# pm2 start yosemite-reservation-check.py --name yosemite --interpreter python
import http.client
import json, time, threading
to_query_dates = ["2022-06-07", "2022-06-08", "2022-06-09"] # Follow the format: YYYY-MM-DD
query_period = 300 # seconds
def query():
conn = http.client.HTTPSConnection("www.recreation.gov")
function cocomod() {
# port list all detected ports: python3 -m there detect
# run run local file on module (not send): python3 -m there run [FILE]
# list list file: python3 -m there ls -l [/] python3 -m there run [FILE]
# send send file to module: python3 -m there push [FILE] [/]
# read get source code from file on module: python3 -m there cat [FILE]
# delete delete file from module: python3 -m there rm [FILE]
# repl enter repl: python3 -m there -i
# echo "Usage: burn, goto, port, run, list, send, read, delete, repl"
import subprocess, os
current_path = os.getcwd()
current_file_list = os.listdir()
def exec_command(cmd):
command = cmd.split()
command_output = subprocess.run(command, capture_output=True)
for line in command_output.stdout.decode("utf-8").split("\n"):
print("\t\t", line)
@tommyjtl
tommyjtl / dopa-rev5_withname.stl
Last active June 26, 2020 04:43
Ring for lovers. License under CC 4.0 BY-SA.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
'''
requirements:
scikit-image==0.16.2
tqdm==4.45.0
'''
from PIL import Image, ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
import glob, random, os, time, re, time
@tommyjtl
tommyjtl / http-benchmark.md
Created August 3, 2019 02:53 — forked from denji/http-benchmark.md
HTTP(S) Benchmark Tools / Toolkit for testing/debugging HTTP(S) and restAPI (RESTful)