Skip to content

Instantly share code, notes, and snippets.

View garybernhardt's full-sized avatar

Gary Bernhardt garybernhardt

View GitHub Profile
#!/usr/bin/env bash
set -e
if [ -e static ]; then
rm -r static
fi
mkdir -p static
sass src/sass/main.scss > static/application.css
$(npm bin)/browserify src/js/main.js > static/application.js

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

(Chapters marked with * are already written. This gets reorganized constantly
and 10 or so written chapters that I'm on the fence about aren't listed.)
Programmer Epistemology
* Dispersed Cost vs. Reduced Cost
* Verificationist Fallacy
* Mistake Metastasis
The Overton Window
Epicycles All The Way Down
The Hyperspace Gates Were Just There
ES2015
Optimisation
proper tail calls (tail call optimisation)
Syntax
default function parameters
rest parameters
spread syntax for iterable objects
object literal extensions
for..of loops
octal and binary literals
@garybernhardt
garybernhardt / selectable_queue.rb
Last active November 23, 2022 12:42
A queue that you can pass to IO.select.
# A queue that you can pass to IO.select.
#
# NOT THREAD SAFE: Only one thread should write; only one thread should read.
#
# Purpose:
# Allow easy integration of data-producing threads into event loops. The
# queue will be readable from select's perspective as long as there are
# objects in the queue.
#
# Implementation:

Things that programmers don't know but should

(A book that I might eventually write!)

Gary Bernhardt

I imagine each of these chapters being about 2,000 words, making the whole book about the size of a small novel. For comparison, articles in large papers like the New York Times average about 1,200 words. Each topic gets whatever level of detail I can fit into that space. For simple topics, that's a lot of space: I can probably walk through a very basic, but working, implementation of the IP protocol.

commit 9f676b29d4a49356e756048ff249d17e552b5faa (HEAD -> master, origin/master)
Author: Gary Bernhardt <gary.bernhardt@gmail.com>
Date: Sun Mar 15 13:36:55 2020 -0700
cache public dir between deploys (note)
Problem:
1. A deploy starts.
2. A browser starts loading a page.
3. The deploy finishes.
import React, { useEffect } from "react"
import { META_DESCRIPTION } from "../../util"
export const Page: React.FC<{
title?: string
metaDescription?: string
}> = props => {
useEffect(() => {
document.title = props.title ?? "Execute Program"
{
"extends": "../tsconfig.json",
"compilerOptions": {
"composite": true,
"rootDir": ".",
"outDir": "../../build/common"
},
"include": ["."]
}
function f() {
switch (x) {
case "1":
<div>foo</div>
case "2":
return <div>
<div>
foo
</div>
<div>foo</div>