Skip to content

Instantly share code, notes, and snippets.

View HenriqueSilverio's full-sized avatar
🎯
Focusing

Henrique Silvério HenriqueSilverio

🎯
Focusing
View GitHub Profile
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
type Test = {
foo: string,
bar: string,
baz: string,
daz?: string,
}
type Test1 = Optional<Test, 'foo'>
@HenriqueSilverio
HenriqueSilverio / ssl-tls-nginx.md
Last active February 26, 2022 15:03
Instalação/Configuração de SSL/TLS no Nginx com Let’s Encrypt

SSL/TLS no Nginx com Let’s Encrypt

Instalar o cliente do Let’s Encrypt

Primeiro adicione o repositório do certbot com o seguinte comando:

add-apt-repository ppa:certbot/certbot

Em seguida instale o certbot e o plugin para o Nginx:

@HenriqueSilverio
HenriqueSilverio / express-async-handler.js
Last active December 23, 2021 16:14
Utility for Express.js < 5
const asyncHandler = (fn) => (
(req, res, next) => {
Promise.resolve(fn(req, res, next))
.catch(next)
}
)
export default asyncHandler
/**
* Scenario:
* The user requests an account sync
* Given the account
* And the institution of account
* And the user of account
* When the user requests the account sync
* Then a sync is scheduled
* And the sync scheduled event is created
*/
const capitalize = (string = '') => {
if (toString.call(string) !== '[object String]') {
return ''
}
const name = string.split(' ')[0]
return name.charAt(0).toUpperCase() + name.slice(1)
}
const cleanup = async () => {
try {
console.log('Cleaning up')
} catch (error) {
console.error(error)
process.exit(1)
}
}
const start = async () => {
const start = async () => {
throw new Error('Failed to start!')
}
start()
.catch(async err => {
// Precisa de async no catch pra fazer upload de alguma coisa por exemplo...
// Mas por ser async, pode por sua vez dar erro também...
// Então throw novamente...
throw new Error('Failed to catch start error!')
// Implementation of Kotlin `String.toByteArray` in JavaScript
// https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-byte-array.html
const UTF8ByteArrayFromString = (string) => {
const encoder = new TextEncoder()
return encoder.encode(string)
}
const stringFromUTF8ByteArray = (array) => {
const decoder = new TextDecoder()
const start = async () => {
try {
throw new Error('Failed to start!')
} catch (err) {
await somethingThrows()
}
}
start()
.catch(err => {
{
"[csv]": {
"files.encoding": "windows1252"
},
"[javascript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.formatOnSave": false