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 / 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 / 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);
@stampycode
stampycode / How Strong Is Your Generated Key.php
Last active February 20, 2017 15:40
How Strong Is Your PRNG Generated Key
| Example Key | Key Alphabet | Number of Possible Combinations
-------------------------------------------------------------------------------------------------------------------------
10**3 | 976 | Numerical | 1000
16**3 | 6d2 | Hexadecimal | 4096
10**4 | 9766 | Numerical | 10000 // eg. Bank Card Pin number
26**3 | bsa | Alphabetical | 17576
16**4 | 6d20 | Hexadecimal | 65536
10**5 | 97667 | Numerical | 100000
62**3 | bSA | a-zA-Z0-9 | 238328
64**3 | bSA | Base64 | 262144
@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'] : '';