Skip to content

Instantly share code, notes, and snippets.

@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 / 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'
from google.appengine.api import images
from google.appengine.api import urlfetch
from google.appengine.ext import webapp
from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
PAYLOAD_TEMPLATE = \
"""--==boundary\r
Content-Disposition: form-data; name="file"; filename="%s"\r
#!/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 / dns.py
Created August 15, 2011 21:57
Twisted DNS server!
# http://notmysock.org/blog/hacks/a-twisted-dns-story.html
# http://blog.inneoin.org/2009/11/i-used-twisted-to-create-dns-server.html
# twistd -y dns.py
import socket
from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor
from twisted.names import dns
from twisted.names import client, server
@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 / 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 / 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 / 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