Skip to content

Instantly share code, notes, and snippets.

View sayhicoelho's full-sized avatar
🏠
Working from home

Renan Coelho sayhicoelho

🏠
Working from home
  • Hotcafe.io
  • Rio de Janeiro, Brazil
View GitHub Profile
@sayhicoelho
sayhicoelho / index.js
Last active February 27, 2024 00:25
NodeJS: In Memory Worker + Worker Threads
const worker = require('./worker')
const data = {
// ...
}
worker.enqueue('send-reports', data)
@sayhicoelho
sayhicoelho / index.js
Last active February 21, 2024 15:42
NodeJS: In Memory Worker
const worker = require('./worker')
async function main() {
let count = 0
const interval = setInterval(() => {
worker.enqueue('jobExample', {
message: `Hello from worker ${++count}!`
})
@sayhicoelho
sayhicoelho / shufflearray.js
Created July 17, 2023 15:32
JavaScript: Shuffle Array
function shuffleArray(array) {
let currentIndex = array.length
let temporaryValue, randomIndex
while (currentIndex !== 0) {
randomIndex = Math.floor(Math.random() * currentIndex)
currentIndex--
temporaryValue = array[currentIndex]
array[currentIndex] = array[randomIndex]
@sayhicoelho
sayhicoelho / findDocumentIndex.js
Created June 16, 2023 18:52
Find document index/position with MongoDB
async function findDocumentIndex({ _id, collection, conditions, sort }) => {
const data = await db.collection(collection).aggregate([{
$match: conditions
}, {
$sort: sort
}, {
$group: {
_id: null,
positions: {
$push: "$_id"
@sayhicoelho
sayhicoelho / rss.js
Created November 21, 2021 21:26
Fetch RSS using Node.js
const { parse } = require('rss-to-json')
async function fetchPosts() {
const rss = await parse('http://rss.uol.com.br/feed/economia.xml')
return rss.items
}
fetchPosts()
.then(posts => {
@sayhicoelho
sayhicoelho / DelayedJob.php
Created December 30, 2020 01:00
Laravel: Run only latest delayed job
<?php
namespace App\Support;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Facades\Redis;
class DelayedJob
{
/**
class Validator {
constructor(data, rules) {
this.data = data
this.rules = rules
this.errors = {}
}
get validations() {
return {
required(field) {
@sayhicoelho
sayhicoelho / AccordionGroup.svelte
Created August 1, 2020 23:37
Svelte accordion based on Bootstrap Collapse.
<script>
import { setContext } from 'svelte';
export let multiple = false
export let header = true
const items = new Set()
setContext('accordion', {
getMultiple: () => multiple,
@sayhicoelho
sayhicoelho / AccordionGroup.vue
Last active February 16, 2023 17:20
Vue.js Accordion base on Bootstrap Collapse.
<template>
<div class="accordion-group">
<slot />
</div>
</template>
<script>
export default {
name: 'AccordionGroup',
props: {
@sayhicoelho
sayhicoelho / pure-js-bootstrap-accordion.html
Last active May 22, 2023 08:52
Pure JS accordion based on Bootstrap Collapse.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;