Skip to content

Instantly share code, notes, and snippets.

View vczb's full-sized avatar
🙃
Code with passion, unleash your creations.

Vinicius Zucatti vczb

🙃
Code with passion, unleash your creations.
View GitHub Profile
@vczb
vczb / fisher.js
Last active December 4, 2021 16:08
Sorting an Array in Random Order
/*
The above example, array.sort(), is not accurate, it will favor some numbers over the others.
The most popular correct method, is called the Fisher Yates shuffle, and was introduced in data science as early as 1938!
In JavaScript the method can be translated to this:
*/
const points = [40, 100, 1, 5, 25, 10];
@vczb
vczb / palindrome.js
Last active December 13, 2021 18:42
random list of palindromic words
/*
Write a script that creates an array with 10000 random words between 3 and 5 characters,
and returns the number of words that are palindromes in that array. Notes: You'll need to
return just the number of words.
*/
const alphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
const charLimit = [3,4,5];
const randomWords = [];
const palindromeWords = [];
@vczb
vczb / delete_all_local_branches.sh
Created December 16, 2021 14:48
Delete all local branches
git for-each-ref --format '%(refname:short)' refs/heads | grep -v "master\|stg1\|stg2\|stg3" | xargs git branch -D
@vczb
vczb / index.js
Created December 17, 2021 20:27
React TS custom hook to intersection observer dom elements
import { useEffect, useState, useRef } from 'react'
export default function useOnScreen(ref?: any) {
const observerRef = useRef<IntersectionObserver | null>(null)
const [isOnScreen, setIsOnScreen] = useState(false)
useEffect(() => {
observerRef.current = new IntersectionObserver(([entry]) =>
setIsOnScreen(entry.isIntersecting)
)
@vczb
vczb / index.js
Created December 17, 2021 20:29
useReziseWindow react custom hook
import { useEffect, useState } from 'react'
export default function useReziseWindow() {
const [windowWidth, setWindowWidth] = useState<number | null>()
useEffect(() => {
const onResize = () => {
setWindowWidth(window?.innerWidth)
}
@vczb
vczb / inspect.md
Created February 11, 2022 12:31
Service Worker

chrome

chrome://inspect/#service-workers

@vczb
vczb / docker-compose.yml
Last active March 20, 2022 22:22
Mongo DB - Docker
version: '3.1'
services:
mongo:
image: mongo:4.4-bionic
# restart: always
container_name: mongodb
environment:
MONGO_INITDB_ROOT_USERNAME: admin
@vczb
vczb / settings.json
Created March 13, 2022 14:29
Visual Studio Code - settings
{
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.detectIndentation": false,
"files.insertFinalNewline": true,
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.autoIndent": "full"
@vczb
vczb / createAsyncThunk.d.js
Created March 17, 2022 23:42
createAsyncThunk.d.ts
import type { Dispatch, AnyAction } from 'redux';
import type { ActionCreatorWithPreparedPayload } from './createAction';
import type { ThunkDispatch } from 'redux-thunk';
import type { FallbackIfUnknown, IsAny, IsUnknown } from './tsHelpers';
export declare type BaseThunkAPI<S, E, D extends Dispatch = Dispatch, RejectedValue = undefined, RejectedMeta = unknown, FulfilledMeta = unknown> = {
dispatch: D;
getState: () => S;
extra: E;
requestId: string;
signal: AbortSignal;
@vczb
vczb / fetcher.js
Created March 18, 2022 23:40
fetcher.ts
type FetchRequest = {
url: string;
method?: "GET" | "POST";
body?: object;
headers?: {
[key: string]: string;
};
};
type Error = {