Skip to content

Instantly share code, notes, and snippets.

@frdnrdb
frdnrdb / video-vtt-programmatic.js
Last active January 4, 2023 15:12
Programmatically assigning text track video captions from vtt file url
const vttText = await fetch(vttUrl).then(res => res.text());
const timeCodeToSeconds = (str) => {
const [h, m, s] = str.split(':').map(Number);
return h * 60 * 60 + m * 60 + s;
};
// PS! simple TEST parser! vtt format could contain NOTES and css styling
// https://developer.mozilla.org/en-US/docs/Web/API/VTTCue
const cues = vttText
@frdnrdb
frdnrdb / toWords.js
Created November 11, 2022 00:44
english: numbers to words/ number spelling
const AND = 'and';
const NIL = 'zero';
const NUMBERS = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];
const TENS = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];
const UNITS = ['', '', 'hundred', 'thousand', 'million', 'billion', 'trillion', 'quadrillion', 'quintillion', 'sextillion', 'septillion', 'octillion', 'nonillion', 'decillion', 'undecillion', 'duodecillion', 'tredecillion', 'quattuordecillion', 'quindecillion', 'sedecillion', 'septendecillion', 'octodecillion', 'novendecillion', 'vigintillion', 'unvigintillion', 'duovigintillion', 'tresvigintillion', 'quattuor­vigint­illion', 'quinvigintillion', 'sesvigintillion', 'septemvigintillion', 'octovigintillion', 'novemvigintillion', 'trigintillion', 'untrigintillion', 'duotrigintillion', 'trestrigintillion', 'quattuor­trigint­illion', 'quintrigintillion', 'sestrigintillion', 'se
@frdnrdb
frdnrdb / toWords.js
Last active November 11, 2022 00:41
norwegian: numbers to words/ number spelling
// source: https://no.wikipedia.org/wiki/Tall
const numbers = ['','en','to','tre','fire','fem','seks','sju','åtte','ni','ti','elleve','tolv','tretten','fjorten','femten','seksten','søtten','atten','nitten'];
const tens = ['','','tjue','tretti','førti','femti','seksti','søtti','åtti','nitti'];
const units = [ '', '', 'hundre', 'tusen', 'million', 'milliard', 'billion', 'billiard', 'trillion', 'trilliard', 'kvadrillion', 'kvadrilliard', 'kvintillion', 'kvintilliard', 'sekstillion', 'sekstilliard', 'septillion', 'septilliard', 'oktillion', 'oktilliard', 'nonillion', 'nonilliard', 'desillion', 'undesillion', 'dodesillion', 'tredesillion', 'quattordesillion', 'kvindesillion', 'seksdesillion', 'googol', 'septendesillion', 'oktoesillion', 'novemdesillion', 'vigintillon', 'unvigintillion', 'dovigintillion', 'trevigintillion', 'kvartvigintillion', 'kvintvigintillion', 'seksvigintillion', 'septenvigintillion', 'octovigintillion', 'novemvigintillion', 'trigintillion', 'untrigintillion', 'dotrigintillion', 'trerigintill
const msal = require('@azure/msal-node');
const app = someServer();
const authenticator = new msal.ConfidentialClientApplication({
auth: {
clientId: process.env.AZURE_CLIENT_ID,
clientSecret: process.env.AZURE_CLIENT_SECRET,
authority: `https://login.microsoftonline.com/${process.env.AZURE_TENANT_NAME}`,
},
    system: {
import { UserAgentApplication } from 'msal';
const app = new UserAgentApplication({
auth: {
clientId: process.env.AZURE_CLIENT_ID,
authority: `https://login.microsoftonline.com/${process.env.AZURE_TENANT_ID}`
},
cache: {
cacheLocation: 'localStorage'
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>kraft</title>
<style>
body {
font-size: 50vw;
font-family: sans-serif;
@frdnrdb
frdnrdb / register-node-fileformat-import-function.js
Created October 30, 2019 17:16
Import any fileformat to node
const fs = require('fs')
const JSON5 = require('./')
// eslint-disable-next-line node/no-deprecated-api
require.extensions['.json5'] = function (module, filename) {
const content = fs.readFileSync(filename, 'utf8')
try {
module.exports = JSON5.parse(content)
} catch (err) {
err.message = filename + ': ' + err.message
// -----> server
server <- function(input, output, session) {
loggedIn <- callModule(authorize, 'login')
observe({
req(loggedIn())
callModule(startApp, 'dashboard')
})
@frdnrdb
frdnrdb / example.html
Last active March 7, 2017 09:59
Aptoma DrFront Support df-skin
<!-- ORIGINAL XML FEED -->
<article id="capi.fvn.698705" pubDate="2017-03-07 09:34:46" skin="theme-News section-Nyheter story-olsen-bil-saken shortId-blQkl paywall-closed" title="Olsen Bil-saken: Personlig gjeld på 28 mill. kroner">
<![CDATA[
<a href="http://www.fvn.no/okonomi/Olsen-Bil-saken-Personlig-gjeld-pa-28-mill-kroner-698705b.html"><img src="https://fvn.mnocdn.no/images/6cfcea78-5508-4e64-852c-190768acdafb?fit=crop&q=80&w=2048"/></a><h3><a href="http://www.fvn.no/okonomi/Olsen-Bil-saken-Personlig-gjeld-pa-28-mill-kroner-698705b.html">Olsen Bil-saken: Personlig gjeld på 28 mill. kroner</a></h3> <p>Geir Egil Olsens personlige konkurs har så langt resultert i krav på 28 millioner kroner. Blant de største kreditorene er foreldrene hans. </p>
]]>
</article>