Skip to content

Instantly share code, notes, and snippets.

const fetch = require("node-fetch");
const oauthClientUrl = "https://pastebin.com/raw/pS7Z6yyP"
const baseUrl = "https://owner-api.teslamotors.com";
function wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function getHeaders() {
@domenic
domenic / readable-stream-progress.js
Last active February 10, 2020 17:05
XHR-esque progress events on top of streams
function processBodyChunkwiseWithProgress(res, processChunk) {
const dummyEventTarget = document.createElement("div"); // why isn't EventTarget constructible? :(
const lengthComputable = res.headers.has("Content-Length");
const total = res.headers.get("Content-Length") || 0;
let loaded = 0;
// Using http://underscorejs.org/#throttle
const fireProgressThrottled = _.throttle(fireProgress, 50, { trailing: false });