Skip to content

Instantly share code, notes, and snippets.

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

Renan Coelho sayhicoelho

🏠
Working from home
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 / whatsapp-sendMessage.js
Last active October 8, 2023 06:58
Send messages to WhatsApp (web version only) programmatically.
function sendMessage(message){
const mainEl = document.querySelector('#main')
const textareaEl = mainEl.querySelector('div[contenteditable="true"]')
if(!textareaEl) {
throw new Error('There is no opened conversation')
}
textareaEl.focus()
document.execCommand('insertText', false, message)
@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 / 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;
@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 / Paginator.vue
Last active June 5, 2022 19:05
A Laravel pagination for Vue.js
<template>
<nav aria-label="Page navigation" v-if="paginationTotal > 1">
<ul :class="{ 'pagination': true, 'flex-wrap': true, 'justify-content-center': centered }">
<li :class="{ 'page-item': true, 'disabled' : currentPage <= 1 }">
<a class="page-link" href="#" @click.prevent="pageChanged(currentPage - 1)" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
<template v-if="needLeftDots">
<li v-for="n in 2" :key="n" :class="activePage(n)">
@sayhicoelho
sayhicoelho / config.ini
Last active January 7, 2022 08:26 — forked from FlokiTV/config.ini
Cyber Hunter config.ini
[account]
first_login_game = 0
[settings]
open_music = 1
voice_language = english
graphic_lvl_reported = 1
match_type = 100004
[basic_setting]
@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 => {