Skip to content

Instantly share code, notes, and snippets.

View renaudtertrais's full-sized avatar

Renaud TERTRAIS renaudtertrais

View GitHub Profile
@renaudtertrais
renaudtertrais / zip.js
Created July 5, 2016 13:59
A simple ES6 zip function
const zip = (arr, ...arrs) => {
return arr.map((val, i) => arrs.reduce((a, arr) => [...a, arr[i]], [val]));
}
// example
const a = [1, 2, 3];
const b = [4, 5, 6];
const c = [7, 8, 9];
@renaudtertrais
renaudtertrais / _positions.scss
Last active February 5, 2022 17:34
Sass position mixins
// ----
// Sass (v3.4.14)
// Compass (v1.0.3)
// ----
@mixin pos-absolute($positions...){
position: absolute;
@include position($positions...);
}
@renaudtertrais
renaudtertrais / compose.js
Last active December 16, 2020 06:34
Simple ES6 compose & pipe function
const compose = (...fns) => (...args) => {
return fns.slice(0, -1).reduceRight((res, fn) => fn(res),
fns[fns.length -1].apply(null,args)
);
};
const pipe = (f1, ...fns) => (...args) => {
return fns.reduce((res, fn) => fn(res), f1.apply(null,args));
};
[
{
"country": "Afghanistan",
"continent": "Asia"
},
{
"country": "Albania",
"continent": "Europe"
},
{
.observablehq .octicon {
display: inline-block;
fill: currentColor;
vertical-align: text-bottom;
}
.observablehq .anchor {
float: left;
line-height: 1;
margin-left: -20px;
{
"date": "2018-09-05",
"channelName": "RTS",
"programmes": [
{
"id": "2367276",
"start": 1538715600000,
"name": "La Matinale en vidéo",
"fileSize": 28354000
},
@renaudtertrais
renaudtertrais / mock-global-object-jest.js
Created May 17, 2017 12:00
A simple way to mock/unmock globals object methods or constant
/* global expect jest */
const delay = ms => fn => setTimeout(fn, ms);
const mockGlobalProperty = globalObject => key => value => {
// save original implementation in order to unmock later
const original = globalObject[key];
// mock key on the global object
Object.defineProperty(globalObject, key, { value, writable: true });
@renaudtertrais
renaudtertrais / omit.js
Last active September 11, 2017 15:52
A simple ES7 omit function
const omit = (keys, obj) =>
Object.entries(obj)
.filter(([ key ]) => !keys.includes(key))
.reduce((acc, [key, value]) => Object.assign({}, acc, {
[key]: value,
}), {});
omit(['bar'], { foo: 1, bar: 2, baz: 3 }); // { foo: 1, baz: 3 }
@renaudtertrais
renaudtertrais / curry.js
Last active September 1, 2017 09:43
A simple ES6 curry function
const curry = (fn, ...args) => fn.length === 0
? fn
: fn.length > args.length
? (...args2) => curry(...[fn,...args,...args2])
: fn(...args);
// example
const add = curry((a,b,c,d) => a + b + c + d);
const add1 = add(1);
const add3 = add1(2);
@renaudtertrais
renaudtertrais / tfs-without-visualstudio.md
Last active August 21, 2017 09:47
Use tfs without visual studio