Skip to content

Instantly share code, notes, and snippets.

View douglascayers's full-sized avatar

Doug Ayers douglascayers

View GitHub Profile
@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 / delete-orphaned-local-branches.sh
Last active September 6, 2023 14:52
Delete local branches that no longer exist on a remote
#!/bin/bash
set -e
# Delete all local branches whose remote branch no longer exists.
git branch -v | grep -E "[0-9a-zA-Z]{7} \[gone\]" | awk '{ print $1 }' | xargs git branch -D $1
# The commmand explained:
#
@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-cascade-backmerge.sh
Last active August 1, 2023 02:23
Iteratively backmerges pull requests in sequence using the GitHub and Git CLIs
#!/bin/bash
# For when you have a train of pull requests lined up like A -> B -> C -> D
# and you make a change to base D that you now want backmerged to C then B then A.
set -e
# ----------------------------------------------------------------------------
# List the pull request number (e.g. 42) in order that the backmerges
@douglascayers
douglascayers / EmailQuickActionDefaultsHandler.java
Created November 4, 2016 20:45
Apex class to auto-default values of Email when using Case Feed Email Composer. Setup | Case | Support Settings
/**
* https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_QuickAction_QuickActionDefaultsHandler.htm
*/
public class EmailQuickActionDefaultsHandler implements QuickAction.QuickActionDefaultsHandler {
public void onInitDefaults( QuickAction.QuickActionDefaults[] actionDefaults ) {
for ( QuickAction.QuickActionDefaults actionDefault : actionDefaults ) {
System.debug( actionDefault );
@douglascayers
douglascayers / ContentHubTest1.cls
Last active July 14, 2023 10:04
ConnectApi.ContentHub examples of adding and updating files in external data source (e.g. Google Drive or SharePoint Online) before Summer '17
/**
* Developed by Doug Ayers (douglascayers.com)
* Org62 Case 16584902
* GUS W-006274
*
* This test creates a file "new document.txt" with contents "Hello World"
* in an external data source, such as Google Drive or SharePoint Online.
*
* Despite being a unit test it has real side effects in the external system.
*
@douglascayers
douglascayers / vCalendarPage.html
Last active July 13, 2023 21:59
Create .ics Calendar Event in Visualforce
<!--
Simple proof-of-concept to create a .ics calendar event with visualforce.
Inspired by Natalie Regier @gnatrae
This example uses url parameters to set the details of event.
You could create a custom button that invokes this page, like:
https://<your-salesforce-domain>/apex/vCalendarPage?start={!TEXT(Obj.StartDate__c)}&end={!TEXT(Obj.EndDate__c)}&subject=Event from Visualforce&description=This .ics event created with visualforce&location=The Cloud
An example with literal values you can copy & paste in your browser:
https://<your-salesforce-domain>/apex/vCalendarPage?start=20140524T140000&end=20140524T153000&subject=Event from Visualforce&description=This .ics event created with visualforce&location=The Cloud
@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"