This file contains hidden or 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 default async function whilePromise(action, condition) { | |
const result = await action(); | |
if (condition(result)) { | |
return whilePromise(action, condition); | |
} | |
} |
This file contains hidden or 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 useDelay(time = 1000) { | |
return React.useCallback(async () => { | |
return await new Promise((resolve) => { | |
setTimeout(resolve, time); | |
}); | |
}, [time]); | |
} | |
//usage | |
export default function App() { |
This file contains hidden or 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 } from "react"; | |
function getInputOnChange(setValue) { | |
return (val) => { | |
if (!val) { | |
setValue(val); | |
} else if (typeof val === "function") { | |
setValue(val); | |
} else if (typeof val === "object" && "nativeEvent" in val) { | |
const { currentTarget } = val; |
This file contains hidden or 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
version: "3.3" | |
services: | |
traefik: | |
image: traefik | |
restart: always | |
container_name: traefik | |
ports: | |
- 80:80 | |
- 443:443 |
This file contains hidden or 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
version: "3.3" | |
services: | |
################################################ | |
#### Traefik Proxy Setup ##### | |
############################################### | |
traefik: | |
image: traefik:v2.0 | |
restart: always |
This file contains hidden or 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
server { | |
listen *:80; | |
server_name example.com *.example.com; | |
set $subdomain ""; | |
if ($host ~ ^(.*)\.example\.com$) { | |
set $subdomain $1; | |
} | |
location / { |
This file contains hidden or 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 isOverflowingElement(element) { | |
return (element.scrollWidth > element.offsetWidth); | |
} |
This file contains hidden or 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 shift_f5_hard_reload() { | |
let evt = new KeyboardEvent("keydown", { | |
shiftKey: true, | |
key: "f5", | |
keyCode: 116 | |
}); | |
document.dispatchEvent(evt); | |
} |
This file contains hidden or 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
/** | |
* | |
* @param map Map data | |
* @param searchValue value | |
*/ | |
export function getByValue(map: any[], searchValue: any): any { | |
for (const [key, value] of map.entries()) { | |
if (value === searchValue) return key; | |
} | |
} |
This file contains hidden or 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
/** | |
* Helper to produce an array of enum values. | |
* @param enumeration Enumeration object. | |
*/ | |
export function enumToArray<T, G extends keyof T = keyof T>(enumeration: T): T[G][] { | |
const enumVals = Object.values(enumeration); | |
return enumVals.slice(enumVals.length / 2, enumVals.length) as T[G][]; | |
} |