Skip to content

Instantly share code, notes, and snippets.

John Boxall johnboxall

Block or report user

Report or block johnboxall

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View curl-bash-aliases.sh
# 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 Feb 2, 2017
Archive Slack channels with no messages in the last three months.
View slack-cleanup.js
// 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 Apr 12, 2016
Example of using the `boto3` API to very slowly searching through a S3 bucket for objects which match a condition.
View s3-find-objects-with-websiteredirectlocation.py
'''
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 Jan 12, 2017
A script for generating refresh tokens to used to access Google APIs. Requires `python` + `jq`.
View google_oauth2.sh
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 Dec 22, 2014
TinyPNG script.
View tinypng.sh
# 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 Dec 18, 2015
Not sure if httpbin is down or your tests are failing? Use `mock` to stub out your external calls!
View mock.py
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 Jun 3, 2013
Example of overriding `http.DefaultServeMux` of Go's HTTP server.
View web.go
// 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 Jun 2, 2013
Go's default redirect behaviour seems to merge slashes in HTTP redirects. How can you override this behaviour?
View gist:5695301
package main
import (
"testing"
"net/http"
"net/http/httptest"
)
func TestMergeSlashes(t *testing.T) {
req, _ := http.NewRequest("GET", "http://foo.com/", nil)
View preparser.html
<!doctype html>
<html>
<head>
<script src="http://httpbin.org/delay/10"></script>
<script>document.write("<plaintext>");</script>
<script src="preparsed.js"></script>
<title>Pre-Parser Test</title>
</head>
<body>
<p>Check the wire level requests generated by this page.<p>
View recover.html
<html>
<head>
<script>
/**
* In 1s, `onError` will be called to 'recover' the original document.
*/
onError = function() {
var s;
while (s = document.scripts[0]) s.parentNode.removeChild(s);
You can’t perform that action at this time.