Skip to content

Instantly share code, notes, and snippets.

@johnboxall
johnboxall / webdav.sh
Created February 1, 2023 19:25
How to interact with a Salesforce B2C Commerce instance over WebDAV
#!/bin/bash
# You can modify files on instance progmatically using the WebDAV protocol.
# First create an Account Manager API Client, noting its ID and secret.
# Then on your instance, grant that client access to the WebDAV API in WebDAV Client Permissions page.
# Finally, use the ID and secret to get an access token from Account Manager and use that to call WebDAV on your instance.
set -euo pipefail
HOST='YOUR-INSTANCE-HOSTNAME' # eg. zzrf-001.dx.commercecloud.salesforce.com
CLIENT='YOUR-AM-CLIENT-ID'
SECRET='YOUR-AM-CLIENT-SECRET'
#!/bin/bash
# Trusted Agent on Behalf of Demo:
#
# https://developer.salesforce.com/docs/commerce/commerce-api/references/shopper-login?meta=getTrustedAgentAuthorizationToken
# SLAS Client requires `sfcc.ta_ext_on_behalf_of` scope.
set -eou pipefail
CODE='kv7kzm78'
ORG='f_ecom_zzrf_001'
CLIENT='8eefe333-cac4-4cbe-ad1c-a7336693acbc'
@johnboxall
johnboxall / curl-bash-aliases.sh
Created May 14, 2019 19:06
cURL Bash Aliases
# Print the headers of URL.
alias curl-headers='curl ${CURL_ARGS[@]} --dump-header -'
# Print Time to First Byte of URL.
alias curl-ttfb='curl ${CURL_ARGS[@]} --write-out "%{time_starttransfer}\n"'
# Print bytes file size of URL.
alias curl-size='curl ${CURL_ARGS[@]} --write-out "%{size_download}\n"'
# https://ec.haxx.se/usingcurl-writeout.html
alias curl-timing='curl ${CURL_ARGS[@]} --write-out "
namelookup: %{time_namelookup} Start to name resolving
connect: %{time_connect} Start to TCP connect to host
@johnboxall
johnboxall / slack-cleanup.js
Last active February 2, 2017 06:17
Archive Slack channels with no messages in the last three months.
// Archive channels with no new messages in the last two months.
// Usage: npm install slack async
// SLACK_TOKEN=XYZ node slack-cleanup.js
// Get your Slack Token: https://api.slack.com/docs/oauth-test-tokens
"use strict"
const readline = require('readline')
const slack = require('slack')
const async = require('async')
@johnboxall
johnboxall / s3-find-objects-with-websiteredirectlocation.py
Created April 12, 2016 02:42
Example of using the `boto3` API to very slowly searching through a S3 bucket for objects which match a condition.
'''
Outputs JSON key / value pairs of objects in an S3 bucket which redirect.
* http://boto3.readthedocs.org/en/latest/guide/migrations3.html
* http://boto3.readthedocs.org/en/latest/reference/services/s3.html#S3.Object.get
'''
import csv
import json
import boto3
@johnboxall
johnboxall / google_oauth2.sh
Last active January 12, 2017 22:58
A script for generating refresh tokens to used to access Google APIs. Requires `python` + `jq`.
echo 'Google OAuth2'
echo ''
echo 'This script generates refresh token to retrieve an'
echo 'access token, to allows access to Google APIs :)'
echo ''
echo '--> Application Credentials: https://console.developers.google.com/projectselector/apis/credentials'
read -p 'Client ID: ' CLIENT_ID
read -p 'Client Secret: ' CLIENT_SECRET
echo ''
@johnboxall
johnboxall / tinypng.sh
Created December 22, 2014 23:30
TinyPNG script.
# Usage:
# ./tinypng.sh <filename> <filename> <filename>
#
# Upload the files to shrink and then save them locally under the same name.
# Only works with JPEG and PNG.
#
# Uses the TinyPNG API: https://tinypng.com/developers/reference
# Inspired by this Gist: https://gist.github.com/s4l1h/553d00b71d4ab14c17d9
#
# TODO:
@johnboxall
johnboxall / mock.py
Last active December 18, 2015 02:18
Not sure if httpbin is down or your tests are failing? Use `mock` to stub out your external calls!
import mock
import requests
import unittest
def get():
# Retrieves data from an external service eg. Twitter, Google
try:
return requests.get('http://external-service.com/')
except requests.RequestException:
return None
@johnboxall
johnboxall / web.go
Created June 3, 2013 15:21
Example of overriding `http.DefaultServeMux` of Go's HTTP server.
// http://stackoverflow.com/questions/16888285/overriding-gos-default-http-sever-redirect-behaviour/16891953?noredirect=1#16891953
package main
import (
"fmt"
"net/http"
)
type Handler struct {}
@johnboxall
johnboxall / gist:5695301
Created June 2, 2013 23:14
Go's default redirect behaviour seems to merge slashes in HTTP redirects. How can you override this behaviour?
package main
import (
"testing"
"net/http"
"net/http/httptest"
)
func TestMergeSlashes(t *testing.T) {
req, _ := http.NewRequest("GET", "http://foo.com/", nil)