dP.  .dP .d8888b. .d8888b. 88d888b. d888888b
 `8bd8'  88'  `"" Y8ooooo. 88'  `88    .d8P'
 .d88b.  88.  ...       88 88        .Y8P   
dP'  `dP `88888P' `88888P' dP       d888888P
    
PROGRAMMER /ˈprōˌɡramər/
A person who solves problems you didn't know you had in ways you don't understand.
public wərk snippets contact

Code Snippets

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'),
)
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

Configure

./configure --disable-debug \
            --disable-dependency-tracking \
            --disable-silent-rules \
            --disable-zthreadtest \
            --disable-sysinstall \
            --disable-uninstall \
            --disable-restoreold \
            --enable-automakedefaults \
            --disable-useradd \
            --disable-initscripts \
            --disable-etc

Build

REL_TOP_SRCDIR=. sh desktop/os-x/build_bundle.sh

References

  • https://wiki.armagetronad.org/index.php?title=MacOS
  • https://gitlab.com/armagetronad/armagetronad/-/blob/trunk/documentation/installation.txt
  • https://gitlab.com/armagetronad/armagetronad/-/issues/119
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
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']
# hacky fix to cover the differences between JSON encoding in Python vs PHP
encstr = dumps(OrderedDict((key, relevant[key]) for key in sorted(relevant.keys())),separators=(',', ':')).replace("/", "\\/").encode()
return hashlib.md5(encstr).hexdigest()
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.

Switching to Child Account in AWS

Prerequisites

Setting up a child accocunt:

Configuring switch roles

This needs to be done for every user and needs to be done for every machine (stored in a cookie or local storage).

Once you have switched from the parent account to a subaccount, your profile menu usually appears in the upper right corner will show the Display Name in a bubble colored with the chosen Color (below).

Note: you can switch back to the parent org by selecting Back to [ YOUR USERNAME ] in that same profile menu.

Preparation

  • Click on your username in the upper right corner to access your profile menu (left most of the menus in that corner)
  • Click on My Organization
  • In the Organizational Structure chart copy the account numbers and names of the subaccounts you wish to access

For each subaccount you need access to follow these steps:

  • Make sure you are in the parent account (there will not be a Back to [ YOUR USERNAME ] option in the profile menu).
  • Open your profile menu by clicking on your username in the upper right corner (left most of the menus in that corner).
  • Select Switch role
  • If this is your first time doing this in the browser/computer you will need to click on Switch Role again
  • Enter the account details
    • Account: (as copied in Preparation above)
    • Role: OrganizationAccountAccessRole
    • Display Name: user's choice - whatever makes sense to you
    • Color: user's choice - NOTE: this will be the color of your username in the header when you're logged into this subaccount
  • Click Switch Role
  • Note you are now in the child account, as indicated by the visual change of the profile menu button in the upper right corner.