This file contains hidden or 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'; | |
| const Page404 = () => { | |
| return ( | |
| <> | |
| <p> | |
| This is not the page that you are looking for! | |
| </p> | |
| </> | |
| ); |
This file contains hidden or 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
| // pure function | |
| // depends only on its input | |
| // and produces only its output | |
| const pureFunction = input => input + 1; | |
| const pureFunction2 = function(input) { | |
| return input + 1; | |
| }; |
This file contains hidden or 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
| 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 |
This file contains hidden or 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 data = { some: 'json' }; | |
| const key = 'MuchSecretVerySecureSoSafe'; | |
| jwt.sign(data, key); |
This file contains hidden or 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: { |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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); | |
| }, []); | |