Skip to content

Instantly share code, notes, and snippets.

@domenic
domenic / default-export.md
Last active May 6, 2024 10:56
Default default export = MIO?

Intro

Idea: could we make the "default default export" the module instance object?

So for:

// a.js
export const x = 1;
export const y = 2;
@domenic
domenic / 0-github-actions.md
Last active April 8, 2024 23:35
Auto-deploying built products to gh-pages with Travis

Auto-deploying built products to gh-pages with GitHub Actions

This is a set up for projects which want to check in only their source files, but have their gh-pages branch automatically updated with some compiled output every time they push.

A file below this one contains the steps for doing this with Travis CI. However, these days I recommend GitHub Actions, for the following reasons:

  • It is much easier and requires less steps, because you are already authenticated with GitHub, so you don't need to share secret keys across services like you do when coordinate Travis CI and GitHub.
  • It is free, with no quotas.
  • Anecdotally, builds are much faster with GitHub Actions than with Travis CI, especially in terms of time spent waiting for a builder.
@domenic
domenic / promises.md
Last active March 31, 2024 14:07
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
@domenic
domenic / redirecting-github-pages.md
Created February 10, 2017 19:28
Redirecting GitHub pages after a repository move

Redirecting GitHub Pages after a repository move

The problem

You have a repository, call it alice/repo. You would like to transfer it to the user bob, so it will become bob/repo.

However, you make heavy use of the GitHub Pages feature, so that people are often accessing https://alice.github.io/repo/. GitHub will helpfully redirect all of your repository stuff hosted on github.com after the move, but will not redirect the GitHub Pages hosted on github.io.

The solution

@domenic
domenic / after-thrawn.md
Last active November 28, 2023 20:06
What next after the Thrawn Trilogy?

What to Read After The Thrawn Trilogy?

The first post-Return of the Jedi book series anyone should read is The Thrawn Trilogy: namely Heir to the Empire, Dark Force Rising, and The Last Command, all by Timothy Zahn. They are an excellent introduction to the "New Republic era" of the Star Wars Expanded Universe (EU), and notably they were the first books written in real-world time to explore this era.

But after that, what should you read?

Background: The Eras of the Expanded Universe

First, be aware that the post-Return of the Jedi EU is broken up into three main eras:

@domenic
domenic / angularpromise.js
Created January 21, 2016 23:28
How to subclass a promise
// ES6
class AngularPromise extends Promise {
constructor(executor) {
super((resolve, reject) => {
// before
return executor(resolve, reject);
});
// after
}
@domenic
domenic / promise-retryer.js
Last active September 16, 2023 02:43
Generalized promise retryer
"use strict";
// `f` is assumed to sporadically fail with `TemporaryNetworkError` instances.
// If one of those happens, we want to retry until it doesn't.
// If `f` fails with something else, then we should re-throw: we don't know how to handle that, and it's a
// sign something went wrong. Since `f` is a good promise-returning function, it only ever fulfills or rejects;
// it has no synchronous behavior (e.g. throwing).
function dontGiveUp(f) {
return f().then(
undefined, // pass through success
@domenic
domenic / 0-usage.js
Last active August 21, 2023 09:02
Import module function (assuming <script type="module"> is implemented)
// Dynamic module loading using runtime-composed strings, decisions, etc.
for (const m of ["cool", "awesome", "fun", "whee"]) {
if (Math.random() > 0.5) {
importModule(`/js/${m}.js`).then(
module => console.log("Module instance object for " + m, module),
e => console.error(e)
);
}
}
@domenic
domenic / generate-urltestdata.js
Created December 30, 2022 09:53
urltestdata.json generator using jsdom/whatwg-url
"use strict";
const { URL } = require(".");
const inputs = [
"https://\u0000y",
"https://x/\u0000y",
"https://x/?\u0000y",
"https://x/?#\u0000y"
];
@domenic
domenic / upload.js
Created March 20, 2012 17:13
File upload using XHR PUT
(function () {
var $dropTarget = $("#drop-target");
var slice = Function.prototype.call.bind(Array.prototype.slice);
$dropTarget.on({
drop: function (event) {
slice(event.originalEvent.dataTransfer.files).forEach(putFile);
return false;