Skip to content

Instantly share code, notes, and snippets.

View douglascayers's full-sized avatar

Doug Ayers douglascayers

View GitHub Profile
@douglascayers
douglascayers / docker-destroy.sh
Last active April 3, 2024 16:19
🗑 Delete all docker services, containers, images, and volumes
#!/usr/bin/env zsh
# Exit when any command fails
set -e
# https://docs.docker.com/engine/reference/commandline
SCRIPT_NAME=$(basename ${0})
DELETE_BUILDER_CACHE=0
@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 / tasks.json
Last active January 30, 2024 22:27
Simple tasks for Visual Studio Code to deploy/retrieve/delete the currently opened file, or an entire folder, using Salesforce CLI force:source commands.
{
"version": "2.0.0",
"tasks": [
{
"label": "SFDX: Deploy Current File",
"type": "shell",
"command": "sfdx",
"args": [
"force:source:deploy",
"--sourcepath",
@douglascayers
douglascayers / InvocableApexTemplate.cls
Created January 4, 2018 08:15
Example structure of an invocable apex class
public with sharing class InvocableApexTemplate {
@InvocableMethod(
label = 'Name as displayed in Process Builder'
description = 'Tooltip as displayed in Process Builder'
)
public static List<Response> execute( List<Request> requests ) {
List<Response> responses = new List<Response>();
@douglascayers
douglascayers / github-copy-labels.sh
Last active December 22, 2023 08:16
Export and import GitHub labels between projects by running bash script with jq and curl. Uses GitHub REST API. Requires personal access token.
# This script uses the GitHub Labels REST API
# https://developer.github.com/v3/issues/labels/
# Provide a personal access token that can
# access the source and target repositories.
# This is how you authorize with the GitHub API.
# https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line
GH_TOKEN="YOUR_TOKEN"
# If you use GitHub Enterprise, change this to "https://<your_domain>/api/v3"
@douglascayers
douglascayers / ApprovalRequestComments.html
Last active October 20, 2023 05:09
Approval Request Comments in Visualforce Email Template.
<apex:component controller="ApprovalRequestCommentsController" access="global">
<apex:attribute name="relatedToId" assignTo="{!targetObjectId}" type="String" description="ID of the record whose last approval comments to retrieve"/>
<apex:outputText value="{!comments}"/>
</apex:component>
@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 / 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 / async-poller.ts
Created December 23, 2019 05:25
Typescript async polling function. Simple proof-of-concept before I adopted the p-retry npm module.
/**
* The function you pass to `asyncPoll` should return a promise
* that resolves with object that satisfies this interface.
*
* The `done` property indicates to the async poller whether to
* continue polling or not.
*
* When done is `true` that means you've got what you need
* and the poller will resolve with `data`.
*
@douglascayers
douglascayers / github-export-labels.js
Last active September 14, 2023 15:30
Export and import GitHub labels between projects by running JavaScript in the browser console to automate clicks.
/**
* Inspired by @MoOx original script: https://gist.github.com/MoOx/93c2853fee760f42d97f
* Adds file download per @micalevisk https://gist.github.com/MoOx/93c2853fee760f42d97f#gistcomment-2660220
*
* Changes include:
* - Get the description from the `title` attribute instead of `aria-label` (doesn't exist anymore)
* - Use style.backgroundColor and parse the rgb(...) to hex (rather than regex parsing of 'style' string)
* - Downloads labels to a JSON file named after the webpage to know which GitHub repo they came from.
*
* Last tested 2019-July-27: