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 { Maze } from "./maze"; | |
const state = { | |
x: 1, | |
y: 1, | |
destX: 1, | |
destY: 1, | |
path: [[1, 2], [2, 2], [3, 2], [3, 1], [4, 1], [5, 1], [5, 2]] | |
}; |
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 { Maze } from "./maze"; | |
const state = { | |
x: 1, | |
y: 1, | |
destX: 1, | |
destY: 1, | |
path: [[1, 2], [2, 2], [3, 2], [3, 1], [4, 1], [5, 1], [5, 2]] | |
}; |
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
// did we find the destination? | |
if (lowestCostNode.x === state.destX && lowestCostNode.y === state.destY) { | |
// retrace our steps back to the beginning! | |
function retrace(node, path) { | |
// did we find the origin? if so, we're done! | |
if (node.previous === undefined) return [node, ...path] | |
// not yet ... let's keep retracing our steps | |
return retrace(node.previous, [ node, ...path ]) | |
} | |
// kick off the retracing! |
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 exploreNodes(nodes, exploredNodes) { | |
if (nodes.length === 0) return | |
// sort nodes by cost | |
nodes.sort((a, b) => a.cost < b.cost ? -1 : 0) | |
// remove the lowest cost node from the list | |
const lowestCostNode = nodes.shift() | |
// add it to the explored nodes |
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 { Maze } from "./maze"; | |
const Main = document.createElement("main"); | |
Object.assign(Main.style, { | |
backgroundColor: "#602F6B", | |
width: "600px", | |
height: "600px", | |
position: "relative" | |
}); |
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 updateHamster() { | |
Object.assign(hamster.style, { | |
left: `${state.x * 30}px`, | |
top: `${state.y * 30}px`, | |
transitionDuration: "0.5s" | |
}); | |
} |
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 hamster = document.createElement("div"); | |
Object.assign(hamster.style, { | |
width: "30px", | |
height: "30px", | |
backgroundColor: "#b6102a", | |
borderRadius: "15px", | |
position: "absolute" | |
}); | |
Main.appendChild(hamster); |
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
/* eslint-disable no-sparse-arrays */ | |
const W = "wall"; | |
// prettier-ignore | |
export const Maze = [ | |
[ W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W, W ], | |
[ W, , , , , , , , , , , , , , , , , , , W ], | |
[ W, , , , , , , , , , , , , , , , , , , W ], | |
[ W, , , , , , , , , , , , , , , , , , , W ], | |
[ W, , , , , , , , , , , , , , , , , , , W ], |
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 { types, flow } from "mobx-state-tree" | |
import Api from '...' | |
export const UserStore = types.model({ | |
user: types.reference(User), | |
fetchStatus: types.enumeration(["success", "pending", "error"]) | |
}) | |
.actions(store => ({ | |
fetchUser: flow(function* (id) { | |
store.fetchStatus = "pending" |
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
# URL shortener scripts by Jamon Holmgren, 2020-02-19 | |
# License: MIT | |
# | |
# Setup: | |
# 1. Follow Kent C. Dodds' video to create a new URL shortener with Netlify: https://www.youtube.com/watch?v=HL6paXyx6hM | |
# 2. Clone it to your local machine (I put it in ~/Code/shortener) | |
# 3. Modify this file to point to the right file | |
# 4. Add `source ~/path/to/this/shortner.zsh` to your .zshrc (note this was only tested with zsh) | |
# | |
# Usage: |