Skip to content

Instantly share code, notes, and snippets.

View xaviervia's full-sized avatar

Fernando Via Canel xaviervia

View GitHub Profile
@xaviervia
xaviervia / imperative-sum.js
Last active January 14, 2017 17:53
A verbose and redundant version of an imperative sum in fantasy-land functional style
const Add = x => ({
x,
concat: ({x: y}) => x + y,
fold: f => f(x)
})
const Box = x => ({
x,
map: f => Box(f(x)),
fold: f => f(x)
@xaviervia
xaviervia / collecting-idle-fps.js
Created January 12, 2017 10:01
Plain collect FPS
import collectFPS from 'collect-fps'
window.onload = () => collectFPS(60, (_, x) => console.log(x))
@xaviervia
xaviervia / currentBranch.js
Created January 4, 2017 16:59
Task for getting the current branch name as a Flux action
const Task = require('data.task')
const {Repository, Branch} = require('nodegit')
const {cond, is, T} = require('ramda')
const currentBranch = () =>
new Task((rej, res) =>
Repository.open('.')
.then(repo => repo.getCurrentBranch()
.then(branch => Branch.name(branch).then(name => res(name))))
.catch(() => res()))
@xaviervia
xaviervia / IncrementStore.js
Last active January 4, 2017 16:11
Flux-like IncrementStore as a Monoid
const IncrementStore = state => ({
state,
concat: ({state: delta}) => {
switch (delta.type) {
case 'ADD':
return IncrementStore({
value: state.value + 1
})
case 'REMOVE':
@xaviervia
xaviervia / README.md
Last active December 20, 2016 22:27
rest subscriber

Automatically retries until all three checks are solved

It starts out with:

const initialState = {
  checks: {
    one: undefined,
    two: undefined,
 three: undefined
@xaviervia
xaviervia / cell.js
Created December 10, 2016 15:02
zazen.cell
type Input = any
type EffectCell = {
lastInputs: Array<Input>,
computation: (inputs: Array<Input>) => Array<Input>,
effect: (inputs: Array<Input>) => void,
dependants: Array<Cell>
}
const computation0 = Cell()
@xaviervia
xaviervia / createApp.js
Created December 3, 2016 15:05
Tessellation v1 app lib.
export default (reducer, initialState, effects) => {
let state = initialState
let listeners = []
const broadcast = (state) => {
listeners.forEach((listener) => listener(state))
}
const push = (action) => {
state = reducer(state, action)
  • em dash: –
  • ellipsis: …
@xaviervia
xaviervia / comment-nodes-in-react.js
Created September 27, 2016 14:43
How to add Comment Nodes in React
import React from 'react'
const NODE_COMMENT = 8
export default React.createClass({
displayName: 'CommentNodeInSpan',
render () {
const {comment} = this.props
import React from 'react'
import { render } from 'react-dom'
import * as UI from '@klarna/ui'
const Workshop = React.createClass({
getInitialState () {
return { open: false }
},
render () {