Skip to content

Instantly share code, notes, and snippets.

@MeetMartin
MeetMartin / 404.js
Created August 8, 2021 06:22
React Router In Under 60 Seconds
import React from 'react';
const Page404 = () => {
return (
<>
<p>
This is not the page that you are looking for!
</p>
</>
);
// pure function
// depends only on its input
// and produces only its output
const pureFunction = input => input + 1;
const pureFunction2 = function(input) {
return input + 1;
};
const L = require('@7urtle/lambda');
const myCurry = L.curry((a, b) => a + b);
const myNary = L.nary(a => b => a + b);
// myCurry and myNary can be called
// both as curried and n-ary.
myCurry(1)(2) === myCurry(1, 2);
// => true
import jwt from 'jsonwebtoken';
const data = { some: 'json' };
const key = 'MuchSecretVerySecureSoSafe';
jwt.sign(data, key);
import axios from 'axios';
cons postToMyApi = payload =>
axios.post(
'/v1/my-api',
{
"request": payload.request
},
{
headers: {
import jwt from 'jsonwebtoken';
const key = 'MuchSecretVerySecureSoSafe';
const theSecret = jwt.verify(token, key); // returns the original encrypted JSON
# 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';
// 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
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 React, { useEffect } from 'react';
const MyComponentWithInterval = () => {
useEffect(() => {
const myInterval = setInterval(() => {
console.log('Hello World');
}, 5000);
return () => clearInterval(myInterval);
}, []);