Skip to content

Instantly share code, notes, and snippets.

@kunukn
kunukn / machine.js
Last active January 4, 2021 22:33
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@kunukn
kunukn / Mover.js
Created April 28, 2019 21:09
Nature of Code 2.5
class Mover {
constructor({ mass = 1, size = 40 } = {}) {
this.mass = mass;
this.location = new Vector();
this.velocity = new Vector();
this.acceleration = new Vector();
this.size = size;
}
applyForce = v => {
@kunukn
kunukn / Vector.js
Created April 28, 2019 21:07
Vector 2D
class Vector {
constructor(x, y) {
this.x = x || 0;
this.y = y || 0;
}
toString = () => `(${this.x}, ${this.y})`;
_limitApply = () => {
if (this.limitValue && this.mag() > this.limitValue)
@kunukn
kunukn / bem-utils.js
Created April 2, 2019 14:33
BEM Utils
// BEM Util
export function getModifiers(prefix, modifiers) {
if (!modifiers) return ''
const array = modifiers
.trim()
.split(' ')
.map(m => m.trim())
.filter(Boolean)
@kunukn
kunukn / rangeMap.js
Created March 31, 2019 11:26
rangeMap
// map value x in range [a,b] to [c,d]
function rangeMap(x, a, b, c, d) {
if (a === b) return c;
if (c === d) return c;
return (x - a) / (b - a) * (d - c) + c;
}
import Burger from './Burger';
const MyBurger = () => (
<Burger title="My Burger">
<Burger.Bun />
<Burger.Salat />
<Burger.Meat />
<Burger.Bun />
</Burger>
);
@kunukn
kunukn / tween.js
Last active January 23, 2018 13:41
Tween
(() => {
const root = typeof window !== 'undefined' ? window : global;
const rAF = root.requestAnimationFrame
? root.requestAnimationFrame.bind(root)
: callback => root.setTimeout(callback, 16);
const getNow = () => new Date().getTime();
const tween = ({ duration = 300, update, complete } = {}) => {
const play = () => {
if (duration <= 0) return;
(() => {
const rAF = window.requestAnimationFrame
? window.requestAnimationFrame.bind(window)
: callback => window.setTimeout(callback, 16);
const getNow = () => new Date().getTime();
const tween = ({ duration = 1000 } = {}) => {
const start = ({ update, complete } = {}) => {
const play = () => {
if (duration <= 0) return;
var feed = {
entries: [
{
title: 'title 1',
link: 'link 1',
author: 'author 1',
publishedDate: 'publishedDate 1',
categories: ['category 11', 'category 12']
},
{
!function(d, $) {
var stub = {
entries: [{
title: 'title 1',
link: 'link 1',
author: 'author 1',
publishedDate: 'publishedDate 1',
categories: ['category 11', 'category 12']
}, {
title: 'title 2',