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
name: Build and Deploy to Google Compute Engine | |
on: | |
push: | |
branches: | |
- master | |
env: | |
PROJECT_ID: ${{ secrets.GCE_PROJECT }} | |
GCE_IMAGE: ${{ secrets.GCE_IMAGE }} |
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
# This stage installs modules | |
FROM node:16.2.0 as modules | |
WORKDIR /app | |
COPY package.json package-lock.json ./ | |
RUN npm ci --production | |
# This stage builds TypeScript |
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 randomDiscreteNumber(max: number) { | |
return Math.floor(Math.random() * max) + 1 | |
} | |
export function getRandomColor() { | |
// Use HSL model to create pastel colors. | |
// It is easier to do that by randomizing hue while keeping saturation and lightness in reasonable boundaries. | |
const hue = 6 * randomDiscreteNumber(60) | |
const saturation = 80 + 10 * Math.random() | |
const lightness = (60 + 10 * Math.random()) / 100 |
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 getFileExtension(file: string) { | |
return file.slice((Math.max(0, file.lastIndexOf('.')) || Infinity) + 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
const forceUpdate = useReducer(() => ({}), {})[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
tasks: | |
- init: npm i | |
github: | |
prebuilds: | |
branches: true | |
image: | |
file: .gitpod.Dockerfile |
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, | |
useCallback, | |
RefCallback, | |
} from 'react' | |
function useElement<T>(cb?: (element: T) => any): [T | undefined, (instance: T | null) => void] { | |
const [element, setElement] = useState<T>() | |
const initElementRef = useCallback<RefCallback<T>>((element) => { |
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
// Coverts a signed number to its unsigned hexadecimal representation | |
// `>>> 0` is a conversion to an unsigned 32-bit integer | |
// `000000` adds padding and `.slice(-8)` removes the excessive padding | |
function toHex(value: number) { | |
return ('0000000' + (value >>> 0).toString(16)).slice(-8) | |
} | |
// Creates hash by multiplying each char value | |
// `hash * 31` is an optimized version of `((hash << 5) - hash)` and the number 31 is used for its mathematical properties: | |
// https://stackoverflow.com/questions/299304/why-does-javas-hashcode-in-string-use-31-as-a-multiplier |
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
export function customAlphabet(alphabet: string, size: number) { | |
return () => { | |
let id = '' | |
// A compact alternative for `for (var i = 0; i < step; i++)`. | |
let i = size | |
while (i--) { | |
// `| 0` is more compact and faster than `Math.floor()`. | |
id += alphabet[(Math.random() * alphabet.length) | 0] | |
} | |
return id |
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 ( | |
"math/rand" | |
) | |
var alphabet = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890") | |
func genRandom(length int) string { | |
b := make([]rune, length) | |
for i := range b { | |
b[i] = alphabet[rand.Intn(len(alphabet))] |