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
namespace Visitor | |
type IPrescription = | |
abstract member Accept : IPrescriptionVisitor -> unit | |
and IPrescriptionVisitor = | |
abstract member Visit : PointInTime -> unit | |
abstract member Visit : Infusion -> unit | |
and PointInTime() = |
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 ClassName = () => { | |
const createdClasses = []; | |
const stringToCss = str => str.split('').map(c => c.charCodeAt(0) >= 97 | |
? c | |
: `-${String.fromCharCode(c.charCodeAt(0) + 32)}`).join(''); | |
const cssString = css => Object.keys(css).map(key => `${stringToCss(key)}:${css[key]}`).join(';'); | |
const addStyle = (name, css) => { |
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
require('colors'); | |
const lighthouse = require('lighthouse'); | |
const chromeLauncher = require('chrome-launcher'); | |
const launchAndRun = (url, opts, config = null) => | |
chromeLauncher.launch({ chromeFlags: opts.chromeFlags }) | |
.then(chrome => { | |
opts.port = chrome.port; | |
return lighthouse(url, opts, config).then(results => chrome.kill().then(() => results.lhr)); | |
}); |
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"; | |
function WidthAndHeight() { | |
const [width, setWidth] = React.useState(window.innerWidth); | |
const [height, setHeight] = React.useState(window.innerHeight); | |
React.useEffect(() => { | |
window.addEventListener("resize", updateWidthAndHeight); | |
return () => window.removeEventListener("resize", updateWidthAndHeight); | |
}); |
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"; | |
const scaleWidth = 500; | |
const scaleHeight = 500; | |
function draw(canvas, scaleX, scaleY) { | |
const context = canvas.getContext("2d"); | |
context.scale(scaleX, scaleY); | |
context.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight); |
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 * as React from "react"; | |
function HookRef() { | |
const divRef = React.useRef<HTMLDivElement>(null); | |
React.useEffect(() => { | |
if (divRef.current) { | |
console.log(`hookRef div width: ${divRef.current.clientWidth}`); | |
} | |
}, []); |
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 * as React from "react"; | |
class CreateRef extends React.Component { | |
divRef = React.createRef<HTMLDivElement>(); | |
componentDidMount() { | |
if (this.divRef.current) { | |
console.log(`createRefRef div width: ${this.divRef.current.clientWidth}`); | |
} | |
} |
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 * as React from "react"; | |
class CallbackRef extends React.Component { | |
divRef: HTMLDivElement | null = null; | |
setDivRef = (element: HTMLDivElement) => { | |
this.divRef = element; | |
}; | |
componentDidMount() { |
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 * as React from "react"; | |
const Forward = React.forwardRef((props, ref: React.Ref<HTMLDivElement>) => ( | |
<div ref={ref} style={{ width: "100%", height: "30px", backgroundColor: "green" }} /> | |
)); | |
function ForwardRef() { | |
const divRef = React.useRef<HTMLDivElement>(null); | |
React.useEffect(() => { |
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 evenWord(word) { | |
let charCounts = [...word].reduce( | |
(charCount, char) => ({ | |
...charCount, | |
[char]: charCount[char] ? charCount[char] + 1 : 1, | |
}), | |
{}, | |
); | |
return Object.entries(charCounts).filter(([_, count]) => count % 2 !== 0).length; | |
} |
OlderNewer