Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / mira-milk-frother-instructions.md
Created December 9, 2020 20:39
Mira Milk Frother Usage
  • To warm and froth milk:
Push the on button once
- blue indicator lights up
  • To only warm milk:
Push the on button two time
- blue indicator lights up (not helpful)
@xcsrz
xcsrz / es-backup-control.py
Created October 10, 2020 19:15
This python script is used to increase the number of replicas in an ES cluster and force those new replicas to be allocated to a new host to enable a filesystem backup of the ES data directory.
from requests import get, post, put
from json import dumps, loads
from sys import argv
from math import ceil
commands = []
def addShard(idx, shard):
commands.append({
"allocate" : {
@xcsrz
xcsrz / material-ui-starter-pre-react-hooks.sh
Created May 8, 2020 15:19
When you need to jump start a material-ui project with the pre-hooks version of react. (react v16.7, material-ui v3.7.1)
curl https://codeload.github.com/mui-org/material-ui/tar.gz/v3.7.1 | tar -xz --strip=2 material-ui-3.7.1/examples/create-react-app
@xcsrz
xcsrz / certificate-dates.sh
Created April 16, 2020 03:03
Print the dates from an SSL certificate
openssl x509 -noout -dates -in cert.pem
@xcsrz
xcsrz / pemify-your-private-ssh-key.sh
Created April 5, 2020 19:31
This one command is so hard to track down every 3 years when I need it. So many posts incorrectly insist the private key is in PEM format already. In truth, it depends on how the key pair was created (openssl vs ssh-keygen).
# NOTE: this updates the file in place, do you have a backup?
ssh-keygen -p -m PEM -f ~/.ssh/id_rsa
@xcsrz
xcsrz / abort-trap-6-fix.sh
Created March 11, 2020 00:14
fix for when `macos catalina upgrade` makes random scripts bomb with `Abort trap: 6`
brew update && brew upgrade && brew install openssl
cd /usr/local/Cellar/openssl/1.0.2*/lib
sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/local/lib/
cd /usr/local/lib
sudo ln -s libssl.1.0.0.dylib libssl.dylib
sudo ln -s libcrypto.1.0.0.dylib libcrypto.dylib
@xcsrz
xcsrz / bitbucket-archive.py
Last active March 4, 2020 06:04
With atlassian falling apart and abandoning mercurial (the only reason to use bitbucket unless you're one of those anti-microsoft holdouts) you may find yourself looking to collect all your bitbucket repos to take elsewhere ... like ... github. This script is the first step. This is the first draft, only tested on mac running python 3.7 but shou…
from requests import get
from os import environ, getcwd, chdir, mkdir, system
from json import dumps
basedir = getcwd() + '/repos'
mkdir(basedir)
username=environ['BITBUCKET_USER']
password=environ['BITBUCKET_PASS']
team=environ['BITBUCKET_TEAM']