Skip to content

Instantly share code, notes, and snippets.

View Danetag's full-sized avatar
🕺
Entertaining

Arnaud Tanielian Danetag

🕺
Entertaining
View GitHub Profile
/**
* requestPlaylist: Callback for the say_request_playlist intent
* @param {Object} assistant Assistant instance.
*/
const requestPlaylist = function(assistant) {
// formatted data from current intent
let artists = assistant.data.artist || [];
let genres = assistant.data.genre || [];
let moods = assistant.data.mood || [];
@Danetag
Danetag / service-worker.js
Created January 7, 2018 21:37
Part of service-worker
// On fetch
// ...
if (event.request.headers.get('accept').includes('text/html')) {
event.respondWith(toolbox.networkFirst(event.request));
return;
}
// ...
// Runtime cache configuration, using the sw-toolbox library.
toolbox.router.get(/^https:\/\/images\.contentful\.com/, toolbox.cacheFirst, {});
export const getImageWidthByUserContext = (width, MAX_WIDTH = 2880) => {
if (typeof(window) === 'undefined') return width;
// Pixel ratio
let qualityRatio = window.devicePixelRatio ? window.devicePixelRatio : 1;
// If bad connection, we downgrade
let type = null;
if (navigator && navigator.connection && navigator.connection.type) type = navigator.connection.type;
if (navigator && navigator.connection && navigator.connection.effectiveType) type = navigator.connection.effectiveType;
import tinycolor from 'tinycolor2';
import VARS from 'base/vars';
// https://www.w3.org/TR/WCAG20/#contrast-ratiodef
export const CONTRAST_RATIO = 3.1;
/*
* @name getValidColor
* @description Returns a color that satisfies that contrast color check between a background color and a text color.
* @param backgroundColor {string} Hexadecimal value of the background color
/*
* Based on https://medium.freecodecamp.org/reducing-css-bundle-size-70-by-cutting-the-class-names-and-using-scope-isolation-625440de600b
* Creates a shared dictionnary for client and server side classname rendering
*/
const incstr = require('incstr');
const fs = require('fs');
const jsonfile = require('jsonfile');
// creates dictionnary file if doesn't exists
import React, {PropTypes, Component} from 'react';
import Loadable from 'react-loadable';
class ExperiencePageComponent extends Component {
render() {
const { data } = this.props;
let LoadableComponent = null;
class LottieWebAnimation extends React.Component {
/*
.. render()...
*/
// Capturing mouse move
onMouseMove = (e) => {
this.mouseCoords.x = e.clientX || e.pageX;
this.mouseCoords.y = e.clientY || e.pageY;
// Update the path of the assets in the animation data to use CMS assets instead (optmized)
const updateAnimationData = (assets, animationData, maxAssetWidth) => {
const refIdDictionary = [];
animationData.assets.forEach((asset, i) => {
if (!asset.u || !asset.id) return;
// replace id
const newId = asset.p.split('.')[0];
const prevId = asset.id !== newId ? asset.id : `image_${i}`;
@Danetag
Danetag / Sprite.js
Last active May 13, 2024 17:28
Simple class to play a PNG sequence into a canvas
// Here is a simple class that contains loading methods.
// Nothing fancy, but the idea is simply to return a Promise
import { loadImg } from './load';
class Sprite {
/*
@Example
import Sprite from './Sprite';