Public
Edited
Aug 3, 2023
Insert cell
Insert cell
viewof CONFIG = Inputs.form({
who: Inputs.text({
label: 'Who is using this?',
value: 'th',
}),
why: Inputs.text({
label: 'Why are you running this?',
value: 'jupyter',
}),
where: Inputs.text({
label: 'Where are you running this?',
value: 'daventry',
}),
what: Inputs.text({
label: 'What are you exactly running?',
value: 'tinyproxy',
}),
})
Insert cell
viewof BIND = {
const { who, why, what, where } = CONFIG;

const id = who + '/' + why + '/' + where + '/' + what;
const [ip0, ip1, ip2, ip3, p1, p2] = hash2parts(sha256(id));
return Inputs.form({
id: Inputs.text({
label: 'id',
value: id,
}),
bind: Inputs.text({
label: 'bind',
value: `${ip0}.${ip1}.${ip2}.${ip3}`,
}),
port: Inputs.text({
label: 'port',
value: `${p1<<8|p2}`,
}),
});
function *hash2parts(hash) {
const arr = hex2arr(hash);
const mask0 = new Uint8Array([0xFF, 0x00, 0x00, 0x00, 0x80, 0x00]);
const mask1 = new Uint8Array([0x7F, 0x00, 0x00, 0x00, 0x80, 0x00]);
for (let i=0, n=mask0.length; i<n; ++i) {
arr[i] &= ~mask0[i];
arr[i] |= mask1[i];
yield arr[i];
}
}
// Thanks https://stackoverflow.com/a/50868276
function hex2arr(hexString) {
return Uint8Array.from(hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
}

// Thanks https://stackoverflow.com/a/50868276
function arr2hex(bytes) {
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
}
}
Insert cell
import { sha256 } from '@player1537/utilities'
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more