Skip to content

Instantly share code, notes, and snippets.

@pR0Ps
pR0Ps / zip_paths.py
Last active August 20, 2022 08:10
Add files and folders to a zip file (Python3)
import os
import zipfile
import io
import logging
def zip_paths(paths):
"""
Compresses directories and files to a single zip file.
Returns the zip file as a data stream, None if error.
@pR0Ps
pR0Ps / pre-receive
Last active August 29, 2015 14:09
Server-side commit message validation
#!/bin/sh
read oldrev newrev refname
NULL_SHA1="0000000000000000000000000000000000000000"
revs=""
case $oldrev,$newrev in
*,$NULL_SHA1) # Deleting ref
;;
@pR0Ps
pR0Ps / compare.py
Last active August 29, 2015 14:10
Do ordered comparisons with mixed types in Python 3 (good for sorting heterogeneous lists)
def compare(x, y):
if x == y:
return 0
try:
if x < y:
return -1
else:
return 1
except TypeError as e:
# The case where both are None is taken care of by the equality test
@pR0Ps
pR0Ps / commit-msg
Created August 28, 2015 03:43
Validate commit messages on the client side
#!/bin/sh
# Don't worry about merge commits
if [ -f .git/MERGE_MSG ]; then
exit 0
fi
# Get first non-comment line of the commit message
fl=$(sed '/^#.*/d' $1 | head -1)
@pR0Ps
pR0Ps / gen-flac-visuals
Created January 22, 2017 01:54
Generates spectrogram and waveform images from flac files
#!/bin/sh
# Requires: audiowaveform (https://github.com/bbc/audiowaveform), metaflac, sox
zoom_start=60
zoom_duration=4
zoom_end=$((zoom_start + zoom_duration))
if [ $# -lt 1 ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
echo "Generates spectrogram and waveform images from flac files"
@pR0Ps
pR0Ps / spotify-url2info.py
Last active March 24, 2017 23:30
[quick hack] Get artists and names from a list of spotify track urls
#!/usr/bin/env python3
"""
Takes a file full of Spotify track URLss and prints their artists and track
names to stdout. Useful for converting a spotify playlist export to a list of
human-readable songs.
File format:
```
https://open.spotify.com/track/<track id>
@pR0Ps
pR0Ps / warpwg.sh
Created September 29, 2019 00:02
Generate a vanilla Wireguard config file for Cloudflare's WARP service
#!/usr/bin/env bash
set -eou pipefail
# This script takes/generates a Wireguard private/public key pair, registers it with CloudFlare's WARP
# service, and outputs a Wireguard config file.
# Adapted from @saurik's script here: https://twitter.com/saurik/status/1176893448445558784
if [ "$#" -gt 0 ] && [ "$1" = "--help" ]; then
echo "Creates a Wireguard config file for CloudFlare's WARP service."
@pR0Ps
pR0Ps / make-wg-client.sh
Last active March 28, 2024 10:01
Script to generate wireguard configs for clients to allow them to connect to the local wireguard server
#!/bin/bash
#######
# Setup
#######
### Enable IPv4/6 forwarding:
# # In /etc/sysctl.d/30-ipforward.conf :
# net.ipv4.ip_forward=1
# net.ipv6.conf.default.forwarding=1
# net.ipv6.conf.all.forwarding=1
@pR0Ps
pR0Ps / unifi-update.sh
Last active September 24, 2022 19:10
Update a UniFi Controller installation on Alpine Linux
#!/bin/sh
####################################
# Update a UniFi Controller installation on Alpine Linux
#
# Assumes that the unifi service can be manipulated with "rc-service unifi <start/stop>"
#
# For initial installation see https://wiki.alpinelinux.org/wiki/UniFi_Controller
# Additional steps:
# - apk add --no-cache libc6-compat
@pR0Ps
pR0Ps / skyforcestars.py
Created August 17, 2020 03:23
Set the number of stars you have in Sky Force Reloaded
#!/usr/bin/env python
"""
The game Sky Force Reloaded on Android stores how many in-game stars you've
collected in an obfuscated config file. This program was made by
reverse-engineering that obfuscation using a bunch of sample values.
Given the number of stars you want, it will generate a line to add to the
game's config file. Note that the game will treat invalid values as 0 so make a
backup of your config before modifying it.