Skip to content

Instantly share code, notes, and snippets.

View jamonholmgren's full-sized avatar

Jamon Holmgren jamonholmgren

View GitHub Profile
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
import { Maze } from "./maze";
const Main = document.createElement("main");
Object.assign(Main.style, {
backgroundColor: "#602F6B",
width: "600px",
height: "600px",
position: "relative"
});
function updateHamster() {
Object.assign(hamster.style, {
left: `${state.x * 30}px`,
top: `${state.y * 30}px`,
transitionDuration: "0.5s"
});
}
const hamster = document.createElement("div");
Object.assign(hamster.style, {
width: "30px",
height: "30px",
backgroundColor: "#b6102a",
borderRadius: "15px",
position: "absolute"
});
Main.appendChild(hamster);
/* 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 ],
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"
@jamonholmgren
jamonholmgren / shorteners.zsh
Last active February 20, 2020 04:51
Lets you shorten URLs from your terminal -- assuming you have a Netlify shortener installed per https://github.com/kentcdodds/netlify-shortener
# 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:
@jamonholmgren
jamonholmgren / raw-data-npm-vs-yarn.txt
Created January 31, 2020 18:08
Yarn 1 vs Yarn 2 vs NPM article
Things that are important to us in a JS package manager
Yarn - NPM - Description
✔ ✔ 1. Predictability -- will install the same packages every time
✔ ✔ 2. Reliability -- it's not flaky / fail randomly
✔ ✔ 3. Caching -- local installs wherever possible (less network traffic/bandwidth)
✔ X 4. Speed -- needs to be fast
✔ ✔ 5. Cost of change -- needs to be manageable, both in terms of technical and also training-wise
✔ ✔ 6. Feature: outdated
✔ ✔ 7. Feature: interactive-upgrade
✔ ✔ 8. Broad support -- works with React Native, Node CLIs, web, etc
@jamonholmgren
jamonholmgren / webview-detect-fullscreen.jsx
Last active May 30, 2023 12:14
Example of detecting when a YouTube video goes full screen or ends full screen in React Native WebView.
const App = () => {
return (
<>
<WebView
injectedJavaScript={`
(function() {
setTimeout(() => {
const video = document.getElementsByClassName("html5-main-video")[0]
video.addEventListener('webkitbeginfullscreen', (event) => {
window.ReactNativeWebView.postMessage("Full Screen");
@jamonholmgren
jamonholmgren / react-native-yoga-issue.md
Created September 27, 2019 16:40
Issue building React Native ios -- yoga

I was running into a React Native build issue where I was getting this (only captured part of the error message, unfortunately):

Target Support Files/yoga/yoga.xcconfig: unable to open file (in target "yoga" in project "Pods") (in target 'yoga' from project 'Pods')

To fix:

rm -rf ios/build