Skip to content

Instantly share code, notes, and snippets.

View authenticsebastian's full-sized avatar

Authentic Seb authenticsebastian

View GitHub Profile
@authenticsebastian
authenticsebastian / click.js
Created May 16, 2018 15:26
Click on unfolded files in Github
[].slice.call(document.querySelectorAll('.js-file-header'))
.filter((item) => item.dataset.path.indexOf('{file-name-part}') > -1 && !item.parentNode.classList.contains('Details--on'))
.map((header) => header.querySelector('.js-details-target'))
.forEach((item) => item.click())
@authenticsebastian
authenticsebastian / fizz-buzz.js
Last active February 12, 2018 11:25
Functional take on FizzBuzz
const processNumber = (data, condition, message) => data + (condition ? message : '');
const hasNoRemainder = (number, divider) => number % divider === 0;
const rule = (value, message) => (number, data) =>
processNumber(data, hasNoRemainder(number, value), message);
const rules = [
rule(3, 'Fizz'),
rule(5, 'Buzz')
@authenticsebastian
authenticsebastian / monthsLater.js
Last active February 12, 2018 11:23
Calculating how many months have passed since given date
const monthsLater = (date, months) =>
[
(dateArg) => new Date(dateArg),
(dateObj) => dateObj.setMonth(dateObj.getMonth() + months),
(timestamp) => new Date(timestamp),
String
].reduce(
(value, fn) => fn(value),
date
);
@authenticsebastian
authenticsebastian / getRatio.js
Created January 3, 2018 13:20
Calculate ratio of two numbers, with lower one being 1
const getRatio = (w, h) =>
(
h/w > w/h
? [w/w, h/w]
: [w/h, h/h]
)
.map(
(number) => Number(number.toFixed(2))
)
.join(' : ');
@authenticsebastian
authenticsebastian / px2vw.js
Last active January 3, 2018 13:22
Recalculating `px` value to `vw` value for 1920px
const px2vw = (value) => (100 * value) / 1920;
@authenticsebastian
authenticsebastian / vh2vw.js
Last active January 3, 2018 13:22
Recalculating `vh` value to `vw` value for 16:9 screens
const vh2vw = (value) => value / (16 / 9);