Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Henrique Silvério HenriqueSilverio

🏠
Working from home
View GitHub Profile
View async-error-handling-2.js
const start = async () => {
try {
throw new Error('Failed to start!')
} catch (err) {
await somethingThrows()
}
}
start()
.catch(err => {
View async-error-handling.js
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!')
View settings.json
{
"[csv]": {
"files.encoding": "windows1252"
},
"[javascript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.formatOnSave": false
View factory.js
const client = { name: 'RabbitMQ' }
const broker = () => ({
client,
connection: null,
async connect (url) {
if (!this.connection) {
this.connection = `Connected to: ${url}`
}
return this.connection
View broker-manager.js
const BrokerManager = function BrokerManager () {
let connection = null
let channel = null
return Object.create({
async getConnection () {
if (!connection) {}
return connection
},
async getChannel () {
if (!channel) {}
View extract-from-playlist.js
(() => {
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}`
}, '')
View get-children-products.php
<?php
function getChildrenProducts()
{
$productId = get_the_ID();
$product = wc_get_product($productId);
$childrenIds = $product->get_children();
if (empty($childrenIds)) {
return [];
View str_random.php
<?php
function str_random($length = 16)
{
$string = '';
$len = strlen($string);
while ($len < $length) {
$size = $length - $len;
@HenriqueSilverio
HenriqueSilverio / 01--src-Contracts-Shortcode.php
Last active Oct 19, 2018
Object-Oriented approach to create shortcodes in WordPress plugins.
View 01--src-Contracts-Shortcode.php
<?php
namespace MyPlugin\Contracts;
interface Shortcode
{
public function getTag(): string;
public function start(): void;
@HenriqueSilverio
HenriqueSilverio / permissions-seeder.php
Last active Sep 23, 2018
Laravel Roles and Capabilities seeder sample.
View permissions-seeder.php
<?php
use App\Models\Role;
use App\Models\Capability;
use Illuminate\Database\Seeder;
class PermissionsSeeder extends Seeder
{
private $roles = [[
'slug' => 'administrator',
You can’t perform that action at this time.