Skip to content

Instantly share code, notes, and snippets.

import React from 'react';
import useDeviceType from '../hooks/useDeviceType';
const DeviceComponent = () => {
const isMobile = useDeviceType();
return (
<p>
You are using a {isMobile ? 'mobile device' : 'computer'}.
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;
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>);
};
import React, { useEffect } from 'react';
const MyComponentWithInterval = () => {
useEffect(() => {
const myInterval = setInterval(() => {
console.log('Hello World');
}, 5000);
return () => clearInterval(myInterval);
}, []);
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);
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
# 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
import jwt from 'jsonwebtoken';
const key = 'MuchSecretVerySecureSoSafe';
const theSecret = jwt.verify(token, key); // returns the original encrypted JSON
import axios from 'axios';
cons postToMyApi = payload =>
axios.post(
'/v1/my-api',
{
"request": payload.request
},
{
headers: {