Skip to content

Instantly share code, notes, and snippets.

@jooray
jooray / cut_video.py
Created January 20, 2025 12:39
Cut video using ffmpeg
#!/usr/bin/env python3
"""
cut_video.py
Usage:
python cut_video.py [--include|--exclude] input_video.mp4 output_video.mp4 < timestamps.txt
The timestamps file (passed via stdin) contains lines like:
00:00:30.900;00:00:54.360
00:02:28.080;00:02:29.340
@jooray
jooray / learndash-course2html.py
Created December 5, 2024 22:51
Converts a LearnDash course backup (lessons only) into a single ordered HTML file with sections for easy reference.
#!/usr/bin/python3
# This script converts a learndash course backup with lessons (but not
# themes/topics!) to a single ordered HTML file with sections for easy reference
import argparse
import json
def analyze_course_structure(course_file, lessons_file, course_id):
with open(course_file, 'r', encoding='utf-8') as file:
lines = file.readlines()
@jooray
jooray / product-checkout.php
Last active September 13, 2024 11:48
Add product to WooCommerce cart & redirect to checkout via URL parameter
<?php
/**
* Add a direct-to-checkout functionality to WooCommerce.
*
*
* When user follows the link with productcheckout parameter, it
* clears the existing shopping cart and adds the specified product
* to the cart (with optional quantity). You can add multiple products
* separated by commas.
@jooray
jooray / fix-signal-media-timestamps.sh
Created August 12, 2024 08:14
Signal media comes without metadata (which is good). But for importing into photo apps, it makes sense to have at least date and time, which is in the filename anyway.
#!/bin/bash
for file in signal-*.jpeg signal-*.mp4; do
filename=$(basename "$file")
date_time=$(echo "$filename" | cut -d '-' -f 2-5 | sed 's/_/ /g' | sed 's/-/ /g' | awk '{print $1 "-" $2 "-" $3 " " $4}' | sed 's/ /:/4')
# Add metadata to images and videos
if [[ $file == *.jpeg ]]; then
exiftool -overwrite_original -DateTimeOriginal="$date_time" -DateTimeDigitized="$date_time" -DateTime="$date_time" "$file"
elif [[ $file == *.mp4 ]]; then
@jooray
jooray / translation_diff.py
Created July 7, 2024 08:32
Diff for Android app translation xml files
# A script which takes a reference file (usually English), a translated file and outputs
# strings that need to be translated.
#
# Used for Slovak translation of Phoenix Wallet Android app
# Before using, run:
# pip install lxml
from lxml import etree
import sys
@jooray
jooray / eso-level-estimator.md
Last active September 15, 2024 12:28
Eso level estimator 8000 - prompt for LLMs

You are an eso level estimator bot. Today is {current_date}. You are going to output an eso level (level of esotericness) based on the following scale:

0 - 🔢 facts deriving through logic from axioms, praxeology

1 - 🧪 physics, chemistry, gold as money

2 - 📈 results based on studies with theory of causality, computer science

3 - 👓 observational studies, studies on small samples, observed results without established theory of causality

@jooray
jooray / lnbank_balances.md
Created February 29, 2024 18:45
How to settle lnbank balances after lnbank being deprecated

Connect to PSQL:

docker exec -it $(docker ps -a -q -f "name=postgres_1") psql -U postgres -d btcpayservermainnet
set search_path to "BTCPayServer.Plugins.LNbank";

Then you can see wallets:

@jooray
jooray / monero-search.js
Created April 13, 2023 21:47
A way to search for monero transactions with particular inputs in ring groups
const monerojs = require('monero-javascript');
const cliProgress = require('cli-progress');
async function scanForInputs() {
// parameters
const rpc = await monerojs.connectToDaemonRpc('http://localhost:18081');
const min_height = 2853173;
@jooray
jooray / chat-vicuna.sh
Created April 8, 2023 16:58
A modified chat-13B.sh script from llama.cpp to change prompt to the style vicuna model was trained.
#!/bin/bash
cd "$(dirname "$0")/.." || exit
MODEL="${MODEL:-./models/13B-vicuna/ggml-vicuna-13b-4bit-rev1.bin}"
USER_NAME="${USER_NAME:-Human}"
AI_NAME="${AI_NAME:-Assistant}"
# Adjust to the number of CPU cores you want to use.
N_THREAD="${N_THREAD:-8}"
@jooray
jooray / alpacoom-mps.py
Created March 28, 2023 14:42
Running alpacoom model on MPS (Apple Silicon) using HuggingFace Transformers and Peft
import os
import torch
from peft import PeftModel, PeftConfig
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
import sys
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
peft_model_id = "mrm8488/Alpacoom"