Skip to content

Instantly share code, notes, and snippets.

View salvoravida's full-sized avatar
💯
top

Salvatore Ravidà salvoravida

💯
top
View GitHub Profile
@salvoravida
salvoravida / unescapeUnicode.ts
Created January 19, 2022 10:13
unescape unicode and utf-8 hex chars
/**
* \xe2\x98\x89 Mercury -> ☉ Mercury
**/
function unescapeUtf8Hex(s: string): string {
if (typeof s !== 'string') return s;
return s.replace(/(?:\\x[\da-fA-F]{2})+/g, (m) => decodeURIComponent(m.replace(/\\x/g, '%')));
}
/**
* \\\\U0001F528 hello \\U0001F528 hello -> 🔨 hello 🔨 hello
@salvoravida
salvoravida / jwtRS256.sh
Created February 14, 2020 12:19 — forked from ygotthilf/jwtRS256.sh
How to generate JWT RS256 key
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
cat jwtRS256.key
cat jwtRS256.key.pub
@salvoravida
salvoravida / useStateRef.js
Created November 28, 2019 22:02
useStateRef
import { useState, useCallback } from 'react';
export const useStateRef = initialState => {
const [state, setState] = useState(() => ({
current: typeof initialState === 'function' ? initialState() : initialState
}));
const setStateRef = useCallback(
(setter, forceRender) => {
setState(prev => {