Skip to content

Instantly share code, notes, and snippets.

Avatar

Jean-Pierre Vincent jpvincent

View GitHub Profile
View mesure abandon avant GA.js
// idée originale : https://developers.google.com/web/fundamentals/performance/user-centric-performance-metrics#load_abandonment
window.__trackAbandons = () => {
// Remove the listener so it only runs once.
document.removeEventListener('visibilitychange', window.__trackAbandons);
const ANALYTICS_URL = 'https://www.google-analytics.com/collect';
const GA_COOKIE = document.cookie.replace(
/(?:(?:^|.*;)\s*_ga\s*\=\s*(?:\w+\.\d\.)([^;]*).*$)|^.*$/, '$1');
const TRACKING_ID = 'UA-XXXXX-Y';
const CLIENT_ID = GA_COOKIE || (Math.random() * Math.pow(2, 52));
@jpvincent
jpvincent / proposition syntaxe Jest — webdriver.js
Created Dec 29, 2017
Jest marche bien avec Webdriver, mais la syntaxe peut être lourde. On pourrait étendre l'assert de Jest pour intégrer les appels webdriver
View proposition syntaxe Jest — webdriver.js
// actuellement
expect(await browser.isSelected('[name=CustomClearanceRadios]'))
.toBe(true)
// proposition
expect.el('[name=CustomClearanceRadios]')
.toBeSelected()
// actuellement
expect(await browser.getValue('#ShipperEmail'))
.toBe('jp@made.this')
@jpvincent
jpvincent / inclusion-asynchrone.js
Created Oct 28, 2016
inclusion asynchrone de JS prenant en compte IE < 10 et ne ralentissant pas le body.onload
View inclusion-asynchrone.js
// Pour rappel, voici la manière de faire de GA
/*(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
*/
// C'est compatible partout et asynchrone, mais dans le cas de IE < 10, si le script est déclenché trop tôt, il ralentit window.onload
// Il faut donc juste écouter window.onload et déclencher ce script en asynchrone, quitte à le ralentir
function includeGa(){
@jpvincent
jpvincent / multiple-spof-check.js
Created Oct 28, 2016
Compile and sort multiple runs of spofcheck. Display scores in CLI
View multiple-spof-check.js
// Warning : the original spofcheck works with an old version of Node. 0.10.36 did it for me.
// npm install spofcheck before
// For CLI display only : the original spofcheck could also generate a junit.xml file to be used in continuous integration
const spofcheck = require('spofcheck')
const url = require('url')
const Table = require('cli-table')
const URLs = [
'http://www.vanityfair.fr/',
// 'http://www.vanityfair.fr/video',
View FontLoader.js
var namespace = window;
// Font Loader
namespace.loadFont = function(familyName, fileName, callback) {
var pathToFonts = 'Content/fonts/';
function applyFont() {
var css = '@font-face { font-family: "' + familyName + '";\
src: url("'+pathToFonts+ fileName + '.eot");\
src: url("'+pathToFonts+ fileName + '.eot?#iefix") format("embedded-opentype"),\
url("'+pathToFonts+ fileName + '.woff2") format("woff2"),\
@jpvincent
jpvincent / optimizedFor.js
Last active Dec 18, 2020
never blocking loop mechanism, using setTimeout 0 trick and time control to break the loop and let the browser breath
View optimizedFor.js
/**
* NEVER BLOCKING LOOP : implementation of the infamous setTimeout 0 hack, with time checking in order to guarantee fluidity without sacrificing execution speed.
*
* USAGE :
* var array = ["a way too big array that is heavy to process"]
* optimizeFor({
* nbIterations: array.length,
* each:function( index ) {
* doSomethingUsefulWith( array[ index ] );
* },
View .jshintrc pour élèves
{
"eqeqeq": true, // This options prohibits the use of == and != in favor of === and !==.
"noarg": true, // This option prohibits the use of arguments.caller and arguments.callee
"undef": true, // This option prohibits the use of explicitly undeclared variables
"unused": true, // This option warns when you define and never use your variables
"trailing": true, // This option makes it an error to leave a trailing whitespace in your code
"maxdepth": 3,
"camelCase": true,
"curly": true, // This option requires you to always put curly braces around blocks in loops and conditionals
"immed": true, // This option prohibits the use of immediate function invocations without wrapping them in parentheses
View .jshintrc de base
{
"eqeqeq": true,
"undef": true,
"unused": true,
"trailing": true,
"maxdepth": 3,
"debug": true,
"eqnull": true,
"esnext": true,
"loopfunc": true,
View OPML des feeds feedly
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>Jean-Pierre subscriptions in feedly Cloud</title>
</head>
<body>
<outline text="innovation" title="innovation">
<outline type="rss" text="Pl4n3s world" title="Pl4n3s world" xmlUrl="http://pl4n3.blogspot.com/feeds/posts/default?alt=rss" htmlUrl="http://pl4n3.blogspot.com/"/>
<outline type="rss" text="Mozilla Hacks - the Web developer blog" title="Mozilla Hacks - the Web developer blog" xmlUrl="http://hacks.mozilla.org/feed/" htmlUrl="https://hacks.mozilla.org"/>
View gist:6339863
function makeMochaToBrowserScopeCallback ( testKey, sandboxid) {
'use strict';
return function mochaToBrowserScopeCallback () {
var sendToBenchmark = {};
console.log( mocha.globals('runner').suite );
function applatir (suite) {
// extraction des résultats des tests
var title;