Skip to content

Instantly share code, notes, and snippets.

View queckezz's full-sized avatar

Fabian Eichenberger queckezz

View GitHub Profile
@queckezz
queckezz / machine.js
Created January 27, 2020 16:36
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@queckezz
queckezz / longest-increasing-subsequence.js
Created November 3, 2018 09:36
longest increasing subsequence
function longestIncreasingSubsequence(arr) {
return arr.slice(0, arr.lastIndexOf(-1)).reduce(
(acc, val) => {
if (acc.prev == null) {
return { ...acc, prev: val }
}
if (val > acc.prev) {
return { ...acc, count: acc.count + 1, prev: val }
} else {
@queckezz
queckezz / index.js
Created November 18, 2017 21:44
sort urls alphabetically
function sortUrls(urls) {
return urls
.map(link => {
const normalizedLink = /^(https?:\/\/)?(www\.)?/.exec(link)[0]
return [link.replace(normalizedLink, ''), normalizedLink]
})
.sort(([a], [b]) => {
if(a < b) return -1
if(a > b) return 1
return 0
@queckezz
queckezz / simplex.js
Created January 24, 2017 11:42
simplex noise demo, sampling values from black to white
const FastSimplexNoise = require('fast-simplex-noise').default
const fill2d =
(rows, cols, fn) => Array(rows)
.fill(true)
.map((_, x) => {
return Array(cols)
.fill(true)
.map((_, y) => {
@queckezz
queckezz / index.js
Created July 8, 2016 14:45
react, recompose, xstream
import { componentFromStream, setObservableConfig } from 'recompose'
import xstreamConfig from 'recompose/xstreamObservableConfig'
import { h, p, div, h1, h2 } from 'react-hyperscript-helpers'
import { render } from 'react-dom'
import xs from 'xstream'
setObservableConfig(xstreamConfig)
const Users = componentFromStream((props$) => {
@queckezz
queckezz / 01_overview.md
Last active June 26, 2017 19:48
yo-yo redux counter example

overview

@queckezz
queckezz / 0_index.md
Last active December 8, 2015 11:21
CSS in javascript with redux

Overview

After a style dispatch, the middleware hashes the style object and looks up if its already in the cache. If not, add the given classname to the document and add it to the cache:

  • Dispatch action to store { type: '...', payload: { ...styles }}
  • Hash StyleObject -> '646efd54'
  • Check if style is already in cache
  • Store renders style to client (or could be anything: server-side to string etc.)
  • Return hash
@queckezz
queckezz / index.js
Last active December 2, 2015 18:59
react better createElement (temporary until r-dom)
import { createElement } from 'react'
const isChildren = arr => typeof arr == 'string' || Array.isArray(arr)
const create = (tag, props, children) => {
if (Array.isArray(children)) {
return createElement(tag, props, ...children)
} else {
return createElement(tag, props, children)
@queckezz
queckezz / 1_1.js
Last active December 8, 2015 10:22
css in js
import {
em
} from './utils'
import zyle from 'zyle'
function initStyles(dispatch) {
const gen = zyle(dispatch)
function contain (width = 56) {
@queckezz
queckezz / 00_index.md
Last active January 6, 2016 18:58
Java Snippets