Skip to content

Instantly share code, notes, and snippets.

@xcsrz
xcsrz / webtask-backup.py
Created May 10, 2021 21:05
Backup your webtask code. Can be used to make sure you have the latest version of your code locally, or used to backup in case at some point webtask.io ceases to function. Considering they very recently started failing to install new npm modules, this could be any point now I fear.
import subprocess
from json import dumps
# NOTE: Files will be written to the current directory, without any checks to prevent overwriting. Archiving and/or version control are not considered here, but highly encouraged.
# get a list of all webtasks for the current user
list_request = subprocess.run(['wt', 'ls'], stdout=subprocess.PIPE, text=True)
# transform that output into a list of task names
tasks = [ ln.replace('Name:','').strip() for ln in list_request.stdout.split("\n") if 'Name:' in ln ]
@xcsrz
xcsrz / accessing child accounts in aws.md
Created October 11, 2021 17:42
Accessing "member accounts" of your AWS organization. Since the AWS documentation and all the write-ups are more complicated than useful, there's the cliff notes.
@xcsrz
xcsrz / getContentHash.py
Last active December 20, 2021 20:19
Python port of the getContentHash() function from PHP's Composer. Useful when updating composer.lock from php when composer is available. Granted this "shouldn't be done" and is "doing it wrong", but sometimes running composer commands in your deployment chain is overkill and redundent.
import hashlib
from json import dumps
from collections import OrderedDict
# composerFileContents should be the dict version of the composer.json file
def getContentHash(composerFileContents):
relevant = OrderedDict((key, composerFileContents[key]) for key in composerFileContents.keys() if key in ['name','version','require','require-dev','conflict','replace','provide','minimum-stability','prefer-stable','repositories','extra'])
if 'config' in composerFileContents and 'platform' in composerFileContents['config']:
relevant['config']['platform'] = composerFileContents['config']['platform']
@xcsrz
xcsrz / flush-elasticsearch.sh
Created November 13, 2021 22:13
Sometimes you just need to delete everything in an elasticsearch cluster and you don't have access to do the stop-rm-rf-start thing.
for idx in $(curl -sS https://${DOMAIN}:${PORT}/_cat/indices | awk '{print $3}'); do curl -XDELETE "https://${DOMAIN}:${PORT}/${idx}"; done
@xcsrz
xcsrz / armagetron-build-instructions.md
Created January 11, 2022 17:04
Building Armagetron on macos (worked on Catalina)

Install Dependencies

brew install pkg-config autoconf automake sdl2 sdl2_image sdl2_mixer protobuf-c glew boost ftgl dylibbundler create-dmg

Setup

./bootstrap.sh
@xcsrz
xcsrz / list-timezones-with-winter-and-summer-offsets.py
Created January 16, 2022 17:46
Sometimes you just want a list of timezones with their offsets. From this you can find the offset for a given timezone on a specific date.
from datetime import datetime
import pytz
UTC = pytz.timezone("UTC")
for tzn in pytz.common_timezones:
tz = pytz.timezone(tzn)
print(
tzn,
UTC.localize(datetime(2020, 12, 15)).astimezone(tz).strftime('%z'),
UTC.localize(datetime(2020, 6, 15)).astimezone(tz).strftime('%z'),
@xcsrz
xcsrz / amazon2-linux-amis-for-cloudformation.py
Created February 25, 2022 21:20
This script prints out the current list of Amazon2 Linux AMI's by region (kernel 5.10, HVM, x86_64, gp2). Changing the image variable and the Path filter make this capable of searching for any public/shared image.
import boto3
from json import dumps
from yaml import dump
image = 'amzn2-ami-kernel-5.10-hvm-x86_64-gp2'
regions = [
'ap-northeast-1',
'ap-northeast-2',
'ap-northeast-3',
@xcsrz
xcsrz / es-doc-accounting.py
Created March 7, 2022 15:57
Reconcile descrepencies in document counts within elasticsearch
from requests import get
from json import dumps, loads
from prettytable import PrettyTable
src_server = 'http://localhost:9200'
def docCount(idx=None, typ=None):
url = src_server
if idx:
@xcsrz
xcsrz / install-python-3.9-on-centos.sh
Created May 13, 2022 15:52
Install Python 3.9 on CentOS or Amazon Linux
#!/bin/sh
sudo yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel
cd /tmp
wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
tar -xvf Python-3.9.6.tgz
cd Python-3.9.6
./configure --enable-optimizations
sudo make altinstall
python3.9 --version
@xcsrz
xcsrz / add-fades-to-video.sh
Last active February 26, 2023 16:36
Add a gentle fade-in from black to the beginning and a matching fade-out to the end of a video clip
#!/bin/bash
destfile() {
dir=$(dirname "$1")
filename=$(basename -- "$1");
extension="${filename##*.}";
basename="${filename%.*}";
filepath="${dir}/${basename}-faded.${extension}";
c=0