Skip to content

Instantly share code, notes, and snippets.

View Danetag's full-sized avatar
🕺
Entertaining

Arnaud Tanielian Danetag

🕺
Entertaining
View GitHub Profile
import React, {PropTypes, Component} from 'react';
import Loadable from 'react-loadable';
class ExperiencePageComponent extends Component {
render() {
const { data } = this.props;
let LoadableComponent = null;
/*
* 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 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
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;
@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, {});
/**
* 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 || [];
[
{
"id": "default",
"params": {
"seed_artists": [],
"seed_genres": []
}
},
{
"id": "fallback",
const speakTag = function speakTag(content) {
return `<speak>${content}</speak>`;
};
const audioTag = function audioTag(src, name) {
return `<audio src="${src}">${name}</audio>`;
};
const CONFIG = require('./config.json');
module.exports = {
INPUT_WELCOME: 'input.welcome',
INPUT_UNKNOWN: 'input.unknown',
REQUEST_PLAYLIST: 'request_playlist',
ADD_MOOD: 'add_mood',
ADD_ARTIST: 'add_artist',
ADD_GENRE: 'add_genre',
PREVIEW: 'preview',
APPROVE_SONG: 'approve_song',
DISAPPROVE_SONG: 'disapprove_song',