Skip to content

Instantly share code, notes, and snippets.

View cmbuckley's full-sized avatar

Chris Buckley cmbuckley

View GitHub Profile
<?php
// run all the tests
abstract class TestSuite {
public function __construct() {
$ref = new ReflectionClass($this);
$methods = $ref->getMethods(ReflectionMethod::IS_PUBLIC);
$output = '';
foreach ($methods as $method) {
if ($method->getDeclaringClass() == $ref) {
@cmbuckley
cmbuckley / akamai.sh
Last active June 24, 2020 11:10
Akamai hosts updater
#!/bin/bash
domain=$1
origin="example-origin.net"
file=/etc/hosts
fqdn=
if [ $# -lt 1 ]; then
echo "Usage: $(basename "$0") DOMAIN [{production|staging|origin|off}]" >&2
exit 1
@cmbuckley
cmbuckley / cert.sh
Last active October 27, 2017 10:49
Crete a CSR and split the intermediates from a CRT chain
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Usage: $(basename "$0") DOMAIN [ALTERNATIVES]..." >&2
exit 1
fi
# first arugment is the CN
domain=${1//\*/wild}
config="$domain.cnf"
@cmbuckley
cmbuckley / bucket.awk
Last active May 16, 2018 11:13
Group a list of numbers into discrete buckets
# Round to the nearest multiple of "size"
function bucket(a) {
return int((a + (size/2)) / size) * size;
}
{ buckets[bucket($1)]++ }
END {
for (b in buckets) {
print b, buckets[b]
<?php
header('Location: https://setcookie.net');
<html>
<body>
<script id="script">
var window = {
location: {
hostname: 'malicious site'
}
};
alert(window.location.hostname);
@cmbuckley
cmbuckley / san.sh
Last active October 27, 2017 10:35
List the SAN extension domain names contained in an SSL cert on a given domain
#!/bin/bash
domain=$1
[[ $domain != *":"* ]] && domain="$domain:443"
openssl s_client -connect $domain 2>/dev/null </dev/null \
| openssl x509 -noout -text \
| grep -A1 'Subject Alternative Name:' \
| awk 'BEGIN{RS=",";FS=":"}{print $NF}'
@cmbuckley
cmbuckley / woop.html
Last active December 27, 2017 09:45
Decommission the Thing page
<html>
<head>
<script>
document.addEventListener('keypress', function (e) {
if (e.charCode == 13) {
document.body.classList.add('flash');
document.querySelector('.warning').innerText = 'Bye bye thing!';
var a = new Audio('http://soundbible.com/mp3/Woop%20Woop-SoundBible.com-198943467.mp3');
a.play();
a.addEventListener('ended', function() {
@cmbuckley
cmbuckley / contentful-travis.php
Created February 7, 2018 16:31
Webhook from Contentful to Travis
<?php
$token = $_SERVER['HTTP_AUTHORIZATION'];
$slug = urlencode($_SERVER['HTTP_X_TRAVIS_REPOSITORY']);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => "https://api.travis-ci.org/repo/$slug/requests",
CURLOPT_POSTFIELDS => json_encode([
'request' => [
@cmbuckley
cmbuckley / mem.js
Created April 9, 2018 15:09
Basic Node.js Memory Consumption (https://stackoverflow.com/a/45904781/283078)
let maxConsumption = 0;
process.nextTick(() => {
let memUsage = process.memoryUsage();
if (memUsage.rss > maxConsumption) {
maxConsumption = memUsage.rss;
}
});
process.on('exit', () => {