Skip to content

Instantly share code, notes, and snippets.

View douglascayers's full-sized avatar

Doug Ayers douglascayers

View GitHub Profile
@douglascayers
douglascayers / pubsub-service.mock.ts
Last active March 11, 2024 17:40
PubSubService with RXJS
import { Observable, Subject, filter } from 'rxjs';
import { PubSubMessage, PubSubService, PubSubTopic } from '../pubsub.types';
export class PubSubServiceMock implements PubSubService {
public readonly subject$ = new Subject<PubSubMessage<PubSubTopic>>();
public readonly publishSpy = jest.fn();
public readonly streamSpy = jest.fn();
public publish<T extends PubSubTopic>(message: PubSubMessage<T>): void {
@douglascayers
douglascayers / create-commit-check.sh
Created September 26, 2023 18:54
Use GitHub CLI to create a commit status
OWNER="some_owner"
REPO="some_repo"
COMMIT="some_sha"
gh api \
repos/${OWNER}/${REPO}/statuses/${COMMIT} \
-X POST \
-F state=success \
-F description="Completed" \
-F context=ci/release
@douglascayers
douglascayers / benchmark.ts
Created September 6, 2023 22:22
Benchmark an operation
function benchmarkLoop(iterations: number, operation: () => void): void {
const times: number[] = [];
for (let i = 0; i < iterations; i++) {
const start = performance.now();
operation();
const end = performance.now();
times.push(end - start);
@douglascayers
douglascayers / aws-iot-add-thing-to-group.sh
Created August 7, 2023 22:42
Adds a AWS IOT thing to a group
#!/bin/bash
set -e
THING_GROUP_NAME="changeme"
THING_NAMES=(
"thing1"
"thing2"
)
@douglascayers
douglascayers / github-merge-prs-into-branch.sh
Last active September 25, 2023 13:23
Iteratively merges into local branch a list of pull requests in sequence using the GitHub and Git CLIs
#!/bin/bash
set -e
# Name of the branch to merge all the pull requests into.
MERGE_BRANCH="staging"
# Name of the branch to hard reset to before merging others into it.
RESET_BRANCH="master"
@douglascayers
douglascayers / s3-rename-folder.sh
Created May 25, 2023 21:29
Move S3 files from one folder to another using AWS CLI
# https://stackoverflow.com/questions/21184720/how-to-rename-files-and-folder-in-amazon-s3
BUCKET="your-bucket"
OLD_FOLDER="changeme"
NEW_FOLDER="changeme"
aws s3 --recursive mv s3://${BUCKET}/${OLD_FOLDER} s3://${BUCKET}/${NEW_FOLDER}
@douglascayers
douglascayers / delete-sagemaker-experiments.py
Created May 24, 2023 21:43
Delete AWS SageMaker Experiments
# Install dependencies
# - pip install sagemaker
#
# https://pypi.org/project/sagemaker/
# https://docs.aws.amazon.com/sagemaker/latest/dg/experiments-cleanup.html
from sagemaker.experiments.experiment import Experiment
# In SageMaker Studio:
# 1. Click "Experiments"
@douglascayers
douglascayers / update-cli-tools.sh
Created April 12, 2023 21:28
⚡️ Update various CLI tools
#!/usr/bin/env zsh
# Update Heroku CLI
# https://devcenter.heroku.com/articles/heroku-cli
echo "Updating heroku..."
heroku login
heroku update
heroku autocomplete --refresh-cache
# Update Salesforce CLI
@douglascayers
douglascayers / convert.rb
Created March 13, 2023 16:14
Ruby script to confirm csv if IP ranges to IP login ranges for Salesforce profile
require "CSV"
items = []
# The ips.csv data comes from copying the HTML table of IP ranges
# from the Salesforce profile in the UI from the org you want to copy.
# Workaround when you don't have metadata api access to the org to copy from.
CSV.foreach("ips.csv") do |row|
items << <<~XML
<loginIpRanges>