Skip to content

Instantly share code, notes, and snippets.

View gaurangrshah's full-sized avatar
💭
🚀

gshah2020 gaurangrshah

💭
🚀
View GitHub Profile
{
"compilerOptions": {
"baseUrl": "pages",
"paths": { "@/components": ["components/*"] }
}
}
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
/* 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');
import { useCallback, useMemo, useRef } from "react";
// unused
export const useFocus = () => {
const htmlElRef = useRef(null);
const setFocus = useCallback(() => {
if (!htmlElRef.current) return;
htmlElRef.current.focus();
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
{}
);
}
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);
@gaurangrshah
gaurangrshah / arrayFill.js
Last active December 16, 2021 17:17
Synced via Snip
export function arrayFill(length, val) {
return new Array(length).fill(val);
}
// @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(() => {
@gaurangrshah
gaurangrshah / create-new-user-trigger.sql
Created April 7, 2021 00:42
sql snippets used for supabase
-- 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;
@gaurangrshah
gaurangrshah / create-enum.sql
Last active April 7, 2021 00:41
Helpful sql statements / queries
CREATE TYPE enum_name AS ENUM ('value1', 'value2', 'value3', 'value4');
-- DROP TYPE admin_level1;