Skip to content

Instantly share code, notes, and snippets.

View HenriqueSilverio's full-sized avatar
🎯
Focusing

Henrique Silvério HenriqueSilverio

🎯
Focusing
View GitHub Profile
const cleanup = async () => {
try {
console.log('Cleaning up')
} catch (error) {
console.error(error)
process.exit(1)
}
}
const start = async () => {
// 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 => {
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!')
{
"[csv]": {
"files.encoding": "windows1252"
},
"[javascript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.formatOnSave": false
const client = { name: 'RabbitMQ' }
const broker = () => ({
client,
connection: null,
async connect (url) {
if (!this.connection) {
this.connection = `Connected to: ${url}`
}
return this.connection
const BrokerManager = function BrokerManager () {
let connection = null
let channel = null
return Object.create({
async getConnection () {
if (!connection) {}
return connection
},
async getChannel () {
if (!channel) {}
(() => {
const tracksSelector = '.tracklist-row'
const $tracks = Array.from(document.querySelectorAll(tracksSelector))
const tracks = $tracks.reduce((result, track) => {
const { name, artist } = {
name: track.querySelector('.tracklist-name').innerText.trim(),
artist: track.querySelector('.tracklist-row__artist-name-link').innerText.trim()
}
return `${result}\n${name} - ${artist}`
}, '')
<?php
function getChildrenProducts()
{
$productId = get_the_ID();
$product = wc_get_product($productId);
$childrenIds = $product->get_children();
if (empty($childrenIds)) {
return [];
<?php
function str_random($length = 16)
{
$string = '';
$len = strlen($string);
while ($len < $length) {
$size = $length - $len;