// green to red
const getColor = v => `hsl(${((1 - v) * 120)},100%,50%)`;
// red to green
const getColor = v => `hsl(${((1 - Math.abs(v - 100)) * 120)},100%,50%)`;Pass in (perccentage / 100).
| const proxy = require('http-proxy-middleware'); | |
| // Execute `copy(document.cookie)` in the console on the proxy site | |
| // and paste into this string. | |
| const cookies = ''; | |
| module.exports = function(app) { | |
| app.use(proxy('/api', { | |
| changeOrigin: true, | |
| cookiePathRewrite: true, |
| function isAvailable() { | |
| try { | |
| this.storage.setItem('__testFeature', true); | |
| this.storage.removeItem('__testFeature'); | |
| return true; | |
| } catch (ex) { | |
| return false; | |
| } | |
| } |
// green to red
const getColor = v => `hsl(${((1 - v) * 120)},100%,50%)`;
// red to green
const getColor = v => `hsl(${((1 - Math.abs(v - 100)) * 120)},100%,50%)`;Pass in (perccentage / 100).
| // Packages like PassportJS and useless diagrams online make OAuth seem complicated to implement, but in reality it's simple... | |
| const got = require('got'); | |
| const jwt = require('jsonwebtoken'); | |
| const querystring = require('querystring'); | |
| const mins = min => 1000 * 60 * min; | |
| // 1. Direct users browser to this url. | |
| app.get('auth/github', (req, res) => { | |
| const csrfState = Math.random().toString(36).substring(7); |
| /* globals matchMedia */ | |
| import React, { PureComponent } from 'react'; | |
| function adaptiveComponent(mediaQueries) { | |
| const firstMatchingQuery = Object.keys(mediaQueries).find(mediaQuery => | |
| matchMedia(mediaQuery).matches); | |
| if (!firstMatchingQuery) { | |
| throw new Error(`No media query matches found in ${mediaQueries}`); | |
| } |
| /* | |
| Example usage: | |
| StackNavigator({ | |
| Login: { screen: Login }, | |
| Play: { screen: AuthBlockade(Play) }, | |
| }, { | |
| initialRouteName: 'Play', | |
| }); | |
| */ |
| export const copyToClipboard = (function initClipboardText() { | |
| const id = 'copy-to-clipboard-helper'; | |
| const element = document.getElementById(id); | |
| const textarea = element || document.createElement('textarea'); | |
| if (!element) { | |
| textarea.id = id; | |
| // Place in top-left corner of screen regardless of scroll position. | |
| textarea.style.position = 'fixed'; | |
| textarea.style.top = 0; |
| /* | |
| BEM Class helper: | |
| const c = makeClass('myparentclass'); | |
| className={c`myclass myclass--active`} | |
| becomes: className="myparentclass__myclass myparentclass__myclass--active" | |
| */ | |
| export const makeClass = (cls) => | |
| (subCls) => subCls[0].split(' ').reduce((acc, s) => | |
| `${acc}${cls}__${s} `, '').trimRight(); |
| /* | |
| Authenticate component using a wrapper | |
| */ | |
| import React, {Component} from 'react'; | |
| import { connect } from 'react-redux'; | |
| export default function(ComposedComponent) { | |
| class Auth extends Component { | |
| static contextTypes = { |
| 'use strict'; | |
| const path = require('path'); | |
| const fs = require('fs'); | |
| const types = require('node-sass').types; | |
| function svgContentWrapper(svgContent) { | |
| return `url('data:image/svg+xml;charset=UTF-8,${svgContent.replace(/\r?\n|\r/g, '')}')`; | |
| } |