This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define ARRAY_CAPACITY_INDEX 0 | |
#define ARRAY_LENGTH_INDEX 1 | |
#define ARRAY_DATA_START_INDEX 2 | |
#define capacity(array) array[ARRAY_CAPACITY_INDEX] | |
#define length(array) array[ARRAY_LENGTH_INDEX] | |
#define get(array, index) array[ARRAY_DATA_START_INDEX + index] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Calculates the euclidean distance between two N-dimensional | |
* points, represented as arrays of length N. | |
*/ | |
export function euclideanDistance<P extends [number, ...number[]]>( | |
p1: P, | |
p2: P, | |
): number { | |
if (p1.length === 1) { | |
return Math.abs(p1[0] - p2[0]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-check | |
const ALIVE = 1; | |
const DEAD = 0; | |
/** | |
* @param {0 | 1} cell | |
* @param {number} nNeighbours | |
*/ | |
function getNextCell(cell, nNeighbours) { | |
if (cell === DEAD) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function estimateExpectedNumberOfGroups(n: number, iterations: number = 2000): number { | |
const groupCounts = range(iterations).map(() => | |
countGroups(createPairsOfPeople(n)) | |
); | |
return mean(groupCounts); | |
} | |
type Pair<T> = readonly [T, T]; | |
function countGroups(pairsOfPeople: Iterable<Pair<number>>): number { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export module Maybe { | |
enum MaybeKind { | |
SOME = 1, | |
NOTHING, | |
} | |
export type Nothing = { kind: MaybeKind.NOTHING }; | |
export type Some<T> = { kind: MaybeKind.SOME; value: T }; | |
export type t<T> = Some<T> | Nothing; | |
export const nothing = (): Nothing => ({ kind: MaybeKind.NOTHING }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const renderBootstrap = body => `const modules = {}; | |
function require(name) { | |
return modules[name] && modules[name].exports; | |
} | |
function define(name, definition) { | |
const module = {}; | |
definition(require, module); | |
modules[name] = module; | |
} | |
${body} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" plugins | |
call plug#begin('~/.vim/plugged') | |
Plug 'pangloss/vim-javascript' | |
Plug 'mxw/vim-jsx' | |
Plug 'leafgarland/typescript-vim' | |
Plug '/usr/local/opt/fzf' | |
Plug 'junegunn/fzf.vim' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let range = length => Array.from({ length }, (_, i) => i) | |
let template = (params, args) => `let calls = 0 | |
let r = (${params}) => { | |
calls++ | |
r(${args}) | |
} | |
try { | |
r(${args}) | |
} catch (_) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import { Redirect, Route, RouteComponentProps } from 'react-router'; | |
type RouteWithQueryParamsProps<R extends string, O extends string> = { | |
path: string; | |
params: readonly ({ | |
name: R; | |
required: true; | |
} | { | |
name: O; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::env; | |
use std::fs; | |
use std::io; | |
use std::path::Path; | |
use std::str; | |
fn main() -> io::Result<()> { | |
let args: Vec<String> = env::args().collect(); | |
let pattern = &args[1]; | |
let path = &args[2]; |