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 cleanup = async () => { | |
| try { | |
| console.log('Cleaning up') | |
| } catch (error) { | |
| console.error(error) | |
| process.exit(1) | |
| } | |
| } | |
| const start = async () => { |
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
| // 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() |
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 start = async () => { | |
| try { | |
| throw new Error('Failed to start!') | |
| } catch (err) { | |
| await somethingThrows() | |
| } | |
| } | |
| start() | |
| .catch(err => { |
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 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!') |
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
| { | |
| "[csv]": { | |
| "files.encoding": "windows1252" | |
| }, | |
| "[javascript]": { | |
| "editor.formatOnSave": true, | |
| "editor.defaultFormatter": "esbenp.prettier-vscode" | |
| }, | |
| "[javascriptreact]": { | |
| "editor.formatOnSave": false |
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 client = { name: 'RabbitMQ' } | |
| const broker = () => ({ | |
| client, | |
| connection: null, | |
| async connect (url) { | |
| if (!this.connection) { | |
| this.connection = `Connected to: ${url}` | |
| } | |
| return this.connection |
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 BrokerManager = function BrokerManager () { | |
| let connection = null | |
| let channel = null | |
| return Object.create({ | |
| async getConnection () { | |
| if (!connection) {} | |
| return connection | |
| }, | |
| async getChannel () { | |
| if (!channel) {} |
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 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}` | |
| }, '') |
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
| <?php | |
| function getChildrenProducts() | |
| { | |
| $productId = get_the_ID(); | |
| $product = wc_get_product($productId); | |
| $childrenIds = $product->get_children(); | |
| if (empty($childrenIds)) { | |
| return []; |
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
| <?php | |
| function str_random($length = 16) | |
| { | |
| $string = ''; | |
| $len = strlen($string); | |
| while ($len < $length) { | |
| $size = $length - $len; |