Skip to content

Instantly share code, notes, and snippets.

View kennetpostigo's full-sized avatar
🏠
Working from home

Kennet Postigo kennetpostigo

🏠
Working from home
View GitHub Profile
@kennetpostigo
kennetpostigo / Migrating.md
Last active June 2, 2021 17:44
How I migrated from ReactRouter v2 to v4

First couple things I thought about when migrating after reading the docs

So migrating my existing app wasn't as troublesome as I originally thought. First thing I did was take a look at my router and routes and figure try to make a mental model of all the files where I had nested routes in the existing app because those components/containers will contain {this.props.children}. So I need to replace those with the nested <Match /> components.

So just to give an example:

In v2:

<Router history={history}>
  <Route path="/" component={App}>
@kennetpostigo
kennetpostigo / ReasonBSTADTNPM.re
Last active October 8, 2019 03:54
Reason BST Primer for Blog Post algebraic data types + pattern matching
type worker = {
name: string,
age: int,
};
type workStatus =
| Unemployed(worker)
| Fulltime(worker)
| Parttime(worker);
@kennetpostigo
kennetpostigo / ReasonBST.re
Created June 22, 2018 22:45
Reason BST Modeling for Blog Post
type binarySearchTree('a) =
| Empty
| Node(node('a))
and node('a) = {
value: 'a,
left: binarySearchTree('a),
right: binarySearchTree('a),
};
let empty = Empty;
@kennetpostigo
kennetpostigo / ReasonBSTFun.js
Last active June 22, 2018 22:56
Reason BST Blog Post Function Usage
/*Single line function named square*/
let square = x => x * x;
/* Multiline function named logNSquare */
let logNSquare = x => {
let squared = x * x;
Js.log(squared);
squared;
};
@kennetpostigo
kennetpostigo / ReasonBSTInsert.re
Created June 22, 2018 23:02
Reason BST Blog Post insert
let rec insert = (tree, compare, v) =>
switch (tree) {
| Empty => Node({value: v, left: Empty, right: Empty})
| Node({value, left, right}) =>
if (compare(v, value) == (-1)) {
Node({value, left: insert(left, compare, v), right});
} else if (compare(v, value) == 1) {
Node({value, left, right: insert(right, compare, v)});
} else {
tree;
@kennetpostigo
kennetpostigo / ReasonBSTCompare.re
Created June 22, 2018 23:06
Reason BST Blog Post compare
let compare = (f, s) =>
if (f < s) {
(-1);
} else if (f > s) {
1;
} else {
0;
};
@kennetpostigo
kennetpostigo / ReasonBSTRemove.re
Created June 22, 2018 23:21
Reason BST Blog Post remove
let rec remove = (tree, compare, v) =>
switch (tree) {
| Empty => Empty
| Node({value, left: Empty, right: Empty}) =>
compare(v, value) == 0 ? Empty : tree
| Node({value, left: Node(_) as left, right: Empty as right}) =>
compare(v, value) == 0 ?
left : Node({value, left: remove(left, compare, v), right})
| Node({value, left: Empty as left, right: Node(_) as right}) =>
compare(v, value) == 0 ?
@kennetpostigo
kennetpostigo / ReasonBSTMin.re
Created June 22, 2018 23:24
Reason Blog Post min
let rec min = node =>
switch (node) {
| Empty => Empty
| Node({value, left, right}) =>
if (left == Empty) {
node;
} else {
min(left);
}
};
@kennetpostigo
kennetpostigo / ReasonGenericPhantomType.re
Last active June 23, 2018 00:40
Reason Phantom Types Blog Post generic phantom type
type t('a) = string;
@kennetpostigo
kennetpostigo / ReasonAnimalType.re
Last active June 23, 2018 00:42
Reason Phantom Type Animal module type
module type Animal = {
/* Define abstract types t, dog, and cat */
type t('a);
type dog;
type cat;
/* helpers to create a type dog or cat */
let makeDog: string => t(dog);
let makeCat: string => t(cat);
let mate: (t('a), t('a)) => string;