Skip to content

Instantly share code, notes, and snippets.

@pesterhazy
pesterhazy / print-to-pdf.md
Last active October 2, 2022 15:43
Print web pages to PDF for readability

It's often desirable to print articles or blog posts to PDF for easier reading. In fact you're almost always better off reading a cleaned-up printout than a noisy HTML page on a backlit screen.

Printing the web without all the noise

Why?

Offline reading has fewer distractions; you can mark up the article with your own notes; and it's easier on the eyes. Active reading, underlinding and annotating improves comprehension and retention. If you read on the reMarkable tablet, as I do, then you don't to print to actual paper and save trees.

If an article is worth reading, it's worth printing and reading with a pen in your hand.

@pesterhazy
pesterhazy / github-print.md
Last active July 10, 2022 04:52
Print Github Markdown

I often want to read Markdown documentation on Github — or proof-read my own documents — without staring at a backlit screen. Here's an easy way to print the files in a readable format.

  1. Create a bookmarklet with the following code and give it the name "github print"

    javascript:void function(){b=document.body,c=document.querySelector("article"),b.innerHTML="",b.appendChild(c)}();
    
  2. Go to the markdown view on Github of the file you want to print, e.g. Ripgrep's user guide

  3. Click on the bookmarklet. Alternatively (in Chrome) type "github print" in the search bar, select the bookmarklet code with cursor keys if necessary and press enter.

  4. Use the browser print feature to print the document, to a physical printer or (to save paper) to PDF on a reMarkable eInk tablet.

import * as assert from "node:assert/strict";
function splitLinesWithEols(str) {
let r=/((?!(\n|\r\n)).)*(\n|\r\n)/y;
let m;
let last = 0;
let result = [];
while ( (m=r.exec(str)) ) {
result.push(m[0]);
@pesterhazy
pesterhazy / geepaw-incrementalism.md
Last active June 17, 2022 09:02
GeePaw Hill on Incrementalism in Software Development

This gist collects publications by GeePaw Hill around the topic of Incrementalism in Software Development - the advice to "take many more, much smaller steps."

Where to start

The good entry point into the discussion is a pair of 2020 muses: The RAT: Rework Avoidance Theory and Understanding Incremental Switchover

Muses

Later muses are also published as podcast episodes.

@pesterhazy
pesterhazy / cljs-let-shadowing.md
Last active May 25, 2022 02:00
Clojurescript let global variable shadowing

Consider this ClojureScript code:

(defn foo []
  (let [location 12345] (prn js/location.hash)))

This won't work. js/ isn't a real namespace. This code will throw an exception at runtime.

The reason is that the code expands to this JS snippet:

@pesterhazy
pesterhazy / react_cljs_es6_classes.cljs
Last active November 7, 2021 17:54
ClojureScript: bare React with ES6 classes (extending React.Component, no createClass or reagent)
(ns demo.react-cljs-es6-classes
(:require [goog.object :as gobj]))
;; Demo of using bare React using ES6 classes (without createClass or reagent)
;;
;; Equivalent of Javascript/JSX:
;;
;; class MyComponent extends React.Component {
;; constructor(props) {
;; super(props);
@pesterhazy
pesterhazy / promises-passing-values.cljs
Last active October 24, 2021 00:55
Promise chains in ClojureScript and the problem of previous values
(ns my.promises
"Demo to show different approaches to handling promise chains in ClojureScript
In particular, this file investigates how to pass data between Promise
callbacks in a chain.
See Axel Rauschmayer's post
http://2ality.com/2017/08/promise-callback-data-flow.html for a problem
statement.
@pesterhazy
pesterhazy / error_boundary.cljs
Last active October 12, 2021 00:19
Reagent error boundary for recovering from exceptions
(ns error-boundary.error-boundary
(:require [reagent.core :as r]
[reagent.impl.component :as comp]
[reagent.impl.util :as util]
[goog.object :as gobj]))
;; (c) 2016 Paulus Esterhazy
;;
;; License: MIT
@pesterhazy
pesterhazy / learning-italian.md
Last active July 8, 2021 16:16
Learning Italian using the natural method // Imparare italiano col metodo naturale
(ns background
(:require [clojure.tools.logging :as log])
(:import [java.util.concurrent]))
(defonce !executor (delay (java.util.concurrent.Executors/newCachedThreadPool)))
(defn background
"Calls the fn passed in a thread from a thread pool, returning immediately.
Unlike future, background does not swallow exceptions."
[f]