Skip to content

Instantly share code, notes, and snippets.

View washingtonsoares's full-sized avatar
🎯
Focusing

Washington Soares washingtonsoares

🎯
Focusing
View GitHub Profile
// 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)) {
@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>

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 / 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
@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 / array_iteration_thoughts.md
Created January 13, 2017 14:58 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@washingtonsoares
washingtonsoares / spark.md
Created December 14, 2016 19:20 — forked from jesperfj/spark.md
Spark on Heroku

This guide will get you started using Spark on Heroku/Cedar. Spark is basically a clone of Sinatra for Java. 'Nuff said.

Create your app

Create a single Java main class in src/main/java/HelloWorld.java:

:::java
import static spark.Spark.*;
import spark.*;
@washingtonsoares
washingtonsoares / git-zsh-checkout-autocomplete-local-only.md
Created October 15, 2016 22:17 — forked from mmrko/git-zsh-checkout-autocomplete-local-only.md
List only local branches when autocompleting git checkout (Zsh)
git config --global alias.checkoutr checkout
nano /usr/local/share/zsh/site-functions/git-completion.bash

...and then modify the file as follows...

-__gitcomp_nl "$(__git_refs '' $track)"
+if [ "$command" = "checkoutr" ]; then
+    __gitcomp_nl "$(__git_refs '' $track)"
+else
http://appcamp.io/courses/user-interface/layout-simple

http://thompsonemerson.github.io/ionic-collection/


## ionic examples
ionic start ionicApp
ionic start blankApp blank
ionic start tabsApp tabs
@washingtonsoares
washingtonsoares / BotãoWhatsApp.html
Created April 24, 2016 17:06 — forked from lucianobragaweb/BotãoWhatsApp.html
Como abrir o WhatsAPP no seu site
<!--
Subistitua o Número(8888387788) pelo seu número do WhatsApp
Siga este padrão: DDD + Numero, ex: 88 8838 7788 (Meu Número Whats)
-->
<a href="intent://send/8888387788#Intent;scheme=smsto;package=com.whatsapp;action=android.intent.action.SENDTO;end">Vamos Conversar?</a>