Skip to content

Instantly share code, notes, and snippets.

View abiodun0's full-sized avatar

Abiodun abiodun0

View GitHub Profile
@abiodun0
abiodun0 / jsdominit.js
Last active July 10, 2017 10:07
sample New JSDOM config and some extras
const dotenv = require('dotenv');
dotenv.config();
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`);
global.document = dom.window.document;
global.window = document.defaultView;
@abiodun0
abiodun0 / checkbox.jsx
Created July 4, 2017 22:47
React RxJS and Checkbox
import React from "react";
import Connect from "../connect";
const initialState = {
isActive: false
};
const toggle = state => Object.assign({}, state, { isActive: !state.isActive });
const updaters = {
@abiodun0
abiodun0 / optimized.js
Last active July 10, 2017 15:46
composing withstate
// Keep it simple
import React from 'react';
import { render } from 'react-dom';
import hoistNonReactStatic from 'hoist-non-react-statics';
const increment = multiply => ({ counter }, { step }) => ({
counter: counter + step * multiply,
});
@abiodun0
abiodun0 / contramap-functor.js
Last active August 13, 2021 21:11
Contramap and functors in js. react as an example
import React from 'react'
// Comp:: a -> JSX;
const Comp = g => ({
fold: g,
contramap: f => Comp(x => g(f(x))),
concat: other => Comp((x) => <div> {g(x)} {other.fold(x)} </div>)
});
// Reducer :: (a, b) -> a
@abiodun0
abiodun0 / ramdareact.js
Created August 2, 2017 21:50
When react act as the v.. composable view with Ramda
import React from "react";
import { render } from "react-dom";
import R from "ramda";
const users = [
{ id: 1, name: "foo", points: 45 },
{ id: 2, name: "bar", points: 22 },
{ id: 3, name: "baz", points: 79 },
{ id: 4, name: "bla", points: 54 }
];
@abiodun0
abiodun0 / daggy.ts
Last active August 6, 2017 06:39
Daggy typescript implementation
//
// product types
//
/*
// A coordinate in 3D space
export type Coord = {
readonly x: number
readonly y: number
readonly z: number
@abiodun0
abiodun0 / ui-states.re
Created August 18, 2017 16:44
Display UI states nicely in reason
/* Slaying a UI Anti Pattern in Reason */
type remoteData 'e 'a =
| Nothing
| Loading
| Failure 'e
| Success 'a;
type item = {
userId: int,
@abiodun0
abiodun0 / tic-tac-toc.ts
Created September 1, 2017 16:27
Type safety with ts
/*
Type Tac Toe: Advanced Type Safety
==================================
Adapted from http://chrispenner.ca/posts/type-tac-toe
*/
/** Either X, O, or Nothing */
type Piece = 'X' | 'O' | 'N'
/** coordinates */
@abiodun0
abiodun0 / flip.ts
Created October 4, 2017 10:02
Problems with ts
// Typescript can handle monomoprhic functions
const flip = <A, B, C>(f: (a: A) => (b: B) => C): ((b: B) => (a: A) => C) => b => a => f(a)(b)
const foo = (a: string) => (b: number) => a.length - b
// fooFlipped: (b: number) => (a: string) => number
const fooFlipped = flip(foo)
// But can't handle polymorphic functions
const concat = <A>(xs: Array<A>) => (a: A): Array<A> => xs.concat([a])
@abiodun0
abiodun0 / higherOrderAbstractSyntax.hs
Created October 10, 2017 01:20
Higher-order abstract syntax for any cartesian-closed category
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module CCCs where