Skip to content

Instantly share code, notes, and snippets.

@laughinghan
laughinghan / Every possible TypeScript type.md
Last active Nov 16, 2022
Diagram of every possible TypeScript type
View Every possible TypeScript type.md

Hasse diagram of every possible TypeScript type

  • any: magic, ill-behaved type that acts like a combination of never (the proper [bottom type]) and unknown (the proper [top type])
    • Anything except never is assignable to any, and any is assignable to anything at all.
    • Identities: any & AnyTypeExpression = any, any | AnyTypeExpression = any
    • Key TypeScript feature that allows for [gradual typing].
  • unknown: proper, well-behaved [top type]
    • Anything at all is assignable to unknown. unknown is only assignable to itself (unknown) and any.
    • Identities: unknown & AnyTypeExpression = AnyTypeExpression, unknown | AnyTypeExpression = unknown
  • Prefer over any whenever possible. Anywhere in well-typed code you're tempted to use any, you probably want unknown.
View unicode_blossom_notebook.md

Text and Unicode in Blossom Notebook

The Absolute Bare Minimum You Need To Know

Consider the text:

Sent in my résumé! 😮‍💨

Computers represent that as zeroes and ones:

View simpler_stack_switching.md

Simpler Stack Switching for Wasm

To me, #1360 "First-Class Stacks" seems like it started out great, in particular primitive stack-switching seems like a great low-level building block for everything you'd want to do including algebraic effects (#1359); but then it seems to me like it ended up both overly complex and yet also underspecified. In particular, stack extension and redirection seem like they should be extensions to stack-switching added later; whereas creating stacks seems like it would be immediately necessary for priority use cases like the Go and Erlang runtimes, and it seems like it would be a simple win to be able to send normal, non-exception values and thus remove the dependency on the exception-handling work.

Just like the TinyGo author suggested, it seems to me like it would be simplest to just have 3 instructions for creating, using, and destroying stack continuations, respectively:

  • (for brevity, `(cont X … -
@laughinghan
laughinghan / MathSON.md
Last active Sep 7, 2022
MathSON - JSON for Math Formulae
View MathSON.md

MathSON

Status: Draft 1 In Progress. This document is undergoing its first revision. Initial implementation has begun alongside editing Draft 1. Your feedback is hoped and dreamed of.

Mathematical Structured Object Notation is a JSON-based representation for most of the common subset of what LaTeX and Presentation MathML can

View README.md

Minimalist Layout System

This super simple, fast, flexible layout system operates in a single pass (no reflow or constraint solving) and is probably <100 lines of non-comment, non-duplicate logic (there's a lot of duplicate logic between the top/left/right/bottom directional code that's not worth de-duplicating).

To layout PinLayout's Example 1:

pinlayout example 1

The code is much simpler than PinLayout's:

View SAT_visualization.js
// https://jsbin.com/xirefor/edit?js,output
var paper = Raphael("paper", 600, 600)
var n = 7 // number of boolean variables
var C1 = function(x1, x2, x3, x4, x5, x6, x7) {
return !x2 || !x3 || !x4 || x5
}
var C2 = function(x1, x2, x3, x4, x5, x6, x7) {
return !x1 || !x5 || x6
View assert_vs_assume.md

Assert, Assume, and Force-Assume in Mechanical

All 3 have nearly-identical runtime behavior, which is no-op if a condition is true, otherwise raise a fatal runtime error. (The runtime checks can ofc be omitted by compiler config options.)

However, they are treated very differently by static analysis. Briefly:

  • Assert tells the compiler something it doesn't know (but in theory could figure out from the code, if it were smarter)
  • Assume tells the compiler something it couldn't possibly know (because it can't be deduced from the code even in theory; no matter how smart the compiler is, it can't read your mind)
  • Assume ^force tells the compiler something it has good reason to think is actually wrong (as a general rule, avoid this one)
View E2E (symmetric crypto only).vdx
<?xml version="1.0" encoding="utf-8"?><VisioDocument xml:space="preserve"><FaceNames><FaceName CharSets="1614742015 -65536" Flags="357" ID="1" Name="Arial Unicode MS" Panos="2 11 6 4 2 2 2 2 2 4" UnicodeRanges="-1 -369098753 63 0"/><FaceName CharSets="-2147483648 0" Flags="261" ID="2" Name="Symbol" Panos="5 5 1 2 1 7 6 2 5 7" UnicodeRanges="0 0 0 0"/><FaceName CharSets="-2147483648 0" Flags="261" ID="3" Name="Wingdings" Panos="5 0 0 0 0 0 0 0 0 0" UnicodeRanges="0 0 0 0"/><FaceName CharSets="1073742335 -65536" Flags="325" ID="4" Name="Arial" Panos="2 11 6 4 2 2 2 2 2 4" UnicodeRanges="-536859905 -1073711037 9 0"/><FaceName CharSets="262145 0" Flags="421" ID="5" Name="SimSun" Panos="2 1 6 0 3 1 1 1 1 1" UnicodeRanges="3 680460288 6 0"/><FaceName CharSets="1048577 0" Flags="421" ID="6" Name="PMingLiU" Panos="2 2 5 0 0 0 0 0 0 0" UnicodeRanges="-1610611969 684719354 22 0"/><FaceName CharSets="1073873055 -539557888" Flags="421" ID="7" Name="MS PGothic" Panos="2 11 6 0 7 2 5 8 2 4" UnicodeRanges="-536870145 179149
@laughinghan
laughinghan / SP500.csv
Last active Jul 29, 2021
S&P 500 index daily price data, 1927-12-30 thru 2021-02-05, from Yahoo Finance (^GSPC)
View SP500.csv
We can't make this file beautiful and searchable because it's too large.
Date,Open,High,Low,Close,Adj Close,Volume
1927-12-30,17.660000,17.660000,17.660000,17.660000,17.660000,0
1928-01-03,17.760000,17.760000,17.760000,17.760000,17.760000,0
1928-01-04,17.719999,17.719999,17.719999,17.719999,17.719999,0
1928-01-05,17.549999,17.549999,17.549999,17.549999,17.549999,0
1928-01-06,17.660000,17.660000,17.660000,17.660000,17.660000,0
1928-01-09,17.500000,17.500000,17.500000,17.500000,17.500000,0
1928-01-10,17.370001,17.370001,17.370001,17.370001,17.370001,0
1928-01-11,17.350000,17.350000,17.350000,17.350000,17.350000,0
View PackSec.md

PackSec: Package-level capability-based security

What: A capability-secure version of Node.js, and an ecosystem of capability-secure repackaged versions of existing NPM packages, community-contributed and hosted on GitHub like Homebrew & DefinitelyTyped.

Why: Immediately, this provides strong defense against malicious dependencies (supply chain attacks) like event-stream, electron-native-notify, typosquatting like crossenv, and thousands more; as well as vulnerable dependencies like JS-YAML, [`express-fileupl