Skip to content

Instantly share code, notes, and snippets.

View kristoferjoseph's full-sized avatar
🐈‍⬛

kj kristoferjoseph

🐈‍⬛
View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>👊✋✌️</title>
<style>
/* RESET */
* {
margin: 0;
padding: 0;
#!/usr/bin/env node
var path = require('path')
var parse = require('minimist')
var browserify = require('browserify')
var args = parse(process.argv.slice(2))
var entries = args._
var output = args.o || args.output
var main = args.m || args.main
var url = args.url || output
@kristoferjoseph
kristoferjoseph / remove.js
Created June 22, 2017 17:01
Flux pattern: How to remove an item in an Array in an immutable way
function remove (state, data) {
var active = state.active.concat()
var i = 0
var l = active.length
var item
for (i; i<l; i++) {
item = active[i]
if (item.id === data.id) {
break
}
@kristoferjoseph
kristoferjoseph / update.js
Created June 22, 2017 16:59
Flux pattern: How to update an item in an Array in an immutable way
function update (state, data) {
var active = state.active.concat()
var i = 0
var l = active.length
var item
for (i; i<l; i++) {
item = active[i]
if (item.id === data.id) {
active[i] = data
break
@kristoferjoseph
kristoferjoseph / fixed-header.html
Created May 18, 2017 18:57
Example of a fixed header html page using flexbox
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fixed header</title>
<style>
.container {
display: flex;
flex-direction: column;
position: absolute;
@kristoferjoseph
kristoferjoseph / debounce.js
Last active March 31, 2018 21:09
Debounce with immediate execution option removed
function debounce (fn, wait) {
var timeout
return function () {
var context = this
var args = Array.prototype.slice.call(arguments)
var later = function () {
timeout = null
fn.apply(context, args)
}
clearTimeout(timeout)
var html = require('yo-yo')
module.exports = function Component () {
var currentState
var element
function render (state) {
if (!element) {
currentState = state
return element = create(currentState)
@kristoferjoseph
kristoferjoseph / trite-view.js
Created March 21, 2017 22:04
Trite View component
var html = require('yo-yo')
module.exports = function View (store) {
var currentState = store.getState()
var subscribe = store.subscribe
var unsubscribe
var element
function load () {
unsubscribe = subscribe(update)
@kristoferjoseph
kristoferjoseph / AuntieSister.js
Created January 12, 2017 20:47
pseudo code for child an sibling element comparisons
function walk(n, o, update, target) {
tree = update(n, o, target)
n = n.firstChildElement
o = o.firstChildElement
target = tree.firstChildElement
while (n || o) {
walk(n, o, update)
n = n.nextElementSibling
o = n.nextElementSibling
}
@kristoferjoseph
kristoferjoseph / nanobel.js
Created January 8, 2017 05:52
Test app for nanomorph 2.0
var html = require('bel')
var nanomorph = require('nanomorph')
var cache = require('cache-element')
var stuff = [
[{
title: 1
}, {
title: 2
}, {
title: 3