Skip to content

Instantly share code, notes, and snippets.

View bradymholt's full-sized avatar

Brady Holt bradymholt

View GitHub Profile
@bradymholt
bradymholt / index.html
Last active November 22, 2022 13:23
Backup textarea in localStorage
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<script>
const issueId = window.location.search; // TODO: clean up parsing of issue id
@bradymholt
bradymholt / index.js
Created September 5, 2022 23:38
Download usage information from Colorado Springs Utilities (csu.org)
#!/usr/bin/env npx jsh
usage(`
Usage:
${$0} service_type
Examples:
${$0} ELECTRICITY
${$0} WATER
Downloads usage information from Colorado Springs Utilities
@bradymholt
bradymholt / presigned.rb
Last active May 9, 2022 18:35
Generate presigned S3 upload URL with aws-sdk-s3 in Ruby
resource = Aws::S3::Resource.new(client: Aws::S3::Client.new)
url = resource.bucket('my-bucket').object('myfolder/foo.txt').presigned_url(:put)
put url
@bradymholt
bradymholt / require-or-install.js
Last active November 7, 2022 13:59
Require or Install NPM package on demand
/**
* This function will check to see if a module is installed and if not will run `npm install` to install all dependencies.
* Then, the module will be required and returned.
* The intended usage is for a consumer to be able to require a module even if npm install has not been run beforehand.
* Source: https://stackoverflow.com/a/53377794/626911
*
* Example usage:
* const requireOrInstall = require("./helpers/require-or-install");
* axios = await requireOrInstall("axios");
*
@bradymholt
bradymholt / delete_all_disabled_workflow_runs.sh
Created January 12, 2022 18:18
Delete all disabled GitHub Action workflow runs
# Source :https://stackoverflow.com/a/67000032/626911
org=<your org>
repo=<your repo>
# Get workflow IDs with status "disabled_manually"
workflow_ids=($(gh api repos/$org/$repo/actions/workflows | jq '.workflows[] | select(.["state"] | contains("disabled_manually")) | .id'))
for workflow_id in "${workflow_ids[@]}"
do
echo "Listing runs for the workflow ID $workflow_id"
git-move() {
echo "Moving commits on current branch to a new branch..."
# This is useful if commits were mistakenly made on master and need to be move to a new branch.
# $1 - New target branch name
if [ -z "$1" ]; then echo "New branch name required!"; exit 0; fi
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Moving local commits on ${CURRENT_BRANCH} to $1"
git branch ${1} && git reset --hard origin/${CURRENT_BRANCH} && git checkout ${1}
}
@bradymholt
bradymholt / delete_draft_releases.sh
Created September 2, 2020 15:22
Delete GitHub draft releases
TOKEN=123; curl -Ss -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
"https://api.github.com/repos/username/repo_name/releases?per_page=100&page=1" \
| jq -r '.[] | select(.draft == true) | .id' \
| xargs -I {} -L 1 \
curl -L -H "Authorization: token $TOKEN" -X DELETE "https://api.github.com/repos/username/repo_name/releases/{}"
@bradymholt
bradymholt / pollster.groovy
Created May 28, 2020 02:30
“Pollster” - A SmartThings Polling Daemon
/**
* Pollster - The SmartThings Polling Daemon.
*
* Pollster works behind the scenes and periodically calls 'poll' or
* 'refresh' commands for selected devices. Devices can be arranged into
* three polling groups with configurable polling intervals down to 1 minute.
*
* Please visit [https://github.com/statusbits/smartthings] for more
* information.
*
@bradymholt
bradymholt / gist:fc8ec86dbc00098ee4622e1dbe69776c
Created December 22, 2019 01:06
Create PostgreSQL user and give permissions to objects in database
SELECT set_config('current.user', 'my_user', false);
SELECT set_config('current.dbname', 'my_database', false);
CREATE USER current_setting('current.user');
-- Give CREATE, CONNECT, TEMPORARY permissions
GRANT ALL PRIVILEGES ON DATABASE current_setting('current.dbname') TO current_setting('current.user');
-- Grant INSERT, UPDATE, DELETE access to all EXISTING tables in public schema
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO current_setting('current.user');
@bradymholt
bradymholt / gist:15d210f3eee4637d3a20ca3f74d9cc6a
Created November 22, 2019 18:05
Delete Private GitHub Docker Registry packages
# Find latest version of packages
curl -X POST \
-H "Accept: application/vnd.github.package-deletes-preview+json" \
-H "Authorization: bearer $GITHUB_API_TOKEN" \
-d '{"query":"query { repository(owner:\"johndoe\", name:\"myepo\") { registryPackagesForQuery(first:10) { edges { node { latestVersion { id } } } } } }"}' \
https://api.github.com/graphql
# Example output from above command
# {"data":{"repository":{"registryPackagesForQuery":{"edges":[{"node":{"latestVersion":{"id":"MDE01234523233"}}}]}}}}