Skip to content

Instantly share code, notes, and snippets.

In TypeScript, you can create an Either type similar to Rust's Either by using discriminated unions. This approach allows you to define a type that can hold one of two possible types (commonly referred to as Left and Right). Here's how you can implement it:

Step 1: Define the Either Type

First, define the Either type as a union of Left and Right interfaces. Each interface includes a discriminant property (tag) to distinguish between the two variants.

// Either.ts

// Define the Left variant

The Opulence of Species How Memetic Selection Rules Economic Stagnation, Growth and the Revolution in Between by Lemin Wu

Chapter 1: An Eternal and Dismal Guide

Main Points

  • Malthusian theory posits a pessimistic view of pre-industrial economic life. This theory, which the book intends to challenge, suggests that any increase in income would be inevitably consumed by population growth, trapping societies in a cycle of poverty. This "Malthusian trap" is maintained by three key mechanisms: higher incomes lead to higher birth rates ("preventive check"), lower incomes lead to higher death rates ("positive check"), and larger populations lead to lower per capita income.
  • The Malthusian model suggests limited ways to escape the poverty trap. The model suggests that temporary increases in income could be achieved through positive shocks like technological advancements, or negative shocks like plagues and wars, but these gains would be short-lived due to subsequent population adjustments. Lon
[
{
"position": 1,
"items": [
{
"position": 1,
"itemUnion": {
"simpleText": {
"textDirection": "USER_LOCALE",
"text": "About 4,630,000 results",
@joaoeira
joaoeira / main.js
Created April 9, 2021 20:01
hacky hacker news scraper
const url = "https://news.ycombinator.com/"
const fetch = require('node-fetch');
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
function getUpvotesTitleUrl(entry){
const upvotes = entry.getElementsByClassName('title')[0].textContent
const title = entry.getElementsByClassName('title')[1].textContent
const url = entry.getElementsByClassName('title')[1].getElementsByTagName('a')[0].getAttribute('href')
body,html {
height: 100%;
margin: 0px;
}
header {
min-height: 25%;
border-top: 1px hsl(0, 0%, 30% 0%) solid;
}
.max-width-wrapper {
width: fit-content;
//leftward (downward) sidebar close
document.addEventListener("keydown", (e) => {
if(e.ctrlKey && e.altKey && e.key === "n"){
const sidebar = document.getElementById("roam-right-sidebar-content");
if(sidebar){
// Leftward page is the last child of sidebar
// so if e.g. 5 pages open, the leftward is in index 4 (0-index, remember)
sidebar.childNodes[sidebar.childElementCount - 1].getElementsByClassName("bp3-icon-cross")[0].click()
}
}
sudo apt-get update
sudo apt-get autoclean
sudo apt-get autoremove
sudo apt-get upgrade
sudo apt-get install gnulib autogen git emacs24 texlive-full texinfo global markdown vlc pandoc compizconfig-settings-manager compiz-plugins libfreetype6-dev libatlas-base-dev gcc gfortran g++ ubuntu-restricted-extras calibre anki strongswan network-manager-strongswan redshift gparted ruby ruby-dev geoclue-2.0 python3-ipython
sudo echo "deb http://cran.rstudio.com/bin/linux/ubuntu xenial/" | sudo tee -a /etc/apt/sources.list
gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
gpg -a --export E084DAB9 | sudo apt-key add -
sudo apt-get update
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"ein.tags": [
"worksheet-0"
]
},
"source": [