This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { forwardRef } from "react"; | |
// Declare a type that works with generic components | |
type FixedForwardRef = <T, P = {}>( | |
render: (props: P, ref: React.Ref<T>) => React.ReactElement | |
) => ( | |
props: P & React.RefAttributes<T> | |
) => React.ReactElement; | |
// Cast the old `forwardRef` to the new one |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// find next non incremented number greater then 0 | |
function solution(array) { | |
const sortedArray = array.sort((a, b) => (a - b)); | |
const cleanArray = [...new Set(sortedArray)]; | |
const N = cleanArray.reduce((total, value, i, arr) => { | |
if (value !== total + 1) { | |
const n = value + 1 | |
return n > 0 ? n : 1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flattenArray(array) { | |
var flattened = []; | |
function loop(array) { | |
for (var i=0; i < array.length; i++) { | |
var value = array[i]; | |
if (typeof value === 'object' && value.constructor === Array) { | |
loop(value); | |
} else { | |
flattened.push(value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { render as renderReact } from 'react-dom' | |
import retargetEvents from 'react-shadow-dom-retarget-events' | |
import App from './App' | |
(function() { | |
window.addEventListener('WebComponentsReady', () => { | |
class MyApp extends HTMLElement { | |
constructor() { | |
super() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const canvas = document.getElementById("myCanvas"); | |
canvas.width = width; | |
canvas.height = height; | |
class Scene { | |
constructor() { | |
this.orbs = []; | |
this.context = canvas.getContext("2d"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useRef } from 'react'; | |
export default function whatChanged(props) { | |
const prev = useRef(props); | |
useEffect(() => { | |
const changedProps = Object.entries(props).reduce((ps, [k, v]) => { | |
if (prev.current[k] !== v) { | |
ps[k] = [prev.current[k], v]; | |
} | |
return ps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const timeframeAffectsKpiData = (isInstantKpi, timeframe) => { | |
if (timeframe && isInstantKpi && !timeframeContainsToday(timeframe)) { | |
return false; | |
} | |
return true; | |
}; | |
//vs | |
const timeframeAffectsKpiData = (isInstantKpi, timeframe) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const minWidth = 220; | |
const minColumns = 1; | |
const maxColumns = 5; | |
const numberOfColumns = clamp( | |
this.props.containerWidth / minWidth, | |
minColumns, | |
maxColumns); | |
// vs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const boxers = [ {name: "Muhammad Ali"}, {name: "Barry McGuigan"} ]; | |
const boxer = boxers[0]; | |
let clone = $.extend(true, {}, boxer); | |
let index = 1; | |
let isNameUnique = name => _(boxers) | |
.chain() | |
.map(dg => dg.name) | |
.all(n => n !== name) | |
.value(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
background: linear-gradient(0deg, #0f0763, #000000); | |
background-size: 400% 400%; | |
-webkit-animation: AnimationName 16s ease infinite; | |
-moz-animation: AnimationName 16s ease infinite; | |
-o-animation: AnimationName 16s ease infinite; | |
animation: AnimationName 16s ease infinite; | |
@-webkit-keyframes AnimationName { | |
0%{background-position:50% 0%} | |
50%{background-position:50% 100%} |