Skip to content

Instantly share code, notes, and snippets.

@pixelchai
pixelchai / int_to_string.py
Last active May 24, 2021 00:45
Encode an int into a compact string representation using an arbitrary alphabet
# works on any integer N where N > 0
def int_to_string(n):
alphabet = "0123456789abcdefghijklmnopqrstuvwxyz"
if n == 0:
return ""
else:
return int_to_string(n // len(alphabet)) + alphabet[n % len(alphabet)]
@pixelchai
pixelchai / ellipse_regress.py
Last active February 19, 2021 23:57
A Python script to regress an ellipse from a list of (x, y) coordinate pairs by solving systems of linear equations and using monte carlo
# This is a Python script to regress an ellipse from a list of (x, y) coordinate pairs
# it heuristically optimises the coefficients of the following equation:
# Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0
# It tries to minimise the MSE between observed points and points predicted by the model
# Method:
# It may not be the most optimal method but it's reasonably fast, was quick to implement and works
# - Randomly picks 5 points out of the list of points
# - Solves for the coefficients by solving the corresponding system of equations
# - The solution is evaluated by randomly selecting coordinate pairs and evaluating their MSE
@pixelchai
pixelchai / m3u8_listener.md
Last active September 18, 2024 19:15
Tutorial on how to listen for and extract m3u8 streams over https using TShark

Listening for m3u8 files using TShark

Set-Up

In order to capture https traffic, some setting up is required in order to allow tshark to decrypt the traffic.
A pre-master secret key will be used in order to do this.

Basically, we need to get the browser to log a SSL key log file. This can be done by following the steps here: https://www.comparitech.com/net-admin/decrypt-ssl-with-wireshark/.

In summary, the steps are:

  1. export SSLKEYLOGFILE=~/.ssl-key.log
@pixelchai
pixelchai / noise.sh
Created September 14, 2020 12:33
Generate and play brown noise using mpv and ffmpeg
#!/bin/sh
mpv "av://lavfi:anoisesrc=color=brown,volume=0.5"
@pixelchai
pixelchai / outlook_export.py
Created August 29, 2020 00:36
Quick script I made to automate exporting all my emails from my Outlook inbox as .msg files and renaming them all to be the timestamp of the message
import os
import time
import shutil
import extract_msg
import dateparser
import datetime
import pygetwindow as gw
import pyautogui as gui
import traceback
import ctypes
@pixelchai
pixelchai / gif-to-insta.sh
Last active August 23, 2020 12:08
ffmpeg command to convert a gif into an instagram-compatible video. NB: it is assumed that the gif is already in the correct dimensions: Square video minimum resolution is 600 x 600. Max is 1080 x 1080.
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100
-i input.gif
-c:v libx264 -pix_fmt yuv420p -movflags +faststart
-filter:v fps=fps=30
-c:a aac -shortest
output.mp4
@pixelchai
pixelchai / journal.py
Last active July 26, 2020 11:41
Python script to manage a simple Journal system (with a template)
#!/bin/env python3
import os
import datetime
EDIT_CMD = "vim {{ path }}"
BASE_PATH = "posts"
def template(s, data):
"""
a very simple template evaluation method
@pixelchai
pixelchai / memories.py
Last active April 27, 2021 06:46
Script to download all the memories media from Snapchat's 'Download My Data' thing: https://accounts.snapchat.com/accounts/downloadmydata
import json
import requests
from tqdm import tqdm
import os
import traceback
OUTPUT_FOLDER = "media"
def download(media):
try:
@pixelchai
pixelchai / popm_redist.py
Last active July 13, 2020 08:22
Redistribute ID3 POPM ratings to follow a different distribution (especially: to import songs rated in MusicBee into Quod Libet)
import sys
from mutagen.id3 import ID3
from pathlib import Path
WRITE = 1
bins = [248, 219, 190, 157, 121, 100, 59, 20, 8, 1, 0]
# new_dist = [255, 229, 204, 178, 135, 127, 80, 56, 51, 25, 0]
new_dist = [int(255 * x / 10) for x in range(10, -1, -1)]
@pixelchai
pixelchai / python.gitignore
Last active September 27, 2024 18:19
My simple Python .gitignore file
.idea/
.vscode/
__pycache__/
*.lock
**/.nfs*
/venv/
**/.fuse_hidden*
.ipynb_checkpoints/