Skip to content

Instantly share code, notes, and snippets.

Benjamin De Cock bendc

Block or report user

Report or block bendc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bendc
bendc / assign.js
Created Jun 25, 2018
Unified object assignment
View assign.js
const assign = (target, key, value) =>
Object.assign(target, Object(key) === key ? key : {[key]: value});
@bendc
bendc / sets.js
Created Jan 31, 2018
Sets: Union, Intersection and Difference
View sets.js
const union = (...sets) =>
sets.reduce((acc, set) => {
set.forEach(val => acc.add(val));
return acc;
}, new Set);
const intersection = (...sets) =>
sets.reduce((acc, set) => {
set.forEach(val => {
if (sets.every(set => set.has(val)))
@bendc
bendc / list.js
Last active Jan 15, 2018
Array of arbitrary number of items
View list.js
const list = (length, callback) =>
Array.from({length}, (hole, index) => callback(index));
@bendc
bendc / simulate-typing.js
Created Sep 1, 2017
Fake typing animation
View simulate-typing.js
const trackTime = timing => {
const now = performance.now();
if (!timing.startTime) timing.startTime = now;
const elapsed = now - timing.startTime;
const {duration} = timing;
if (duration != null && duration <= elapsed) timing.startTime = null;
return elapsed;
};
const delay = (callback, duration) => {
@bendc
bendc / personal-raf-boilerplate.js
Last active Jan 21, 2018
requestAnimationFrame boilerplate code
View personal-raf-boilerplate.js
"use strict";
// animation utils
// ===============
const trackTime = timing => {
const now = performance.now();
if (!timing.startTime) timing.startTime = now;
const elapsed = now - timing.startTime;
@bendc
bendc / raf-boilerplate.js
Created Aug 28, 2017
rAF tutorial: boilerplate code
View raf-boilerplate.js
"use strict";
// animation utils
// ===============
const trackTime = id => {
const [entry] = performance.getEntriesByName(id);
if (!entry) {
performance.mark(id);
@bendc
bendc / raf-delay.js
Created Aug 28, 2017
rAF tutorial: better setTimeout
View raf-delay.js
const delay = (callback, duration) => {
const tick = () =>
getProgress(time) < 1 ? requestAnimationFrame(tick) : callback();
const time = {
duration,
id: requestAnimationFrame(tick)
};
};
@bendc
bendc / raf-performance-mark.js
Created Aug 28, 2017
rAF tutorial: advanced time tracking
View raf-performance-mark.js
const trackTime = id => {
const [entry] = performance.getEntriesByName(id);
if (!entry) {
performance.mark(id);
return 0;
}
return performance.now() - entry.startTime;
};
const getProgress = ({duration, id}) => {
@bendc
bendc / raf-svg-morphing.js
Created Aug 25, 2017
rAF tutorial: SVG morphing
View raf-svg-morphing.js
// polygon's points
const shapes = {
play: [85, 70, 180, 125, 180, 125, 85, 180],
stop: [85, 85, 165, 85, 165, 165, 85, 165]
};
const tick = now => {
// calculate the current position of each point
const points = shapes.play.map((start, index) => {
const end = shapes.stop[index];
@bendc
bendc / raf-ease-out.js
Created Aug 24, 2017
rAF tutorial: ease-out equation
View raf-ease-out.js
const easeOut = progress =>
Math.pow(--progress, 5) + 1;
You can’t perform that action at this time.