Skip to content

Instantly share code, notes, and snippets.

Domenic Denicola domenic

Block or report user

Report or block domenic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@domenic
domenic / redirecting-github-pages.md
Created Feb 10, 2017
Redirecting GitHub pages after a repository move
View redirecting-github-pages.md

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 / auto-deploy.md
Last active Jun 14, 2019
Auto-deploying built products to gh-pages with Travis
View auto-deploy.md

Auto-deploying built products to gh-pages with Travis

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.

Create a compile script

You want a script that does a local compile to e.g. an out/ directory. Let's call this compile.sh for our purposes, but for your project it might be npm build or gulp make-docs or anything similar.

The out/ directory should contain everything you want deployed to gh-pages. That almost always includes an index.html.

@domenic
domenic / promises.md
Last active Jun 13, 2019
You're Missing the Point of Promises
View promises.md

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 / interop.md
Last active Jun 12, 2019
`module.exports =` and ES6 Module Interop in Node.js
View interop.md

module.exports = and ES6 Module Interop in Node.js

The question: how can we use ES6 modules in Node.js, where modules-as-functions is very common? That is, given a future in which V8 supports ES6 modules:

  • How can authors of function-modules convert to ES6 export syntax, without breaking consumers that do require("function-module")()?
  • How can consumers of function-modules use ES6 import syntax, while not demanding that the module author rewrites his code to ES6 export?

@wycats showed me a solution. It involves hooking into the loader API to do some rewriting, and using a distinguished name for the single export.

This is me eating crow for lots of false statements I've made all over Twitter today. Here it goes.

@domenic
domenic / escape-vm.js
Created Aug 17, 2015
Escaping the vm sandbox
View escape-vm.js
"use strict";
const vm = require("vm");
const sandbox = { anObject: {} };
const whatIsThis = vm.runInNewContext(`
const ForeignObject = anObject.constructor;
const ForeignFunction = ForeignObject.constructor;
const process = ForeignFunction("return process")();
const require = process.mainModule.require;
require("fs");
@domenic
domenic / 1-service-worker.js
Last active Jun 4, 2019
Service worker stream transferring
View 1-service-worker.js
"use strict";
const worker = new Worker("worker.js");
self.onfetch = e => {
const transform = new TransformStream(); // creates an identity transform
e.respondWith(new Response(transform.readable));
// Give the worker the writable end. An identity transform stream will just shuffle
// bytes written there into transform.readable.
@domenic
domenic / event-emitter.js
Last active Jun 4, 2019
Revealing constructor pattern event-emitter
View event-emitter.js
// This event emitter emits events, but reserves the right to publish events to
// for its creator. It uses a WeakMap for true encapsulation.
const eesToEventMaps = new WeakMap();
export default class EventEmitter {
constructor(publisher) {
const eventMap = Object.create(null);
eesToEventMaps.set(this, eventMap);
@domenic
domenic / combinators.js
Last active May 18, 2019
Promise combinators
View combinators.js
Promise.all = iterable => {
return new this((resolve, reject) => {
const values = [];
let countdown = 0;
let index = 0;
for (let nextValue of iterable) {
const nextPromise = this.resolve(nextValue);
const countdownFunction = makeCountdownFunction(index);
@domenic
domenic / after-markdown-conversion.html
Created Apr 26, 2019
Working mode before and after
View after-markdown-conversion.html
<!DOCTYPE HTML>
<html lang="en">
<meta charset="utf-8">
<title>Working Mode — WHATWG</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#3A7908">
<link rel="icon" href="https://resources.whatwg.org/logo.svg">
<link rel="stylesheet" href="/style/shared.css">
<link rel="stylesheet" href="/style/subpages.css">
@domenic
domenic / angularpromise.js
Created Jan 21, 2016
How to subclass a promise
View angularpromise.js
// ES6
class AngularPromise extends Promise {
constructor(executor) {
super((resolve, reject) => {
// before
return executor(resolve, reject);
});
// after
}
You can’t perform that action at this time.