Skip to content

Instantly share code, notes, and snippets.

@tdreyno
tdreyno / church.js
Created Apr 22, 2020
Basic church encoding in JS
View church.js
// Lambda calculus: Church 1940-ish
//
// <expression> := <name> | <function> | <application>
// <function> := λ <name>.<expression>
// <application> := <expression><expression>
//
// expression := name | function | application
// function := name => expression
// application := expression(expression)
//
@tdreyno
tdreyno / to.ts
Last active Jan 9, 2020
Helper method to make `reduce(to(` be a somewhat awkard way to transform arrays to other types.
View to.ts
export function to<A, T>(fn: (items: A[]) => T) {
return (sum: any, _item: A, index: number, all: A[]): T => {
const isLast = index === all.length - 1;
if (!isLast) {
return sum;
}
return fn(all);
};
View TasksLoading.ts
export function loadStories(userId: string) {
return Task.map2(
myStories => storiesSharedWithMe =>
({
myStories,
storiesSharedWithMe,
}),
userStories(userId).map(listToLookup),
userSharedStories(userId).map(listToLookup),
@tdreyno
tdreyno / andThen.ts
Last active Oct 23, 2019
It's like map, but you get the whole list.
View andThen.ts
interface Array<T> {
andThen: <U>(this: T[], fn: (items: T[]) => U) => U;
}
Array.prototype.andThen = function<T, U>(this: T[], fn: (items: T[]) => U): U {
return fn(this);
};
View 1-demo.ts
// Vector of number types
const v1 = vector([1, 2, 3, 4]);
console.log(v1.toString());
// Vector of string types
const v2 = vector(["a", "b", "c", "d"]);
console.log(v2.toString());
// Vector of vector types
View button.tsx
import React from 'react';
import { stylesheet, css } from '../../util';
import {
MEDIUM_COLOR,
LIGHT_PRIMARY_TEXT_COLOR,
BUTTON_LINK_TYPE,
LIGHT_COLOR,
} from '../../styles';
const STYLES = stylesheet({
View cssInJS.ts
import {
StyleSheet,
css as stylesheetToClassNames,
} from 'aphrodite';
import { Map } from 'immutable';
const Prefixer = require('inline-style-prefixer');
import { DEVELOPMENT } from '../config';
const prefixer = new Prefixer({ userAgent: navigator.userAgent });
View tslint.json
{
"rules": {
"align": [true, "parameters", "statements"],
"arrow-parens": true,
"class-name": true,
"comment-format": [
true,
"check-space"
],
"curly": true,
View gist:ab5431caabaddc907e1dbbec4ec141a6
const country = (seg) => /^[a-z]{2}$/.test(seg);
const midPrefix = (seg) => /^m|g$/.test(seg);
const midValue = (seg) => /^[a-zA-Z0-9_]+$/.test(seg);
const coMidPrefix = (seg) => /^m|g$/.test(seg);
const coMidValue = (seg) => /^[a-zA-Z0-9_]+$/.test(seg);
const darkNews = (seg) => seg === DARK_LABEL;
const year = (seg) => /^[0-9]{4}/.test(seg);
const month = (seg) => /^[0-9]{2}/.test(seg);
const day = (seg) => /^[0-9]{2}/.test(seg);
View keybase.md

Keybase proof

I hereby claim:

  • I am tdreyno on github.
  • I am tdreyno (https://keybase.io/tdreyno) on keybase.
  • I have a public key whose fingerprint is 0D56 40C3 629D 4F02 3108 0B9B 5DD3 A3D3 D928 68DE

To claim this, I am signing this object: