Skip to content

Instantly share code, notes, and snippets.

View washingtonsoares's full-sized avatar
🎯
Focusing

Washington Soares washingtonsoares

🎯
Focusing
View GitHub Profile
@washingtonsoares
washingtonsoares / utils.js
Created October 3, 2017 02:43
Funções Uteis (só one-liners)
const fact = n => n && n * fact(n-1) || 1;
const decToBin = dec => dec && dec % 2 + 10 * decToBin(0 | dec / 2) || 0;
const iif = pr => t => f => x => pr(x) ? t(x) : f(x);
const not = fn => x => !fn(x);
const or = pra => prb => x => pra(x) || prb(x);
const isArray = x => x instanceof Array;
const isPromise = x => x instanceof Promise;
const isPlainObject = x => typeof x === 'object' && x !== null && x == '[object Object]';
const isTraversable = or(isPlainObject)(isArray);
const keys = Object.keys.bind(Object);
@washingtonsoares
washingtonsoares / rails_annotations.md
Created May 10, 2018 01:39 — forked from daltonjorge/rails_annotations.md
Explicações de conceitos do Rails e outras infos úteis.

Active Record

É um design pattern que o Rails implementa a partir da gem ActiveRecord.

Serve para conectar a camada Model da aplicação com tabelas do database, para assim criar um modelo de domínio persistível, onde a lógica (Model) e dados (BD) são apresentados em uma única solução.

Já persiste no BD:

obj.create

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@washingtonsoares
washingtonsoares / example.js
Created January 20, 2020 18:17 — forked from jcarroll2007/example.js
React Intersection Observer Hook: `useIsElementInView`
import React from 'react'
import useIsElementInView from './useIsElementInView'
export function Example() {
const { ref, isInView } = useIsElementInView()
return (
<div ref={ref}>
{isInView ? 'It is in the view!' : 'Not in view (so you cant really even tell if it works I guess...)'}
</div>
// https://letsbuildui.dev/articles/building-a-dropdown-menu-component-with-react-hooks
import { useState, useEffect, RefObject } from 'react';
export const useDetectOutsideClick = (ref: RefObject<HTMLElement>, initialState: boolean) => {
const [isActive, setIsActive] = useState(initialState);
useEffect(() => {
const pageClickEvent = (event: MouseEvent) => {
// If the active element exists and is clicked outside of
if (ref.current !== null && !ref.current.contains(event.target as Node)) {