Skip to content

Instantly share code, notes, and snippets.

View dmail's full-sized avatar
🍒

Damien Maillard dmail

🍒
  • Datadog
  • Antibes
View GitHub Profile
@dmail
dmail / symlink.js
Last active August 29, 2015 14:19
symlink your module to keep clean and separate sources from project usage
@dmail
dmail / object-fit-cover-video.js
Created October 5, 2015 06:50
object-fit:cover polyfill on video element using canvas
// http://stackoverflow.com/questions/21961839/simulation-background-size-cover-in-canvas
function drawImageProp(ctx, img, x, y, w, h, offsetX, offsetY) {
if (arguments.length === 2) {
x = y = 0;
w = ctx.canvas.width;
h = ctx.canvas.height;
}
// default offset is center
offsetX = typeof offsetX === "number" ? offsetX : 0.5;
@dmail
dmail / multilang-trans.js
Created October 5, 2015 06:58
multilang using data-trans attribute
var Lang = {
name: undefined,
availables: ['fr', 'en', 'de'],
detect: function(){
var languages = window.navigator.languages, preferredLanguage;
if( languages ){
languages = languages.map(function(language){
var lang;
@dmail
dmail / countdown.html
Created October 5, 2015 13:47
A countdown based on jQuery finalcountdown
<!doctype html>
<html>
<head>
</head>
<body>
<div class="countdown">
</div>
@dmail
dmail / one-percent-then.js
Last active November 28, 2015 16:45
Illustration of a case where you have register then() without using catch
var Promise = require('bluebird');
var fs = Promise.promisifyAll(require('fs'));
var existingFile = 'path/to/existing/file';
var unexistingFile = 'path/to/unexisting/file';
var statPromise = fs.stat(existingFile);
function onStatResolution(stat){
return fs.readFile(unexistingFile);
}
@dmail
dmail / node-iterate-mess.js
Last active September 18, 2017 15:50
Node iteration mess
function readNodeAt(rootNode, path) {
var i = 0;
var j = path.length;
var index;
var found = rootNode;
for (;i < j; i++) {
index = Number(path[i]);
found = found.childNodes[index];
if (found === null) {
@dmail
dmail / clone-descendant-deep.js
Created April 28, 2016 09:27
Sort of node.cloneNode(true) on descendant only
// will return a cloned version of rootNode descendants
// in itself this function is useless but it can be modified to add custom cloning behaviour
function cloneNodeDeep(rootNode) {
var node = rootNode;
var rootClone = document.createDocumentFragment();
var nodeClone = rootClone;
while (node) {
var nextNode = null;
var firstChild = node.firstChild;
if (firstChild) {
@dmail
dmail / framB.html
Created August 5, 2016 13:34
Testing Symbol.toStringTag across frames
<HTML>
<HEAD>
<TITLE>JavaScript Example 14</TITLE>
</HEAD>
<BODY>
<FORM name="form1">
<INPUT type="text" name="text1" size="25" value="">
</FORM>
<script>
window.GLOBAL_ARRAY = [];
@dmail
dmail / clone-function.js
Last active August 26, 2016 11:06
JavaScript Function cloning implementation and documentation
function cloneFunction(fn, mode = 'primitive') {
var clonedFn;
if (mode === 'primitive') {
clonedFn = fn;
} else if (mode === 'construct') {
clonedFn = new Function('return ' + fn.toString())();
} else if (mode === 'wrap') {
let Constructor;
clonedFn = function() {