This file contains 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 React from 'react'; | |
import useDeviceType from '../hooks/useDeviceType'; | |
const DeviceComponent = () => { | |
const isMobile = useDeviceType(); | |
return ( | |
<p> | |
You are using a {isMobile ? 'mobile device' : 'computer'}. |
This file contains 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 useInterval from './useInterval'; | |
// use as useHeartBeat(time); which writes out 'I am alive!' every 'time' milliseconds | |
const useHeartBeat = useInterval(() => console.log('I am alive!')); | |
export default useHeartBeat; |
This file contains 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 React from 'react'; | |
import useInterval from '../hooks/useInterval'; | |
const MyIntervalComponent = () => { | |
useInterval(() => console.log('Hello World'))(5000); | |
return (<p>Output 'Hello World' to console every five seconds.</p>); | |
}; |
This file contains 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 React, { useEffect } from 'react'; | |
const MyComponentWithInterval = () => { | |
useEffect(() => { | |
const myInterval = setInterval(() => { | |
console.log('Hello World'); | |
}, 5000); | |
return () => clearInterval(myInterval); | |
}, []); | |
This file contains 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 { useEffect, useState } from 'react'; | |
import { includes, reduce, lowerCaseOf } from '@7urtle/lambda'; | |
const mobileDevices = ['ipad', 'iphone', 'ipod', 'android']; | |
const includesAnyOf = where => reduce(false)((a, c) => includes(c)(where) ? true : a); | |
const isDeviceMobile = () => | |
includesAnyOf(lowerCaseOf(navigator.userAgent))(mobileDevices) || | |
includesAnyOf(lowerCaseOf(navigator.platform))(mobileDevices) || | |
(includes("Mac")(navigator.userAgent) && "ontouchend" in document); | |
This file contains 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 jwt from 'jsonwebtoken'; | |
// don't fortget to generate your own private and public key | |
// by openssl: https://gist.github.com/MeetMartin/8b3e72e4b94cdc6d063671a69440a7e2 | |
const privateKey = | |
`-----BEGIN EC PRIVATE KEY----- | |
MIHcAgEBBEIANjT0EzYXVqsHeKitVMvAQ57pzZWcv5QEWsCap4hl3mk/DIkRCYzg | |
9YGcBtLWhuNitEeKFGLi91rohc2EzmTVIbOgBwYFK4EEACOhgYkDgYYABAFjzu7a | |
UwPT7fIFtwc89Vrkj4a1iXOYNhWEZ97V2EbpFq3AU28o7MoV+IbSv/VrGsHA/1SD |
This file contains 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
# private key | |
openssl ecparam -genkey -name secp521r1 -noout -out es512-private.pem | |
# public key | |
openssl ec -in ecdsa-p521-private.pem -pubout -out es512-public.pem |
This file contains 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 jwt from 'jsonwebtoken'; | |
const key = 'MuchSecretVerySecureSoSafe'; | |
const theSecret = jwt.verify(token, key); // returns the original encrypted JSON |
This file contains 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 axios from 'axios'; | |
cons postToMyApi = payload => | |
axios.post( | |
'/v1/my-api', | |
{ | |
"request": payload.request | |
}, | |
{ | |
headers: { |