Skip to content

Instantly share code, notes, and snippets.

View luizcalaca's full-sized avatar

Luiz Calaça luizcalaca

View GitHub Profile
@luizcalaca
luizcalaca / sum.py
Created April 7, 2024 19:33
Python OOP
# arquivo soma.py
class Soma():
def __init__(self, name: str) -> None:
self.name = name
def sum(self, a, b) -> int:
return a + b
def str_name(self) -> str:
return self.name
@luizcalaca
luizcalaca / api.js
Created July 10, 2023 13:31
API + Node.js + Express.js + Token + business rules
'use strict';
const lodash = require('lodash');
const {v4} = require('uuid');
const express = require('express');
const app = express();
app.use(express.json());
@luizcalaca
luizcalaca / consumer.js
Last active July 2, 2023 16:55
Node.js + BullMQ
const { Worker } = require('bullmq')
const redisConfiguration = {
connection: {
host: "localhost",
port: 6379,
username: "default",
password: "redispw"
}
}
@luizcalaca
luizcalaca / fetch.js
Created June 11, 2023 01:00
Node.js 20 - native fetch
async function fetchData() {
try {
const response = await fetch('https://api.spacexdata.com/v4/launches/latest');
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
console.log('Data:', data);
} catch (error) {
@luizcalaca
luizcalaca / node_test_runner.js
Created June 10, 2023 18:01
Tests in Node.js 20 - built-in test runner
import { test, mock } from 'node:test';
import assert from 'node:assert';
import fs from 'node:fs';
test('first test', (t) => {
assert.strictEqual(8, 8);
});
test('second test', (t) => {
assert.strictEqual(9, 9);
@luizcalaca
luizcalaca / info.md
Created June 10, 2023 13:28
Updating Node.js
$ node -v
$ sudo npm install -g n
(Use this command to install the stable node release.)
@luizcalaca
luizcalaca / reverse_string.ts
Last active June 3, 2023 18:30
Reversing a string using Typescript with Decorators
// Decorator de split
function splitDecorator(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
const originalMethod = descriptor.value;
descriptor.value = function (str: string) {
const arr = str.split('');
return originalMethod.apply(this, [arr]);
};
return descriptor;
@luizcalaca
luizcalaca / lua.js
Created March 15, 2023 17:50
Dia carreira com Lua
console.log('lua é top das galáxias');
@luizcalaca
luizcalaca / cluster.js
Created January 4, 2023 01:30
Node.js and cluster
const express = require('express');
const app = express()
const os = require ('os')
const cluster = require ('cluster')
const numCPU = os.cpus().length
app.get('/heavy', (req, res)=> {
counter = 0;
for (let index = 0; index < 10000000000000; index++) {
@luizcalaca
luizcalaca / App.js
Created December 27, 2022 02:29
React.js + toast
import React from 'react'
import { toast, ToastContainer } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
export function App() {
function handleClick() {
toast.error('error');
}