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 find_max(nums) { | |
let max_num = Number.NEGATIVE_INFINITY; // smaller than all other numbers | |
for (let num of nums) { | |
if (num > max_num) { | |
max_num = num | |
} | |
} | |
return max_num; | |
} |
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 path = require("path"); | |
const HtmlWebpackPlugin = require("html-webpack-plugin"); | |
module.exports = { | |
entry: "./src/index.tsx", | |
output: { | |
path: path.resolve(__dirname, "dist"), | |
filename: "bundle.js", | |
}, | |
resolve: { |
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 NON_SPECIAL_CHARS_REGEX = /\W+|[_]+/; | |
const WHITE_SPACE_REGEX = /\s+/; | |
const formatCamelCase = (text) => { | |
const formatCase = (word, index) => { | |
const formattedNonFirstWord = word.charAt(0).toUpperCase() + word.slice(1); | |
return index === 0 ? word.toLowerCase() : formattedNonFirstWord | |
}; | |
return text | |
.replace(NON_SPECIAL_CHARS_REGEX, ' ') |
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 FIRST_PARAGRAPH_TAG_REGEX = /<p>(.*?)<\/p>/; | |
const INLINE_STYLE_REGEX = /style="[^"]*"/g; |
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 VIDEO_FILE_REGEX = /video\/\w+/gm; | |
const AUDIO_FILE_REGEX = /audio\/\w+/gm; | |
const IMAGE_FILE_REGEX = /image\/\w+/gm; |
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 } from 'react'; | |
import { KeyboardKey } from 'enums/keyboardKey'; | |
export const useKeyPress = (callback: (T?: any) => void, keys: KeyboardKey[]) => { | |
const onKeyDown = (event: KeyboardEvent) => { | |
const wasAnyKeyPressed = keys.some((key) => event.key === key); | |
if (wasAnyKeyPressed) { | |
event.preventDefault(); | |
callback(); |
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 { useState, useEffect } from 'react'; | |
const getWindowDimensions = () => { | |
const { innerWidth: width, innerHeight: height } = window; | |
return { width, height }; | |
} | |
const useWindowDimensions = () => { | |
const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions()); |
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 } from 'react'; | |
export const useOutsideClick = (callback: (T?: any) => void, ref: React.RefObject<HTMLDivElement>) => { | |
const handleClick = (e: Event) => { | |
if (ref.current && !ref.current.contains(<HTMLElement>e.target)) { | |
callback(); | |
} | |
}; | |
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
const createContentExcerpt = (content, maxNumberOfWords, trailingIndicator = '...') => { | |
const listOfWords = content.trim().split(' '); | |
const truncatedContent = listOfWords.slice(0, maxNumberOfWords).join(' '); | |
const excerpt = truncatedContent + trailingIndicator; | |
const result = listOfWords.length > maxNumberOfWords ? excerpt : content; | |
return result; | |
}; | |
// Example: |
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
<!doctype html> | |
<html> | |
<head> | |
<!-- Priority tags. These must come first. --> | |
<meta charset="utf-8"> | |
<meta http-equiv="x-ua-compatible" content="ie=edge; chrome=1"> <!-- Render Chrome if available or using latest version of Internet Explorer (Recommended). --> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> | |
<!-- Document Title --> | |
<title>Page Title</title> | |
<!-- Allows control over where resources are loaded from. Place as early in the document as possible, only applies to content below this tag. --> |
NewerOlder