Skip to content

Instantly share code, notes, and snippets.

View rauschma's full-sized avatar

Axel Rauschmayer rauschma

View GitHub Profile

Mastodon for people who are new to social media

In this blog post, I try to explain Mastodon to people who are not familiar with social media and/or beginner computer users. I try to be as jargon-free as I can.

Structure of this blog post:

  • Reading section 1 and 2 takes a bit of effort: They explain important background knowledge for Mastodon. But, in my opinion, the effort is worth it because you’ll find it much easier to use Mastodon. Not having this knowledge can prevent even otherwise advanced computer users from enjoying Mastodon.

  • Section 3 is brief and mentions first steps for actually getting started with Mastodon.

javascript:{
const text = getSelection().toString().trim();
if (text.length > 0) {
const urlToHighlight = new URL(location);
urlToHighlight.hash = '#:~:text=' + encodeURIComponent(text);
navigator.clipboard.writeText(urlToHighlight.href)
.catch((error) => {
alert(String(error));
});
}

Stateless RegExp methods

The issues

  • The rules for the flags /g and /y are complicated.
  • Regular expression operations keep state in RegExp objects, via property .lastIndex. That leads to several pitfalls if a RegExp object is used multiple times. It also makes it impossible to freeze instances of RegExp.
  • String.prototype.replace() accepts a callback where accessing named captures is inconvenient (via an object that is passed as the last argument).

The goal

const primaryColumn = document.querySelector('div[data-testid="primaryColumn"]');
document.body.innerHTML = '';
document.body.append(primaryColumn);
// Per-tweet controls
for (const ele of document.querySelectorAll('div[role="group"]')) {
ele.remove();
}
// Reply widget

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.
// 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();

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) {
@rauschma
rauschma / README.md
Last active November 19, 2024 16:33
Bookmarklet for Mastodon: Transport a profile or post to your server

Bookmarklet for Mastodon: Transport a profile or post to your server

This bookmarklet shows a profile or a post on another Mastodon server in your server’s web app.

Installation

  • Change the value of HOST to the domain of your Mastodon server.
  • Create a bookmark and paste the lines in show-in-mastodon-web-app.js into its address (browsers are OK with pasting multiple lines).

Usage

import assert from 'node:assert/strict';
// Extended RegExp mode (flag /x) [1] via a template tag
//
// Quote: “While the x-mode flag can be used in a RegularExpressionLiteral,
// it does not permit the use of LineTerminator in RegularExpressonLiteral.
// For multi-line regular expressions you would need to use the RegExp
// constructor.”
//
// The plan is to include this functionality in re-template-tag [2]. Then