Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am michaelphipps on github.
  • I am michaelphipps (https://keybase.io/michaelphipps) on keybase.
  • I have a public key whose fingerprint is FAE5 1CEC F182 EB36 BB3E 4BAD AFC5 0520 8CDF C98D

To claim this, I am signing this object:

@michaelphipps
michaelphipps / apiexplorer.html
Created December 7, 2016 01:23
JSON API Explorer
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="" name="description">
<meta content="" name="author">
<link href="../../favicon.ico" rel="icon">
<title>JSON API Explorer</title><!-- Latest compiled and minified CSS -->
@michaelphipps
michaelphipps / web-font-not-working.md
Last active May 27, 2018 06:46
How to get web fonts working correctly in your server environment.

If you have web fonts on a subdomain seperate to the domain you are calling them, usual advice is to place the following into the .htaccess file for the subdomain

<IfModule mod_headers.c>
  <FilesMatch “.(eot|otf|ttc|ttf|woff|woff2)$”>
    Header set Access-Control-Allow-Origin “*”
  </FilesMatch>  
</IfModule>
@michaelphipps
michaelphipps / how-to-pass-data-to-partials-in-handelbars-php.md
Last active October 23, 2020 11:57
How to pass data to partials in Handlebars.php

How to pass data to partials in Handlebars.php

The way data is passed in partials in salesforce/handlebars-php isn't the same as it is over at handlebars.js

Inspired by this issue

In this gist, we have a dataset of names that we want to display on a page. We are using a partial to format the display of the names to avoid writing repetitive code.

[
    "names"=>[
@michaelphipps
michaelphipps / ably-jwt-authentication-send-json.php
Created March 6, 2021 08:24
Send a JSON message with Ably.com using JWT Authentication in PHP without using the official Ably PHP SDK.
<?php
// $ composer require lcobucci/jwt
require __DIR__ . '/vendor/autoload.php';
use Lcobucci\JWT\Configuration;
use Lcobucci\JWT\Signer\Key\InMemory;
use Lcobucci\JWT\Signer\Hmac\Sha256;
@michaelphipps
michaelphipps / getPublicKeyFromPrivateKey.js
Created March 18, 2023 08:22
ECDSA how to derive public key from private key using web crypto api javascript
// Inspired/copied from : https://stackoverflow.com/questions/72151096/how-to-derive-public-key-from-private-key-using-webcryptoapi
async function getPublicKeyFromPrivateKey(privateKey) {
const jwkPrivate = await crypto.subtle.exportKey("jwk", privateKey);
delete jwkPrivate.d; // this trick makes the jwk a public key!
jwkPrivate.key_ops = ["verify"];
const publicfromprivate = await crypto.subtle.importKey("jwk", jwkPrivate, {name: "ECDSA", namedCurve: "P-256"}, true, ["verify"]);
const publicKey = await crypto.subtle.exportKey('spki', publicfromprivate);
return publicKey;
}
@michaelphipps
michaelphipps / base64url.js
Created March 18, 2023 08:26
Base64url encoding and decoding functions
const base64url = {
encode: (data) => {
let base64 = btoa(String.fromCharCode(...data));
return base64.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
},
decode: (base64url) => {
let base64 = base64url.replace(/-/g, '+').replace(/_/g, '/');
while (base64.length % 4) base64 += '=';
return Uint8Array.from(atob(base64), c => c.charCodeAt(0));
}