Skip to content

Instantly share code, notes, and snippets.

View stampycode's full-sized avatar

Tim Stamp stampycode

View GitHub Profile
@stampycode
stampycode / push.php
Last active May 28, 2021 00:18
Create a ServiceWorker Push notification in PHP
<?php
/*
* If you get any part of this process wrong, Google gives the really helpful error message "invalid JWT provided".
*
* Mozilla (Firefox) gives a slightly just-as-useful error:
* {
* "code": 401, "errno": 109, "error": "Unauthorized",
* "more_info": "http://autopush.readthedocs.io/en/latest/http.html#error-codes",
* "message": "Request did not validate Invalid Authorization Header"
@stampycode
stampycode / docker_registry_browser.php
Last active October 17, 2018 13:36
Interactive browser for a Docker Registry API (v2)
<?php
/**
* Browse a specified (v2) Docker Registry, examine layers, extract useful data >.>
**/
ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED & ~E_WARNING);
$headers = [];
$type = isset($_GET['type']) ? $_GET['type'] : '_catalog';
$registry = (isset($_GET['registry'])) ? $_GET['registry'] : '';
@stampycode
stampycode / hammer.sh
Created October 11, 2017 18:46
hammer a Vault server with encrypt + decrypt requests
#!/bin/bash
set -e
ITERATIONS=2000
BYTES=3000
pppp() {
PLAINTEXT=$(head -c${BYTES} /dev/random |base64)
Verifying that "stampycode.id" is my Blockstack ID. https://onename.com/stampycode
@stampycode
stampycode / print_re.php
Created August 23, 2017 12:05
Recursion-safe php variable dumper
<?php
function print_re($data, $depth = 0, $max = 5) {
if(!headers_sent()) {
header('content-type: application/json');
}
$sp = str_repeat(" ", $depth);
if(is_numeric($data)) {
echo $data;
@stampycode
stampycode / regconnect.sh
Created June 23, 2017 10:45
Connect to Docker Registry and Fetch an Image without hard-coding credentials
#!/bin/bash
if [[ ! -f bin/docker-credential-registrycreds ]] ; then
[[ ! -d bin ]] && mkdir bin
cat > bin/docker-credential-registrycreds <<FFF
cat <<JSON
{
"ServerURL": "https://registry.local/v1",
"Username": "${DOCKER_USER}",
"Secret": "${DOCKER_PASS}"
}
@stampycode
stampycode / nginx.conf
Last active May 18, 2017 14:35
NGinx multi-docker-container reverse proxy config
events {
worker_connections 1024;
}
http {
resolver 127.0.0.11;
server {
server_name ~^(?<ctrn>[^\.]+)-(qa|dev)\.;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@stampycode
stampycode / bash_ssh_sudo.sh
Last active May 17, 2017 08:32
how to BASH SSH and SUDO
ssh ${SERVER} <<ENDSSH
cd ${REPO}
sudo -s -- <<SUDO
unset HISTFILE
[[ ! -d /root/.docker ]] && mkdir /root/.docker
[[ ! -e /root/.docker/config.json ]] && echo '{"credsStore": "registrycreds"}' > /root/.docker/config.json
[[ ! -d /root/bin ]] && mkdir /root/bin
echo > /root/bin/docker-credential-registrycreds <<<RRR
#!/bin/bash
@stampycode
stampycode / numberToWords.php
Last active May 1, 2017 13:55
Convert any positive integer to English
<?php
$_1to19 = [
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
@stampycode
stampycode / render.php
Last active April 4, 2017 12:34
Render binary data safely in html
<?php
$data = str_split($data, 72);
$color = '#888';
$placeholder = '.';
$repl = function($m) use (&$color, &$placeholder) {
$x = str_repeat($placeholder, strlen($m[0]));
return "<span style=\"background-color:{$color};\">{$x}</span>';
};
foreach($data as &$d) {
$d = str_replace(['<','>'], ['&lt;','&gt;'], $d);