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
export const alpha = (color: string, opacity: number) => { | |
// if it has an alpha, remove it | |
if (color.length > 7) { | |
color = color.substring(0, color.length - 2); | |
} | |
// coerce values so ti is between 0 and 1. | |
const newOpacity = Math.round(Math.min(Math.max(opacity, 0), 1) * 255); | |
let opacityHex = newOpacity.toString(16).toUpperCase(); |
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 { useState, useEffect, useCallback } from 'react'; | |
import Peer from 'peerjs'; | |
const usePeer = ({ id, host, port, path, onOpen, onConnection, onDisconnection, onClose, onError, onMessage }) => { | |
const [peer, setPeer] = useState(); | |
const [peerId, setPeerId] = useState(); | |
const [connection, setConnection] = useState(); | |
const [message, setMessage] = useState(); | |
const onPeerOpen = useCallback((current) => { |
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
// https://stackblitz.com/edit/recursive-filter-prop?file=index.ts | |
// perf: https://jsbench.me/8cjrlaine7/1 | |
function flatFilter(nestedProp, compareKey, compareId, arr) { | |
return arr.filter(o => { | |
const keep = o[compareKey] != compareId; | |
if (keep && o[nestedProp]) { | |
o[nestedProp] = flatFilter(nestedProp, compareKey, compareId, o[nestedProp]); | |
} | |
return keep; |
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
# Add this function to your source | |
expose () { | |
if [ -n "$1" ]; then | |
ssh -R $3:80:$1 serveo.net | |
else | |
ssh -R 80:$1 serveo.net | |
fi | |
} |
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
const toCamelCase = string => { | |
return string.replace(/^([A-Z])|[\s-_](\w)/g, (match, p1, p2, offset) => { | |
if (p2) return p2.toUpperCase(); | |
return p1.toLowerCase(); | |
}); | |
} | |
console.log(toCamelCase("Hola perro")) |
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
[ | |
{ | |
"country": "Afghanistan", | |
"alpha_2_code": "AF", | |
"alpha_3_code": "AFG", | |
"numeric_code": 4, | |
"latitude": 33, | |
"longitude": 65 | |
}, | |
{ |