Skip to content

Instantly share code, notes, and snippets.

View romuleald's full-sized avatar
🥳

Antoine Sanchez romuleald

🥳
View GitHub Profile
@romuleald
romuleald / MutationObserver.js
Last active March 26, 2019 18:01
MutationObserver for Jest
/*!
file to place in the JEST setupFiles options
https://github.com/tmpvar/jsdom/issues/639#issuecomment-259296780
*/
class Util {
constructor() {
this.counter = 1;
this.expando = 'mo_id';
}
@romuleald
romuleald / filterKeys.js
Created May 30, 2017 14:21
filter object keys
//accepted = {id: true}
//qs = {id: 'lol', kikoo: 'yes'}
let filterKeys = function (accepted, qs) {
return Object.keys(qs).reduce(function (acc, curr) {
if (accepted[curr]) {
acc[curr] = qs[curr]
}
return acc;
}, {})
};
@romuleald
romuleald / get.js
Created May 1, 2017 17:28
getCookies with reduce
var getCookies = function(){
document.cookie.split(';').reduce(function(acc, curr, arr){
let _split = curr.split('=');
acc[_split[0].trim()] = _split[1];
return acc;
},{})
};
@romuleald
romuleald / inputCursor.js
Created August 24, 2016 15:34
For ES6 browser/compilator
var modifyInputValue = function ($elem, e, value, gap = 0) {
var target = e.target,
position = target.selectionStart; // Capture initial position
$elem.val(value);
target.selectionEnd = position + gap; // Set the cursor back to the initial position.
};
@romuleald
romuleald / count-item.js
Created July 7, 2016 13:15
Count unique item in array
var countItems = function (_array) {
return Array.from(new Set(_array)).length;
};
@romuleald
romuleald / getTpl.js
Last active May 3, 2016 09:54
get a template from a <script type="text/template"> and replace {{foo}} with {foo: 'bar'} → bar
var getTpl = (function () {
"use strict";
let cache = {};
var getCache = function (templateId) {
return cache[templateId];
};
var setCache = function (templateId, html) {
cache[templateId] = html;
};
@romuleald
romuleald / getdayofweek.js
Created December 8, 2015 11:00
Get day in a week
/**
*
* @param date Date
* @param dayOfWeek {Number} between 1 (monday) to 7 (sunday)
*/
var getDayOfWeek = function (date, dayOfWeek) {
if(dayOfWeek > 7 || dayOfWeek < 1){
console.warn('dayOfWeek is out of range (1-7), was:', dayOfWeek);
}
var _date = new Date(date);
@romuleald
romuleald / pjax-caching
Created April 15, 2015 09:38
PJAX with caching on mouseenter
var SPAajaxloading = function () {
var $links = $('#nav a');
var historyCache = {};
var getCache = function (url) {
return historyCache[url];
};
var setCache = function (url, content) {
@romuleald
romuleald / grunt_rename
Last active August 29, 2015 14:18
Rename destination path in Grunt
grunt.initConfig({
less: {
development: {
files: [{
expand: true,
cwd: 'src/',
src: ['**/*.less'],
dest: 'css/',
ext: '.css',
rename: function(dest, src) {
@romuleald
romuleald / _css-triangle.scss
Created December 18, 2014 13:41
SCSS Mixin Arrow/Triangle
@mixin css-border-arrow($dir, $fullborder, $size, $bordersize, $color, $bordercolor) {
$border_position_color: '';
$margin_position: 'left';
$absoluteXposition: 'left';
$absoluteYposition: 'top';
$Xposition: 50%;
$Yposition: 50%;
$borderarrowsize: $size + $bordersize + 2;
$marginborderarrowsize: $size + $bordersize + 2;
$marginsize: $size;