Skip to content

Instantly share code, notes, and snippets.

View enjoylife's full-sized avatar
📖

Matthew Clemens enjoylife

📖
View GitHub Profile
@enjoylife
enjoylife / machine.js
Last active August 29, 2022 05:57
Generated by XState Viz: https://xstate.js.org/viz
// Immer
// ...
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e=e||self).immer={})}(this,function(e){"use strict";var r,t="undefined"!=typeof Symbol?Symbol("immer-nothing"):((r={})["immer-nothing"]=!0,r),n="undefined"!=typeof Symbol&&Symbol.for?Symbol.for("immer-draftable"):"__$immer_draftable",o="undefined"!=typeof Symbol&&Symbol.for?Symbol.for("immer-state"):"__$immer_state";function i(e){return!!e&&!!e[o]}function a(e){return!!e&&(function(e){if(!e||"object"!=typeof e)return!1;if(Array.isArray(e))return!0;var r=Object.getPrototypeOf(e);return!r||r===Object.prototype}(e)||!!e[n]||!!e.constructor[n])}var f=Object.assign||function(e,r){for(var t in r)l(r,t)&&(e[t]=r[t]);return e},s="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames;function c(e,r){
@enjoylife
enjoylife / machine.js
Last active September 28, 2019 05:48
Generated by XState Viz: https://xstate.js.org/viz
const resetableEditableContext = () => {
return {
pushing: {
updates: [],
error: null,
lastSuccess: null,
},
pulling: {
error: null,
@enjoylife
enjoylife / machine.js
Last active September 27, 2019 05:11
Generated by XState Viz: https://xstate.js.org/viz
const resetableEditableContext = () => {
return {
pushing: {
updates: [],
error: null,
lastSuccess: null,
},
pulling: {
error: null,
@enjoylife
enjoylife / .block
Created September 18, 2019 12:46 — forked from kerryrodden/.block
Sequences sunburst (d3 v4)
license: apache-2.0
@enjoylife
enjoylife / nested.example.js
Created March 21, 2019 16:04 — forked from tim-field/useRouter.js
Hooks Router & Nested relative Routes
function Parent(props) {
return (
<>
<Link to='/child'>Child</Link>
<Route path='/child' component={Child}/>
</>
);
}
function Child({match}) {
@enjoylife
enjoylife / option-func-example.go
Last active March 10, 2019 05:07
Practical example using functional options for creating extendable functions in Go(golang).
package main
import (
"flag"
"fmt"
)
// An ServerOption configures our Server
type ServerOption interface {
apply(s *Server) // 😈 an option is now ours and ours alone to implement
// @flow
import {useState, useEffect} from 'react';
// Hook
export default function useLocalStorage(key, initialValue) {
// State to store our value
// Pass initial state function to useState so logic is only executed once
const [storedValue, setStoredValue] = useState(() => {
try {
// Get from local storage by key
@enjoylife
enjoylife / util_types.go
Last active March 1, 2019 23:36
One of the more common things one writes/needs during day to day development in a Go based repo is utility types which handle edge cases in, what are usually rest api's or weird 3rd party interfaces.
package util
import (
"fmt"
"strconv"
"strings"
"time"
)
func GetJSONFieldName(i interface{}, goFieldName string) string {
field, ok := reflect.TypeOf(i).Elem().FieldByName(goFieldName)
if !ok {
return ""
}
tag, ok := field.Tag.Lookup("json")
if !ok {
return ""
}
commaIndex := strings.Index(tag, ",")