Skip to content

Instantly share code, notes, and snippets.

@Addisonbean
Addisonbean / types.md
Last active August 17, 2021 02:49
Sum and Product types

Types

I like to view types as a set of values (eg. string is the set of all possible strings, int is the set of all possible integers).

Looking at it this way, there are two common ways types are composed.

Product Types (a.k.a Intersection Types)

Most types people write are product types. Think of it as the product of two sets. If type a is the set { 1, 2, 3 } and b is the set { x, y, z }, a * b is { (1, x), (1, y), (1, z), (2, x), (2, y), (2, z), (3, x), (3, y), (3, z) }. This set contains every possible combination of values from a and b.

@Addisonbean
Addisonbean / init.vim
Created February 4, 2021 16:12
init.vim
" Vim-Plug {{{
call plug#begin("~/.local/share/nvim/plugged")
" Colorschemes:
Plug 'chriskempson/base16-vim'
Plug 'morhetz/gruvbox'
Plug 'tyrannicaltoucan/vim-deep-space'
Plug 'tyrannicaltoucan/vim-quantum'
@Addisonbean
Addisonbean / PKGBUILD
Created September 20, 2020 17:16
pico-8 0.2.1b PKGBUILD
# Maintainer: Adam Scott (scottmada) <ascott.ca at gmail dot com>
# Common metadata
pkgname='pico-8'
pkgver='0.2.1b'
pkgrel=1
pkgdesc="A fantasy console for making, sharing and playing tiny games and other computer programs."
arch=('i686' 'x86_64' 'armv6h' 'armv7h')
url="http://www.lexaloffle.com/pico-8.php"
license=('custom:commercial')
@Addisonbean
Addisonbean / tmux.conf
Last active September 17, 2020 17:39
Use tmux leader + C-h/j/k/l to switch between vim buffers and tmux panes
# Adapted from here: https://github.com/christoomey/vim-tmux-navigator#custom-key-bindings
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key 'C-h' if-shell "$is_vim" 'send-keys C-a C-h' 'select-pane -L'
bind-key 'C-j' if-shell "$is_vim" 'send-keys C-a C-j' 'select-pane -D'
bind-key 'C-k' if-shell "$is_vim" 'send-keys C-a C-k' 'select-pane -U'
bind-key 'C-l' if-shell "$is_vim" 'send-keys C-a C-l' 'select-pane -R'
bind-key 'C-w' if-shell "$is_vim" 'send-keys C-a C-w' 'select-pane -l'
import Data.Maybe (fromMaybe, maybeToList)
-- https://github.com/sol/interpolate
import Data.String.Interpolate
type Seconds = Int
defaultTimeout :: Milliseconds
defaultTimeout = 8
" Vim-Plug {{{
call plug#begin("~/.vim/plugged")
" Colorschemes:
Plug 'chriskempson/base16-vim'
Plug 'morhetz/gruvbox'
Plug 'tyrannicaltoucan/vim-deep-space'
Plug 'tyrannicaltoucan/vim-quantum'
@Addisonbean
Addisonbean / colors
Last active February 17, 2019 05:42
Vim colors
" dark/chill
" gruvbox
" base16-darktooth
" base16-atelier-dune (almost brown)
" base16-codeschool
" base16-railscasts
" quantum (when `let g:quantum_black = 1`)
" dark/bold/high contrast
" base16-london-tube
" base16-pop
tmux:
path: ~/.tmux.conf
source: https://gist.githubusercontent.com/Addisonbean/04fae7c50b62456c28fd7cfc08c45e5c/raw/6bdd67977c2fffc46c937d4c97a4cb4e50e5f6af/tmux.conf

1. Describe how a typical AJAX call on a web page works. Please describe the various systems involved, what they do, and how they interact.

First, a new instance of XMLHttpRequest is created: let xhr = new XMLHttpRequest();

The request can be configured using xhr.open(method, url). In the xhr.onload callback, you can check if the resource was successfully retrieved using xhr.status. The status property contains the HTTP status code of the response, so if it is 200, then the resource was retrieved successfully. If so, you can use xhr.response to get the data, or xhr.responseXML to get the parsed as XML.

Then, while still in the xhr.onload callback, some content on the page will be updated with the data received. Usually, this will involve adding content to a feed, providing suggestions for a textbox, or responding to other user interactions.

It's important to note that xhr.onload will always be fired as long as a response is received, even if it is an unsuccessful one, such as 404 Not

# TODO: use vim folds
set -g prefix C-a
bind C-a send-prefix
unbind C-b
# set -g utf8 on
# set -g status-utf8 on
set -g default-terminal "screen-256color"