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
Show hidden characters
{ | |
"compilerOptions": { | |
"baseUrl": "pages", | |
"paths": { "@/components": ["components/*"] } | |
} | |
} |
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 GoogleMapReact from "google-map-react"; | |
import { CustomIcon } from "@/chakra/icons/custom-icon"; // replace with any icon if not using chakra | |
// @link https://blog.logrocket.com/a-practical-guide-to-integrating-google-maps-in-react/ | |
// @link https://developers.google.com/maps/gmp-get-started#create-project | |
// - setup google project | |
// - setup google api key (credentials) | |
// - enable api for project (javascript api) | |
// - setup billing for project |
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
/* NOT TO BE USED IN PRODUCTION == FOR BROWSER HACKS ONLY */ | |
function removeAllChildNodes(parent) { | |
while (parent.firstChild) { | |
parent.removeChild(parent.firstChild); | |
} | |
} | |
// USAGE: | |
const container = document.querySelector('#container'); |
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 { useCallback, useMemo, useRef } from "react"; | |
// unused | |
export const useFocus = () => { | |
const htmlElRef = useRef(null); | |
const setFocus = useCallback(() => { | |
if (!htmlElRef.current) return; | |
htmlElRef.current.focus(); |
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 createFormObject(inputsElements) { | |
/** | |
* #SCOPE: takes in an array of inputs and returns a single object with the shape | |
* {[input.name]L input.value} | |
*/ | |
return inputsElements.reduce( | |
(obj, item) => ({ ...obj, [item.name]: item.value.trim() }), // trim whitespace | |
{} | |
); | |
} |
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 isValidJson(string) { | |
/** | |
* @SCOPE: uses json.parse to validate a string as json | |
* used by: | |
* - show-json | |
* | |
*/ | |
if (typeof string !== "string") return false; | |
try { | |
JSON.parse(string); |
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 arrayFill(length, val) { | |
return new Array(length).fill(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
// @link: https://itnext.io/improving-slow-mounts-in-react-apps-cff5117696dc | |
const Defer = ({ chunkSize, children }) => { | |
const [renderedItemsCount, setRenderedItemsCount] = React.useState(chunkSize); | |
const childrenArray = React.useMemo(() => React.Children.toArray(children), [ | |
children | |
]); | |
React.useEffect(() => { |
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
-- inserts a row into public.users | |
create function public.handle_new_user() | |
returns trigger as $$ | |
begin | |
insert into public.users (id) | |
values (new.id); | |
return new; | |
end; | |
$$ language plpgsql security definer; |
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
CREATE TYPE enum_name AS ENUM ('value1', 'value2', 'value3', 'value4'); | |
-- DROP TYPE admin_level1; |