Skip to content

Instantly share code, notes, and snippets.

@zapthedingbat
zapthedingbat / oneid.ts
Created April 4, 2023 13:00
Calling userinfo - OneID
export async function getAuthorizeUrl({redirectUri}:GetAuthorizeUrlOptions){
const authorizeUrl = new URL("https://controller.sandbox.myoneid.co.uk/v2/authorize");
authorizeUrl.searchParams.set("client_id", process.env.ONEID_CLIENT_ID);
authorizeUrl.searchParams.set("redirect_uri", redirectUri!);
authorizeUrl.searchParams.set("response_type", "code");
authorizeUrl.searchParams.set("scope", "product:identity_proof");
//TODO: Store state in client storage
authorizeUrl.searchParams.set("state", "state");
return authorizeUrl.toString();
}
@zapthedingbat
zapthedingbat / motion_switch_sun.yaml
Created February 5, 2023 12:41
Home Assistant Blueprint: Motion-activated switch with sunset condition
blueprint:
name: Motion-activated switch with sun condition
description: Turn on a switch when motion is detected during night.
domain: automation
input:
motion_entity:
name: Motion Sensor
selector:
entity:
domain: binary_sensor
@zapthedingbat
zapthedingbat / README.md
Created November 3, 2020 12:01
Pirates Engineering Challenge

Pirates

You are shipwrecked on a desert island with nothing but your own company and a solar powered laptop with the Node.js, Golang and Python3 or you prefered development environment installed. Without internet access you're driven, by boredom to scratch in the sand where you find a compass and a scroll left behind by some algorithmically minded pirates. The scroll has a set of instructions of how to find hidden treasure and a working satellite phone. You decide to follow them and escape the island so you can return home to the good weather and political stability of the island you live.

@zapthedingbat
zapthedingbat / morse.js
Created November 3, 2020 11:56
Parse morse code
process.argv
.slice(2)
.map(b => [...b].reduce((a, b) => 2 * a + +("." == b ? 1 : 2), 0))
.map(
a => "-etianmsurwdkgohvf-l-pjbxcyzq--54-3---2--+----16=/-----7---8-90"[a]
)
.join("")
@zapthedingbat
zapthedingbat / unicode-tld.html
Created November 3, 2020 11:39
Example of using unicode characters host tld
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<a href="http://www.example.cₒm">test</a>
</body>
@zapthedingbat
zapthedingbat / vendor-ids.js
Last active November 27, 2020 12:30
Compression and decompression for Google's appallingly inefficient additional consent string
/*
|| Compression and decompression using a combination of
|| Variable-length Quantity(VLQ) and Delta encoding to encode the "Additional
|| Consent" (AC) string required by Google’s Additional Consent Mode technical
|| specification https://support.google.com/admanager/answer/9681920?hl=en
||
|| vendorIds.compress(input)
|| input - A string of "." delimited list if ids in ascending order.
||
|| vendorIds.decompress(input)
@zapthedingbat
zapthedingbat / poll-xid.js
Created June 25, 2020 07:41
Poll for the Conde Nast XID and pass it into permutive
(function () {
var interval = setInterval(function () {
var [, xid] = (document.cookie.match(/CN_xi_d=([^;]+)/) || []);
xid = xid || window._4d && window._4d.user && window._4d.user.xid;
if (xid) {
permutive.identify([
{
id: xid,
tag: 'xid'
}
console.log(process.argv.slice(2).map(b=>[...b].reduce((a,b)=>2*a+("."==b?1:2),0)).map(a=>"-etianmsurwdkgohvf-l-pjbxcyzq--54-3---2--+----16=/-----7---8-90"[a]).join(''))
@zapthedingbat
zapthedingbat / watercolors.js
Created November 13, 2019 14:24
Generate watercolor style blobs: Inspired by tyler hobbs's generative watercolors- https://tylerxhobbs.com/
(function(doc) {
const TWO_PI = Math.PI * 2;
const HALF_PI = Math.PI / 2;
const RADIUS_SCALE = 0.05;
const RADIUS_SD = 15;
const POLYGON_SIDES = 5;
const POSITION_SD = 0.04;
const BASE_DEFORMATIONS = 3;
const LAYER_DEFORMATIONS = 3;
const LAYERS = 40;
@zapthedingbat
zapthedingbat / number-bytes.js
Created May 14, 2019 19:30
converting between numbers and bytes in javascript
function bitLength(number) {
return Math.floor(Math.log2(number)) + 1;
}
function byteLength(number) {
return Math.ceil(bitLength(number) / 8);
}
function toBytes(number) {
if (!Number.isSafeInteger(number)) {