Skip to content

Instantly share code, notes, and snippets.

View GuyGooL5's full-sized avatar
๐Ÿ˜
I <3 code

Guy Tsitsiashvili GuyGooL5

๐Ÿ˜
I <3 code
View GitHub Profile
import { useEffect, useRef } from "react";
export interface AudioPlayerProps {
url: string;
}
export const AudioPlayer = ({ url }: AudioPlayerProps) => {
const inputRef = useRef<HTMLInputElement>(null);
const audioRef = useRef<HTMLAudioElement>(null);
const seekingRef = useRef(false);
@GuyGooL5
GuyGooL5 / env_var_loader.py
Created October 30, 2022 15:22
Automatic type casting for environment variables loader
__author__ = "Guy Tsitsiashvili"
from typing import Generic, Type, TypeVar
from decouple import config
AutoCast = TypeVar("AutoCast")
class EnvVar(Generic[AutoCast]):
@staticmethod
@GuyGooL5
GuyGooL5 / useDebouncedState.ts
Created October 18, 2022 12:40
A quick hook that acts like useState but with debounce
/** @author Guy Tsitsiashvili */
import { useState, useEffect, Dispatch, SetStateAction } from "react";
const useDebounceState = <T>(
initialState: T,
delay: number
): [T, Dispatch<SetStateAction<T>>] => {
const [state, setState] = useState(initialState);
const [deboucedState, setDebouncedState] = useState(state);
@GuyGooL5
GuyGooL5 / useTimer.tsx
Created August 24, 2022 17:02
A react hook for starting, pausing and continuing a timer with optional accuracy and string formatting parameters
/** @author Guy Tsitsiashvili */
const useTimer = (
accuracy: number = 0,
remainingFormat: (ms: number) => string = (ms) => `${ms}ms`,
) => {
const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
const [remaining, setRemaining] = useState(0);
const stop = useCallback(() => {
@GuyGooL5
GuyGooL5 / Navbar.tsx
Last active July 16, 2022 14:35
Tailwind Navbar Example
// Navbar.tsx
import { ComponentType } from 'react';
export interface NavbarItem {
route: string;
name: string;
Icon: ComponentType;
}
@GuyGooL5
GuyGooL5 / useGeolocation.tsx
Created May 9, 2022 09:17
This example shows a hook for getting the geolocation from the browser and handling waiting and errors.
/* Copyright 2022 Guy Tsitsiashvili
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR T
@GuyGooL5
GuyGooL5 / GeolocationUI.tsx
Last active May 9, 2022 09:10
This is a snippet for implementing a geolocation component in React.js
/* Copyright 2022 Guy Tsitsiashvili
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR T
@GuyGooL5
GuyGooL5 / LocalStorage.ts
Last active May 9, 2022 20:01
A class to manage Local Storage
/* Copyright 2022 Guy Tsitsiashvili
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR T