Skip to content

Instantly share code, notes, and snippets.

View andrewodri's full-sized avatar
😍

Andrew Odri andrewodri

😍
View GitHub Profile
@andrewodri
andrewodri / encode-camtwist-profile-plist.sh
Created April 28, 2020 20:05
Encode a CamTwist profile for precisely sized window capture
#!/bin/bash
PROFILE_PLIST="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>\$archiver</key>
<string>NSKeyedArchiver</string>
<key>\$objects</key>
<array>
@andrewodri
andrewodri / encode-qwidget-geometry.sh
Last active May 4, 2020 17:12
Encode OBS projector geometry via Bash (or, QWidget::saveGeometry() refactored in Bash)
#!/bin/bash
if [[ "${1}" = "--help" || -z "${2}" ]]
then
echo -e 'Example usage:\n ./encode-qwidget-geometry.sh [PROJECTOR_WIDTH] [PROJECTOR_HEIGHT]'
exit 0
fi
MAIN_SCREEN_RESOLUTION=$(system_profiler -json SPDisplaysDataType | python -c "import sys,json;d=next(i for i in json.load(sys.stdin)['SPDisplaysDataType'][0]['spdisplays_ndrvs'] if 'spdisplays_main' in i);print d['_spdisplays_pixels']")
@andrewodri
andrewodri / decode-plist-data-property.sh
Last active March 3, 2021 09:15
Decode a base64 encoded binary data property from a plist file as XML
#!/bin/bash
if [[ "${1}" = "--help" || -z "${1}" ]]
then
echo -e 'Example usage:\n ./decode-plist-data-property.sh [PATH_TO_PLIST]'
exit 0
fi
perl -0777 -pe 's/\s//gm and s/.+<data>(.+)<\/data>.+/\1/g' "${1}" | base64 -D | plutil -convert xml1 - -o -
@andrewodri
andrewodri / HowToOTG.md
Created April 22, 2020 17:55 — forked from gbaman/HowToOTG.md
Simple guide for setting up OTG modes on the Raspberry Pi Zero

Raspberry Pi Zero OTG Mode

Simple guide for setting up OTG modes on the Raspberry Pi Zero - By Andrew Mulholland (gbaman).

The Raspberry Pi Zero (and model A and A+) support USB On The Go, given the processor is connected directly to the USB port, unlike on the B, B+ or Pi 2 B, which goes via a USB hub.
Because of this, if setup to, the Pi can act as a USB slave instead, providing virtual serial (a terminal), virtual ethernet, virtual mass storage device (pendrive) or even other virtual devices like HID, MIDI, or act as a virtual webcam!
It is important to note that, although the model A and A+ can support being a USB slave, they are missing the ID pin (is tied to ground internally) so are unable to dynamically switch between USB master/slave mode. As such, they default to USB master mode. There is no easy way to change this right now.
It is also important to note, that a USB to UART serial adapter is not needed for any of these guides, as may be documented elsewhere across the int

@andrewodri
andrewodri / enable-startup-chime.sh
Last active May 4, 2020 17:14
Enable the original startup chime on new Macs
#!/bin/bash
sudo nvram StartupMute=%00
@andrewodri
andrewodri / remove.sql
Created February 26, 2020 18:44
Remove all users from Wordpress Multisite that do not belong to other sites
SET @site_id = 1;
SELECT user_id
FROM wp_usermeta
WHERE meta_key = CONCAT('wp_', @site_id, '_capabilities')
AND meta_value LIKE 'a:1:{s%'
HAVING user_id NOT IN (
SELECT user_id
FROM wp_usermeta
WHERE meta_key LIKE CONCAT('wp_', @site_id, '_capabilities')
@andrewodri
andrewodri / Dockerfile
Last active December 22, 2023 20:56
Connect Fargate instance to SSM Session Manager
FROM debian:10-slim
RUN apt-get update -y && \
apt-get install -y awscli curl gnupg && \
apt-key adv --fetch-keys "https://nginx.org/keys/nginx_signing.key" && \
echo "deb http://nginx.org/packages/debian buster nginx" > /etc/apt/sources.list.d/nginx.list
RUN curl --silent --show-error --location --output /tmp/amazon-ssm-agent.deb "https://s3.us-east-1.amazonaws.com/amazon-ssm-us-east-1/latest/debian_amd64/amazon-ssm-agent.deb" && \
dpkg -i /tmp/amazon-ssm-agent.deb
@andrewodri
andrewodri / init.sh
Last active November 16, 2020 04:24
Launch Chromium on macOS with CLI arguments
#!/bin/sh
cat > /Applications/Chromium.app/Contents/MacOS/Chromium.sh <<EOF
#!/bin/sh
exec /Applications/Chromium.app/Contents/MacOS/Chromium --ignore-certificate-errors
EOF
chmod 755 /Applications/Chromium.app/Contents/MacOS/Chromium.sh
@andrewodri
andrewodri / init.sh
Created January 30, 2020 19:56
HomeBridge System Services
#!/bin/bash
rsync -avz -e 'ssh' --exclude='assets' --exclude='node_modules' ./ pi@raspberrypi:~/homebridge/
rsync -avz -e 'ssh' ~/.ssh/id_rsa.pub pi@raspberrypi:~/.ssh/authorized_keys
ssh pi@raspberrypi
chmod 600 ~/.ssh/authorized_keys
mkdir ~/.homebridge
cd homebridge
npm install
@andrewodri
andrewodri / dotenv-to-ssm.sh
Last active July 27, 2023 16:18
Get and set SSM parameters from Bash and/or .env
#!/bin/bash
# set_parameter() { aws ssm put-parameter --overwrite --name "${1}" --value "${2}" --type String --query "''" --output text; }
# set_secure_parameter() { aws ssm put-parameter --overwrite --name "${1}" --value "${2}" --type SecureString --query "''" --output text; }
set_parameter() { aws ssm put-parameter --overwrite --query "''" --output text --cli-input-json '{"Name":"'${1}'","Value":"'$(echo -ne "${2}" | perl -pe 's/(\\(\\\\)*)/$1$1/g; s/(?!\\)(["\x00-\x1f])/sprintf("\\u%04x",ord($1))/eg;')'","Type": "String"}'; }
set_secure_parameter() { aws ssm put-parameter --overwrite --query "''" --output text --cli-input-json '{"Name":"'${1}'","Value":"'$(echo -ne "${2}" | perl -pe 's/(\\(\\\\)*)/$1$1/g; s/(?!\\)(["\x00-\x1f])/sprintf("\\u%04x",ord($1))/eg;')'","Type": "SecureString"}'; }
if [[ "${1}" = "-h" || "${1}" = "--help" || ( -z "${1}" && -z "${2}" ) ]]
then
echo -e 'Example usage:\n ./dotenv-to-ssm.sh [INPUT_FILE] [SSM_PARAMETER_PREFIX]'