Skip to content

Instantly share code, notes, and snippets.

@subzey
Last active December 26, 2016 16:46
Show Gist options
  • Select an option

  • Save subzey/def530dec7c982eedc6bd3682d8a8ad0 to your computer and use it in GitHub Desktop.

Select an option

Save subzey/def530dec7c982eedc6bd3682d8a8ad0 to your computer and use it in GitHub Desktop.
webpack-screensaver.js
<!DOCTYPE html>
<html>
<head>
<title>Webpack screensaver</title>
<style>
html, body {
background: #000;
color: #aaa;
margin: 0;
user-select: none;
}
pre {
margin: 1vw;
font: 3vw/3.5vw monospace;
}
.cursor {
display: inline-block;
width: 1ex;
height: 3.5vw;
box-sizing: border-box;
border: solid currentcolor .1vw;
vertical-align: bottom;
}
</style>
</head>
<body>
<pre>build@node:~$ $(npm bin)/webpack
<span id="percent"></span>% <span id="done"></span>/<span id="total"></span> build modules<span class="cursor"></span></pre>
<script>
var percentTextNode = document.getElementById('percent').appendChild(document.createTextNode(''));
var doneTextNode = document.getElementById('done').appendChild(document.createTextNode(''));
var totalTextNode = document.getElementById('total').appendChild(document.createTextNode(''));
var done = 0;
var total = 1;
var invalidated = false;
function render() {
invalidated = false;
doneTextNode.nodeValue = done;
totalTextNode.nodeValue = total;
percentTextNode.nodeValue = Math.round(done / total * 60 + 10);
}
function update() {
if (Math.random() < done++ / total) {
total += Math.exp(Math.random() * 3) | 0;
}
if (!invalidated) {
invalidated = true;
requestAnimationFrame(render);
}
setTimeout(update, Math.exp(Math.random() * 7));
}
update();
</script>
</body>
</html>
#!/usr/bin/env node
'use strict';
let total = 1;
let done = 0;
const a = () => {
if (Math.random() < done++ / total) {
total += Math.exp(Math.random() * 3) | 0;
}
process.stderr.write(`\r ${Math.round(done / total * 60 + 10)}% ${done}/${total} build modules`);
setTimeout(a, Math.exp(Math.random() * 6));
};
a();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment