Skip to content

Instantly share code, notes, and snippets.

@staydecent
staydecent / atom_concepts.md
Last active May 22, 2020 18:35
atom/redux concepts and best practices

atom Concepts

At Input Logic, we use atom to manange state in our React apps. atom is modeled after Redux, which is a pattern for state management that has stood up in countless apps over the years. This is a succinct overview of the atom/redux concepts and best practices we employ.

What is Redux?

The three principles are the foundation of Redux. Briefly:

const delimiter = /((?:https?:\/\/)?(?:(?:[a-z0-9]?(?:[a-z0-9\-]{1,61}[a-z0-9])?\.[^\.|\s])+[a-z\.]*[a-z]+|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})(?::\d{1,5})*[a-z0-9.,_\/~#&=;%+?\-\\(\\)]*)/ig
let strStartsWith = (str, prefix) => {
return str.slice(0, prefix.length) === prefix;
}
function Linkify ({ text, anchorProps = {} }) {
if (!text) return
return text.split(delimiter).map(word => {
import { useEffect } from 'react'
export function useDocumentClick (ref, cb) {
useEffect(() => {
const callback = (ev) => {
cb && cb(ref.current && !ref.current.contains(ev.target))
}
document.addEventListener('mousedown', callback)
document.addEventListener('touchstart', callback)
import React, { useEffect, useState, useRef } from 'react'
import { MaterialTopTabBar } from 'react-navigation'
import { request } from '@app-elements/use-request/request'
const validRouteNames = {
Clinician: ['Assessments', 'Careplans', 'Caregiving', 'Blog', 'Favorites'],
Guest: ['Assessments', 'Careplans', 'Caregiving', 'Blog', 'Favorites'],
'Home Health Aide': ['Caregiving', 'Blog', 'Favorites']
}
const variantType = require("variant-type")
const hasProp = Object.prototype.hasOwnProperty
const LikedRes = (res) => hasProp.call(res, 'liked')
// We will use a "variant type" aka "tagged union" aka "sum type".
// This is sort of like a finite-state-machine, in that the "Request"
// value can only ever represent one of the following "states".
const Request = variantType({
Loading: [],
@staydecent
staydecent / lispy.js
Last active February 15, 2020 01:29
Lisp interpretor in JS, based on http://www.norvig.com/lispy.html
const check = require('check-arg-types')
const type = check.prototype.toType
const tokenize = str =>
str.replace(/\(/g, ' ( ').replace(/\)/g, ' ) ').split(' ').filter(x => !!x)
const atom = token =>
isNaN(Number(token)) ? String(token) : Number(token)
const readFromTokens = tokens => {
const seq = (...args) => input => args.reduce((acc, el) => el(acc), input)
const cons = (a, b) => fn => fn(b == null ? b : a, b || a)
const car = pair => pair((a, b) => a)
const cdr = pair => pair((a, b) => b)
const tree = comp => seq(car(comp), cdr(comp))
const isCons = fn => fn.toString() === 'fn => fn(b == null ? b : a, b || a)'
;((win, doc) => {
const tags = ["a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "big", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hr", "html", "i", "iframe", "img", "input", "ins", "kbd", "keygen", "label", "legend", "li", "link", "main", "map", "mark", "menu", "menuitem", "meta", "meter", "nav", "noframes", "n
const seq = (...args) => input => args.reduce((acc, el) => el(acc), input)
const cons = (a, b) => fn => fn(a, b)
const car = pair => pair((a, b) => a)
const cdr = pair => pair((a, b) => b)
const render = Comp => seq(car(Comp), cdr(Comp))
const App = cons(state => state.count, count => `Count ${count}`)
console.log(
render(App)({count: 2})
@staydecent
staydecent / alacritty.yml
Created October 10, 2019 19:57
Alacritty config
# Configuration for Alacritty, the GPU enhanced terminal emulator.
# Any items in the `env` entry below will be added as
# environment variables. Some entries may override variables
# set by alacritty itself.
#env:
# TERM variable
#
# This value is used to set the `$TERM` environment variable for
# each instance of Alacritty. If it is not present, alacritty will
@staydecent
staydecent / OceanFade-Light.tmTheme
Last active October 9, 2019 23:38
OceanFade.tmTheme — theme inspired by Light Table's Default and faded ocean moods
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>OceanFade-Light</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>