Skip to content

Instantly share code, notes, and snippets.

View bdavidxyz's full-sized avatar
🏠
Working from home

David Boureau bdavidxyz

🏠
Working from home
View GitHub Profile
@bdavidxyz
bdavidxyz / classtrophobic.js
Last active February 11, 2018 13:01
Classtrophobic transpiled
/*
* Classtrophobic, https://github.com/WebReflection/classtrophobic
* Plain Old Javascript version, transpiled by babel (master branch)
* All credits goes to
*! (C) 2017 Andrea Giammarchi - MIT Style License
*/
function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return right[Symbol.hasInstance](left); } else { return left instanceof right; } }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
@bdavidxyz
bdavidxyz / gist:2f6275160800eae136c7db19d5b468bc
Created January 25, 2018 11:27
auto refresh chrome based on url
var oldURL = "";
function checkURLchange(currentURL){
if(window.location.href !== localStorage.getItem('oldURL') && !document.body){
oldURL = window.location.href;
location.reload();
localStorage.setItem('oldURL', oldURL);
}
setInterval(function() {
checkURLchange(window.location.href);
const sizeDifference = _(proposals).size() - _(definedUserAnswers).size(); // 2
const arrayOfFalse = _.times(sizeDifference, _.constant(false)); // [false, false]
return _.chain(definedUserAnswers) // [false, true]
.concat(arrayOfFalse) // [false, true, false, false]
.zip(proposals) // [[false, 'prop 1'], [true, 'prop 2'], [false, 'prop 3'], [false, 'prop 4']]
.map(_.reverse) // [['prop 1', false], ['prop 2', true], ['prop 3', false], ['prop 4', false]]
.value();
/*
* Example :
* => Input :
* proposals : ['is sky red ?' , 'is sun red ?' , 'is grass red ?' , 'is cloud red ?']
* => Input :
* userAnswers : [false, true]
*
* WARNING : only first(s) userAnswers are given,
* all others have implicitly the boolean value "false"
*
const sizeDifference = _(proposals).size() - _(userAnswers).size(); // 2
const completeWithFalse = _.times(sizeDifference, _.constant(false)); // [false, false]
return _.chain(userAnswers) // [false, true]
.concat(completeWithFalse) // [false, true, false, false]
.zip(proposals) // [[false, 'prop 1'], [true, 'prop 2'], [false, 'prop 3'], [false, 'prop 4']]
.map(_.reverse) // [['prop 1', false], ['prop 2', true], ['prop 3', false], ['prop 4', false]]
.value();
const sizeDifference = _(proposals).size() - _(answers).size();
const arrayOfFalse = _.times(sizeDifference, _.constant(false));
return _.chain(answers)
.concat(arrayOfFalse)
.zip(proposals)
.map(_.reverse)
.value();
let result = _.zip(proposals, answers);
result = _.map(result, (item) => {
if (item[1]) {
return [item[0], true];
} else {
return [item[0], false];
}
});
/*
* Example :
* => Input :
* proposals : ['is sky red ?' , 'is sun red ?' , 'is grass red ?' , 'is cloud red ?']
* => Input :
* userAnswers : [false, true]
*
* WARNING : only first(s) userAnswers are given,
* all others have implicitly the boolean value "false"
*
function labeledCheckboxes (proposals, answers) {
let result = _.zip(proposals, answers);
result = _.map(result, (item) => {
if (item[1]) {
return [item[0], true];
} else {
return [item[0], false];
}
});
return result;
// check pre-conditions
if (_(proposals).isEmpty()) return [];
if (_(proposals).isNotArrayOfString()) return [];
if (_(answers).isNotArrayOfBoolean()) return [];
if (_(answers).size() > _(proposals).size()) return [];