Public
Edited
Mar 4
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
now
Insert cell
Insert cell
unixDays = now / 86400000
Insert cell
Insert cell
Insert cell
yd2d = (y, d) => y * 365 + Math.floor(y / 4) - Math.floor(y / 100) + Math.floor(y / 400) + d
Insert cell
Insert cell
unixEpoch = yd2d(1969, 306)
Insert cell
Insert cell
newYearDiff = yd2d(newYear, 0) - unixEpoch
Insert cell
Insert cell
nowYearDiff = yd2d(nowYear, 0) - unixEpoch
Insert cell
Insert cell
countdown = newYearDiff - unixDays
Insert cell
Insert cell
Insert cell
doty = Math.abs(nDays - countdown)
Insert cell
Insert cell
nowYearDate = `${nowYear}${unixDays < nowYearDiff ? "-" : "+"}${doty.toFixed(5).padStart(9, "0")}`
Insert cell
Insert cell
newYearDate = `${newYear}${unixDays < newYearDiff ? "-" : "+"}${Math.abs(countdown).toFixed(5).padStart(9, "0")}`
Insert cell
Insert cell
Insert cell
Insert cell
time = unixDays % 1
Insert cell
Insert cell
time.toFixed(5).slice(1)
Insert cell
(1 - time).toFixed(5).slice(1)
Insert cell
Insert cell
Insert cell
function dote2snap(dote) {
const cote = Math.floor((
dote >= 0 ? dote
: dote - 146096
) / 146097),
dotc = dote - cote * 146097,
yotc = Math.floor((dotc
- Math.floor(dotc / 1460)
+ Math.floor(dotc / 36524)
- Math.floor(dotc / 146096)
) / 365);
return [
yotc + cote * 400,
dotc - (yotc * 365
+ Math.floor(yotc / 4)
- Math.floor(yotc / 100)
)]}
Insert cell
`${yd[0]}+${yd[1].toFixed(5).padStart(9, "0")}`
Insert cell
nowYearDate
Insert cell
decYear = dote2snap(Date.now() / 864e5 + unixEpoch)[0]
Insert cell
yd = dote2snap(unixDays + unixEpoch)
Insert cell
Insert cell
Insert cell
playTime = "0.00000"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mutable state = md`the audio is not playing at the moment`
Insert cell
Insert cell
files = [
FileAttachment("Auld_Lang_Syne_-_Concert_Band_-_United_States_Air_Force_Heritage_of_America_Band.mp3")
]
Insert cell
viewof soundUrl = {
const selector = select({
title: 'choose the sound effect to be played',
options: _files.map(({ url, name }) => ({
value: url,
label: `file name: ${name}`
}))
});
return selector;
}
Insert cell
// https://observablehq.com/@rabelais/play-sound-on-demand
Insert cell
AudioInstance = () => {
let _a = new Audio();
_a.addEventListener(
'loadeddata',
() => (mutable state = md`the audio is loaded`)
);
_a.addEventListener(
'playing',
() => (mutable state = md`the audio is playing`)
);
_a.addEventListener(
'ended',
() => (mutable state = md`the audio has finished playing`)
);
_a.playAudio = _url => {
_a.setAttribute('src', _url);
_a.load();
_a.play();
};
return _a;
}
Insert cell
audio = AudioInstance()
Insert cell
_files = {
const fetchUrls = files.map(f =>
f.url().then(url => ({ url, name: f.name }))
);
const urls = await Promise.all(fetchUrls);
return urls;
}
Insert cell
playMusic = _url => {
audio.playAudio(_url);
}
Insert cell
import { select } from "@jashkenas/inputs"
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