Skip to content

Instantly share code, notes, and snippets.

@pixelchai
pixelchai / human_number.py
Last active May 8, 2021 02:22
Return human-readable version of number with suffix. E.g: 30.4k (base 10)
def human_number(num):
"""
return human-readable version of number. E.g: 30.4k
"""
# https://gist.github.com/pixelzery/eace0b100a381e7cf724612b7309a9d2
if num == 0:
return "0"
elif num < 0:
return "-" + human_number(-num)
@pixelchai
pixelchai / _sql.json
Last active May 27, 2020 05:32
VSCode sqlite SQL snippets
// create table: ct
// foreign key: fk
// create key with type INTEGER, TEXT, BLOB, NULL, REAL respectively: cki, ckt, ckb, ckn, ckr
// create key with type TEXT + PRIMARY KEY: cktp
// create key with type REAL + NOT NULL: ckrn
// create key with type INTEGER + UNIQUE: ckiu
// PRIMARY KEY, NOT NULL, UNIQUE can be chained in any combination. E.g: ckipnu, ckrun, ckiupn
{
"Create Table": {
"prefix" : "ct",
@pixelchai
pixelchai / insta-timelapse
Created August 31, 2019 00:22
Creates timelapse from video, and padds resultant video appropriately such that its aspect ratio is equal to the input drawing - for Instagram
#!/bin/sh
img=$1
vid=$2
fps=${3:-25}
out=${4:-timelapse.mp4}
echo "insta-timelapse:"
if [ $# -lt 2 ]; then
echo "USAGE: ./insta-timelapse img_path vid_path [target_fps=$fps] [out_path=$out]"
@pixelchai
pixelchai / sqlitetodbdiagram.py
Last active January 17, 2020 22:15
converts an input sqlite sql file into the format used by https://dbdiagram.io/
import re
text = ""
output = ""
with open("input.sql") as f:
text = f.read()
text = re.sub(r"--.*", "", text)
for m_table in re.finditer(r"CREATE\s+TABLE\s+IF\s+NOT\s+EXISTS\s+"\
import math
import subprocess
import os
import sys
import shutil
SEC_LENGTH = 30 # section length - actual time (s)
SEC_SEP = 120 # time spetween sections - actual time (s)
SPEEDUP = 20
FPS_SOURCE = 60
@pixelchai
pixelchai / shortcuts.ahk
Last active May 4, 2020 21:53
AutoHotKey script to mimic some i3 behaviour on Windows
; mod+shift+r or mod+r = reload this script
#+r::
#r::
Reload
return
; mod+shift+q = close active window
#+q::WinClose A
; mod+shift+enter = browser
import subprocess
import os
import sys
import shutil
SEC_LENGTH = 30 # section length - actual time (s)
SEC_SEP = 120 # time petween sections - actual time (s)
SPEEDUP = 1
FPS_FINAL = 15
PART_LENGTH = 59 # time - output time (s)
@pixelchai
pixelchai / player_movement.gd
Created June 25, 2020 21:20
Godot player movement script -- with double jumping
extends KinematicBody2D
const UP = Vector2(0, -1)
const GRAVITY = 20
const ACCELERATION = 200
const MAX_SPEED = 600
const JUMP_HEIGHT = -750
var motion = Vector2()
var num_jumps = 0
@pixelchai
pixelchai / python.gitignore
Last active May 1, 2024 13:37
My simple Python .gitignore file
__pycache__/
*.lock
**/.nfs*
.idea/
/venv/
**/.fuse_hidden*
.ipynb_checkpoints/
@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)]