Skip to content

Instantly share code, notes, and snippets.

View LucasBadico's full-sized avatar

Lucas Badico LucasBadico

View GitHub Profile
@LucasBadico
LucasBadico / delete.go
Created December 20, 2023 01:56
GOLANG CONCURRENCY MODEL EXAMPLE
// CODE EXAMPLE FROM YOUTUBE LIVE: Golang: Modelo de concorrencia goroutine + channels
// LINK: https://youtube.com/live/TRx3W4mLFf8
// Lucas_Badico: Dev, mentor e apaixonado por Programacao
// SIGA ME EM TODAS AS REDES SOCIAIS
package main
import (
"time"
"fmt"
"sync"
@LucasBadico
LucasBadico / notifier.ts
Created February 25, 2023 02:00
objeto vs tipo
class Notifier {
private subscribers: ((notification: Notification) => void)[] = [];
constructor(subscribers: ((notification: Notification) => void)[]) {
this.subscribers = subscribers;
}
public notify(notification: Notification) {
this.subscribers.forEach((subscriber) => subscriber(notification));
}
@LucasBadico
LucasBadico / app.js
Last active February 8, 2023 20:17
Introdução a Banco de Dados - parte 1 | Encontro de Código
const express = require("express");
const fs = require("fs");
const path = require("path");
const app = express();
const port = process.env.PORT || 3000;
const dataFilePath = path.join(__dirname, "data.json");
// Função para ler os dados do arquivo JSON
const readData = () => {
@LucasBadico
LucasBadico / 0001 - for tradicional.js
Created September 18, 2022 16:57
métodos de array: map, ou pq nao usar for each
const items = [1, 2, 3, 4, 5];
const results = [];
for (let i = 0; i < items.lenght; i++){
results[i] = items[i]*2;
}
console.log(results);
const { useState, useEffect } = React;
function App() {
const [posts, setPosts] = useState([]);
useEffect(() => {
axios.get('https://jsonplaceholder.typicode.com/posts').then((res) => {
setPosts(res.data.slice(0, 10));
console.log(posts);
});
@LucasBadico
LucasBadico / 001 - oop heranca e abstracao.js
Created September 12, 2022 22:47
Serviços funcionais
/*
tem rodas
anda de ponto a ponto b
tem peso
*/
class Vehicle {
// dado
constructor({
model,
color,
import { mysql } from '@common/connectors/mysql';
import { GarageRepo, GarageService } from '../../src';
const connection = mysql()('Garage');
describe('Garage Service test', () => {
it('should GarageService be defined', () => {
expect(GarageService).toBeDefined();
@LucasBadico
LucasBadico / garage-service.spec.js
Created October 14, 2019 19:44
conexão com a database
import { mysql } from '@common/connectors/mysql';
import { GarageRepo, GarageService } from '../../src';
const connection = mysql()('Garage');
@LucasBadico
LucasBadico / garage-repo.js
Created October 14, 2019 19:38
create method in repository
export default class GarageRepo {
constructor(mysql, redis) {
this.mysql = mysql;
this.redis = redis;
}
create(attributes) {
return this.mysql.create({
input: attributes,
});
@LucasBadico
LucasBadico / garage-service.js
Created October 14, 2019 19:35
create method on serviço
export default class GarageService {
constructor(garageRepo) {
this.repository = garageRepo;
}
async create(data) {
return this.repository.create({
...data,
id: 'mockid'
})
}