Instantly share code, notes, and snippets.

View 1.js
function logger(strings,...values) {
var str = "";
for (let i = 0; i < strings.length; i++) {
if (i > 0) {
if (values[i-1] && typeof values[i-1] == "object") {
if (values[i-1] instanceof Error) {
if (values[i-1].stack) {
str += values[i-1].stack;

The Web Must PWA

The web is the most important platform for individual empowerment and creative expression that mankind has ever invented. What was once a meager collection of a handful of scientific documents linked together, is now an expansive graph of billions of people interacting to exchange trillions of interconnected ideas. Getting to be even a small part of building that should be tremendously exciting.

But, even as great as it is, the web faces myriad existential threats. And it's up to us, the builders of the web, to confront them head on. Privacy, security, and accessibility are the obvious big ones, but less obvious are some far deeper problems at the core of the web and how we design/build it.

Should the web go all-HTTPS? Most think so, but uncacheable HTTPS alienates 1/3 of the world's population. We can all probably imagine how bad the web is on slow connections, or even how much it costs on expensive metered-data plans. But worse than slow connection is spotty/intermittent connection or


I received a question about this snippet of code:

function def(first="oldValue" , second=function(){
         return first;
        var first="updatedValue";
View 1.js
// my-common-js-module.js
const prefix = "ABC_";
// NOTE: what's good here is that I'm using a `const`, but what's bad is, it's not
// located down below where my other "private" implementation details are.
// my public API for my module
module.exports = {
[`${prefix}1`]: 42,
[`${prefix}2`]: 100,
View 1.js
function waitForEvent(elem,evtName) {
return new Promise(function c(resolve){
elem.addEventListener(evtName,function onEvent(evt){



Some things that are "better" with this BetterPromise implementation:

  • BetterPromise # then(..) accepts a BetterPromise (or Promise) instance passed directly, instead of requiring a function to return it, so that the promise is linked into the chain.

    var p = BetterPromise.resolve(42);
    var q = Promise.resolve(10);
View 1.js
class Foo {
constructor(x) {
this.x = x;
this.hello = () => {
var a = new Foo(12);
View 1.js
NOTE: This code assumes a bare git repo in ./bare-git/,
which should have at least one text file in its root,
named "greetings.txt".
This code updates the contents of a "greetings.txt"
file, and creates a new file called "greetings-XXX.txt"
(with XXX being a random number). It then creates a new
commit for these changes. Finally, it reads and dumps
the new current contents of the repo, file by file.