Skip to content

Instantly share code, notes, and snippets.

View luizcalaca's full-sized avatar

Luiz Calaça luizcalaca

View GitHub Profile
@luizcalaca
luizcalaca / App.tsx
Last active December 21, 2022 10:49
React.js Hooks - useState, useRef, useMemo, useCallback, useReducer and useEffect with Typescript
//npx create-react-app my-app --template typescript
import {useState, useEffect} from 'react'
interface ITodo {
userId: number;
id: string;
title: string;
}
@luizcalaca
luizcalaca / App.js
Last active December 18, 2022 21:23
React Hooks - using useState, useEffect, useReducer
import './App.css';
import {useState} from 'react';
function App() {
const [count, setCount] = useState({count: 0, theme: 'light'})
//const [count, setCount] = useState(0)
//const [theme, setTheme] = useState("dark")
const incrementCount = () => {
setCount((prevState) => {
@luizcalaca
luizcalaca / for.js
Created December 12, 2022 17:31
Loop for Javascript
for (var i = 0; i < 9; i++) {
console.log(i);
// more statements
}
const args = process.argv.slice(2)
console.log(`Hello ${args[0]} your secret ${args[1]} is correct`)
@luizcalaca
luizcalaca / redux.js
Created November 7, 2022 17:46
Redux piece of code that so aWESOME GREAT I`M THE BEST OF THE WORLD
useState();
@luizcalaca
luizcalaca / create.spec.ts
Created September 28, 2022 00:14
BDD test with MongoDB: Mocha, chai and sinon
import chaiAsPromised from 'chai-as-promised';
import * as chai from 'chai'
import sinon from 'sinon'
import Book from '../../src/entities/Book';
import BookService from '../../src/Services/BookService';
import { Model } from 'mongoose';
chai.use(chaiAsPromised)
const expect = chai.expect
@luizcalaca
luizcalaca / function_generator_javascript.js
Last active September 19, 2022 16:20
Javascript function generator example
function* simple() {
yield 1
yield 2
yield 3
}
let a = simple()
console.log(a.next())
console.log(a.next())
console.log(a.next())
@luizcalaca
luizcalaca / process.md
Last active August 27, 2022 01:24
Node.js process - child and spawn

Node.js process

console.log() is the same of process.stdout.write(msg + '/n')

If you use on index.js:

console.log(process.argv)
@luizcalaca
luizcalaca / championsleague_challenge_hackerrank.js
Last active August 22, 2022 01:15
Hackerrank champions league challenge
import fetch from 'node-fetch'
import fs from 'fs'
const groupArray = (arr) => {
let map = new Map()
for (let i = 0; i < arr.length; i++) {
const s = JSON.stringify(arr[i].team1);
if (!map.has(s)) {
map.set(s, {
team: arr[i].team1,
@luizcalaca
luizcalaca / diagonal.js
Created August 20, 2022 23:56
Diagonal Difference - HackerRank
function diagonalDifference(arr) {
let principalDiagonal = 0
let secondaryDiagonal = 0
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length; j++) {
if (i == j) {
principalDiagonal += arr[i][j]
}
}
}