Skip to content

Instantly share code, notes, and snippets.

View romuleald's full-sized avatar
🥳

Antoine Sanchez romuleald

🥳
View GitHub Profile
@romuleald
romuleald / random-beetwen-range-with-not
Created September 29, 2014 16:08
Random number beetwen range, with optional parameter to forbid a specific number
function randomIntFromInterval(min, max, not) {
var _return = Math.floor(Math.random() * (max - min + 1) + min);
if(_return === not){
return randomIntFromInterval(min, max, not);
}
return _return;
}
@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;
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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;
}, {})
};