Skip to content

Instantly share code, notes, and snippets.

Avatar
🇺🇦
You can hire me (part-time)

Ivan Stinsky ivanstnsk

🇺🇦
You can hire me (part-time)
View GitHub Profile
@ivanstnsk
ivanstnsk / useAndroidBackNavigationEffect.ts
Created Jul 22, 2020
use Android Back navigation effect hook React Native in Typescript
View useAndroidBackNavigationEffect.ts
import { useCallback } from 'react';
import { BackHandler } from 'react-native';
import { useFocusEffect } from '@react-navigation/native';
export const useAndroidBackNavigationEffect = (callback: any): void => {
useFocusEffect(
useCallback(() => {
const onBackPress = () => {
if (callback) {
callback();
@ivanstnsk
ivanstnsk / useAndroidPermissions.ts
Created May 27, 2020
use Android Permissions hook React Native in Typescript
View useAndroidPermissions.ts
import { useEffect, useState } from 'react';
import { PermissionsAndroid } from 'react-native';
type THook = [boolean, boolean];
interface PermissionsAndroidResponse {
[key: string]: string;
}
@ivanstnsk
ivanstnsk / useMouseScroll.ts
Created May 26, 2020
use Mouse Scroll hook React in Typescript
View useMouseScroll.ts
import { useEffect, useState, useRef } from 'react';
type THook<T extends HTMLElement> = [
React.RefObject<T>,
number,
];
export const useMouseScroll = <T extends HTMLElement>(): THook<T> => {
const [scrollY, setScrollY] = useState<number>(0);
@ivanstnsk
ivanstnsk / useWindowResize.ts
Last active May 26, 2020
use Window Resize hook React in Typescript
View useWindowResize.ts
import { useEffect, useState } from 'react';
type TWindowSize = [number, number];
type THook = TWindowSize;
export const useWindowResize = (): THook => {
const initSize: TWindowSize = [
window.innerWidth,
@ivanstnsk
ivanstnsk / useMouseHover.ts
Last active May 24, 2020
use Mouse Hover hook React in Typescript
View useMouseHover.ts
import { useEffect, useState, useRef } from 'react';
type THook<T extends HTMLElement> = [
React.RefObject<T>,
boolean,
];
export const useMouseHover = <T extends HTMLElement>(): THook<T> => {
const [hovered, setHovered] = useState(false);
View delay-async-await
export const delay = (timeMs: number): Promise<void> => {
return new Promise((resolve) => {
setTimeout(resolve, timeMs);
});
};
// await delay(2000);
View JS Snippets
// Simulate sleep for 2000 ms
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
sleep(2000).then( /* do something */ );
@ivanstnsk
ivanstnsk / gist:0a5d8d537b8c71ddfd44786aa89d7bca
Created Feb 1, 2018
GPG: Invalid option "--full-gen-key" fix
View gist:0a5d8d537b8c71ddfd44786aa89d7bca
Change:
gpg --full-gen-key
With:
gpg --gen-key
You can’t perform that action at this time.