Skip to content

Instantly share code, notes, and snippets.

View AlexcastroDev's full-sized avatar
🚀
Let's go !!!!

Alexandro Castro AlexcastroDev

🚀
Let's go !!!!
  • Flecto
  • Portugal
View GitHub Profile
@AlexcastroDev
AlexcastroDev / paginate.js
Created June 6, 2021 22:41
how to paginate itens in Javascript
const paginate = (items, page = 1, perPage = 10) => {
const offset = perPage * (page - 1);
const totalPages = Math.ceil(items.length / perPage);
const paginatedItems = items.slice(offset, perPage * page);
return {
previousPage: page - 1 ? page - 1 : null,
nextPage: (totalPages > page) ? page + 1 : null,
total: items.length,
totalPages: totalPages,
// get all Zoom participants
Object.values(document.getElementsByClassName('participants-ul')[0].getElementsByClassName('participants-item__display-name')).map(item => item.innerText).join(',')
// Remove sidebar wol.jw.org
document.getElementById('secondaryNavContent').style.display = 'none'
document.getElementsByClassName('articlePositioner')[0].style.margin = '0px'
@AlexcastroDev
AlexcastroDev / ModuleDecorator.tsx
Last active March 10, 2023 15:13
React Decorator as High order component without class
import React from 'react'
import { IAsyncAppDispatch } from 'my-package'
export interface IHandlers {
onSuccess: IAsyncAppDispatch['onSuccess']
onError: IAsyncAppDispatch['onError']
}
export interface DefaultFormProps {
handlers?: IHandlers
@AlexcastroDev
AlexcastroDev / bash_log.txt
Created April 17, 2023 20:56
streams_question_linux_foundation
12_streams git:(main) ✗ node 8_kb_data.js
read chunk <Buffer 4e 61 6d 65 2c 41 67 65 2c 4c 6f 63 61 74 69 6f 6e 0a 42 75 64 64 79 2c 35 2c 4e 65 77 20 59 6f 72 6b 0a 4c 75 63 6b 79 2c 32 2c 4c 6f 73 20 41 6e 67 ... 8287 more bytes>
stop reading
12_streams git:(main) ✗ node 16_kb_data.js
read chunk <Buffer 4e 61 6d 65 2c 41 67 65 2c 4c 6f 63 61 74 69 6f 6e 0a 42 75 64 64 79 2c 35 2c 4e 65 77 20 59 6f 72 6b 0a 4c 75 63 6b 79 2c 32 2c 4c 6f 73 20 41 6e 67 ... 17332 more bytes> 17382
stop reading
➜ 12_streams git:(main) ✗ node 128_kb_data.js
read chunk <Buffer 4e 61 6d 65 2c 41 67 65 2c 4c 6f 63 61 74 69 6f 6e 0a 42 75 64 64 79 2c 35 2c 4e 65 77 20 59 6f 72 6b 0a 4c 75 63 6b 79 2c 32 2c 4c 6f 73 20 41 6e 67 ... 65486 more bytes> 65536
function closureRequest() {
let success = false, error = false, data = null;
const dispatch = async (fn) => {
try {
data = await fn();
success = true;
error = false;
} catch {
success = false;
version: '3.3'
services:
postgres:
image: postgres
restart: always
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
ports:
import express from "express"
const app = express ();
app.get("/events",(req, res) => {
res. setHeader ("Content-Type", "text/event-stream");
res.setHeader ("Cache-Control", "no-cache");
res.setHeader ("Connection","keep-alive");
// Clean headers
res.flushHeaders();
const transform = new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' })
async function readUserInput(): Promise<number> {
const buffer = new Uint8Array(1024);
const bytesRead = await Deno.stdin.read(buffer);
const input = new TextDecoder().decode(buffer.subarray(0, Number(bytesRead)));
if (Number.isNaN(Number(input))) {
throw new Error('No bytes read');
}
@AlexcastroDev
AlexcastroDev / db.json
Last active August 7, 2023 04:42
public_links
[
{
"details": {
"summary": "An Elo-type rating model for players and teams of variable strength",
"p": "The Elo rating system, which was originally proposed by Arpad Elo for chess, has become one of the most important rating systems in sports, economics and gaming nowadays. Its original formulation is based on two-player zero-sum games, but it has been adapted for team sports and other settings. In 2015, Junca and Jabin proposed a kinetic version of the Elo model..."
},
"link": "https://arxiv.org/abs/2109.15046"
}
]
private async requestWithRetry(
query: string,
username: string,
retryDelay: number = 1000, // Set the delay between retries (in milliseconds)
) {
const tokens = [
Deno.env.get("GITHUB_TOKEN1"),
Deno.env.get("GITHUB_TOKEN2"),
];
const maxRetries = tokens.length