Skip to content

Instantly share code, notes, and snippets.

@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 / undom.js
Created September 26, 2019 00:51
undom with support for mutation observers and PreactX
function assign (obj, props) {
for (var i in props) obj[i] = props[i]
}
function toLower (str) {
return String(str).toLowerCase()
}
function splice (arr, item, add, byValueOnly) {
var i = arr ? findWhere(arr, item, true, byValueOnly) : -1
@staydecent
staydecent / terminus-config.yml
Created September 17, 2019 16:15
Terminus Config
hotkeys:
profile: {}
shell: {}
close-tab: []
close-pane:
- - Ctrl-Shift-W
pane-nav-up:
- - Ctrl-Alt-Up
- - Ctrl-Shift-Up
pane-nav-down:
@staydecent
staydecent / use-mapped-state.js
Created September 12, 2019 19:35
useMappedState
import { useEffect, useReducer, useRef } from 'react' // alias to 'preact/hooks'
import equal from '@app-elements/equal'
export function useMappedState (store, mapper) {
const [, forceRender] = useReducer(n => n + 1, 0)
const mapperRef = useRef()
const stateRef = useRef()
let mappedState = mapper !== mapperRef.current
@staydecent
staydecent / hooks.md
Last active August 30, 2019 21:38
Hooks

Why migrate from class to hooks?

class is syntactic sugar that abstracts prototypal inheritance, making it appear more familiar to those coming from languages with classical inheritance, but does not actually introduce a classical object-oriented inheritance model.

So, it’s basically a LIE.

React docs recommend AGAINST using inheritance to share functionality anyway

So why did they introduce class based components??

const handler = {
get (obj, prop) {
if (prop in obj) {
if (typeof obj[prop] === 'object') {
return new Proxy(obj[prop], handler)
}
return obj[prop]
}
return new Proxy({}, handler)
}
@staydecent
staydecent / ios_rn_deployment.md
Created December 11, 2018 23:09
iOS deployment for React Native projects via Fastlane

iOS Deployment

  • Create an App ID in the Apple Developer portal
  • Add a new App on App Store Connect (may need to wait for App ID to be available)
  • In you xcode project make sure Automatic code signing is checked and a development team is chosen
  • cd ios/ && fastlane init
  • When you are ready: fastlane beta

Sample Fastline config