Skip to content

Instantly share code, notes, and snippets.

View rauschma's full-sized avatar

Axel Rauschmayer rauschma

View GitHub Profile
// Batch-delete videos from YouTube’s “Watch later” playlist
// Paste the following code into a browser console while the playlist is open
// Code based on: https://gist.github.com/astamicu/eb351ce10451f1a51b71a1287d36880f?permalink_comment_id=4087416#gistcomment-4087416
//
// (Suggestions for improvement welcome. My approach for waiting for the .click() to finish, feels hacky.)
const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
async function remove() {
for (let i=0; i < 100; i++) {
document.querySelector('#primary button[aria-label="Action menu"]').click();

Work in a post-growth world

Source: “Le travail dans un monde post-croissance (Dominique Méda)” (56-minute video)

  • Currently, the economy and commercialized work dominates our society.
  • Many societies are not based on “commercialized work” and don’t have a word for it.
  • Adam Smith: work enables us to create wealth. We are interested in the latter (not in work itself).
  • During the 18th century, our values changed significantly: from valuing moderation (a traditional christian value) to valuing wealth.
    • The goal became to produce as much as possible – more than we need to fulfill out immediate needs.
  • Work becomes something meaningful: To assert ourselves in the world, we have to work.
@rauschma
rauschma / about-proposal.md
Last active October 6, 2023 18:30
Enum proposal

Advantages compared to using symbols as enum values:

  • Enum values are much more customizable. For example, one can have custom prototype and/or instance methods.
  • Enum values get two custom properties:
    • name provides direct access to the name of an enum value.
    • ordinal holds a number, the position of the enum value. Useful for some applications.
  • One can use instanceof to test whether a value is an element of an enum.
  • One occasionally requested feature for enums is that enum values be numbers (e.g. for flags) or strings (e.g. to compare with values in HTTP headers). That can be achieved by making those values properties of enum values. For an example, see enum Mode, below.

Static properties of enums:

@rauschma
rauschma / impatient-js-es2021.md
Last active August 31, 2023 07:02
ES2021 edition of “JavaScript for impatient programmers”

What is new in the ES2021 edition of “JavaScript for impatient programmers”?

Free to read online: exploringjs.com/impatient-js/

  • The exercises now run as native ESM modules on Node.js. Previously, they were run via the esm package.
  • Material on new ES2021 features:
    • String.prototype.replaceAll()
    • Promise.any()
    • Logical assignment operators
  • Underscores (_) as separators in number literals and bigint literals
-- Cross-format support for indices (LaTeX, HTML, EPUB, ...)
--
-- Syntax is based on LaTeX: https://en.wikibooks.org/wiki/LaTeX/Indexing
-- Creating entries: \index{key}
-- Creating the index: \printindex
-- ########## Shared data ##########
local indexEntryCounter = 0
local indexEntries = {}
@rauschma
rauschma / README.md
Last active May 10, 2023 09:53
Better dynamic type checks

Better dynamic type checks

  • Update 2022-07-10: new approach based on Function.prototype.hasInstance()

Problems

In principle, the rule “typeof is for primitive values, instanceof is for objects” works. There are two exceptions:

  • Checking if a value is an object
  • Cross-realm instance checks
// From callbacks to Promises to async functions
function callbackFunc(x, callback) {
f1(x, (err1, result1) => {
if (err1) {
console.error(err1);
callback(err1);
return;
}
f2(result1, (err2, result2) => {

I find it easiest to make sense of this as follows:

  • It’s an implicit parameter of functions (other than arrow functions).
  • It’s always provided when we invoke such functions – how depends on how we invoke them.

Demo:

import assert from 'node:assert/strict';

//========== this is an implicit parameter of getThis() ==========

#!/usr/bin/env node
// Use curl to download a URL to a file whose name is URL-decoded
// Related: https://github.com/curl/curl/issues/2573
import {execSync} from 'node:child_process';
// Documentation for node:child_process – https://exploringjs.com/nodejs-shell-scripting/ch_nodejs-child-process.html
export const WEB_PATH_SEP = '/';
export function getWebBasename(webPath) {