Skip to content

Instantly share code, notes, and snippets.

View weslleyaraujo's full-sized avatar
💤

Weslley Araujo weslleyaraujo

💤
View GitHub Profile
// Define which elements this form is going to have
interface FormElements extends HTMLFormControlsCollection {
fieldName: HTMLInputElement;
}
// Set a "HTMLFormElement" interface with those elements
interface MyForm extends HTMLFormElement {
readonly elements: FormElements;
}
function useTimeout(callback: () => void, delay = 1000 * 5) {
const callbackRef = useRef<typeof callback | null>(null);
useEffect(() => {
callbackRef.current = callback;
}, [callback]);
useEffect(() => {
function execute() {
callbackRef.current?.();
const useAsync = <T, E = string>(
asyncFunction: () => Promise<T>,
immediate = true
) => {
const [status, setStatus] = useState<
"idle" | "pending" | "success" | "error"
>("idle");
const [value, setValue] = useState<T | null>(null);
const [error, setError] = useState<E | null>(null);
// The execute function wraps asyncFunction and
@weslleyaraujo
weslleyaraujo / simple-fuzzy.js
Created August 8, 2020 17:56
simple fuzzy search regex
new RegExp(".*" + "string".split("").join(".*") + ".*")
@weslleyaraujo
weslleyaraujo / index.html
Last active January 14, 2020 21:16
React w/TypeScript
<div id="app"></div>
@weslleyaraujo
weslleyaraujo / Build_Vim7.4_CentOS7.txt
Created October 10, 2017 10:10 — forked from junxie6/Build_Vim7.4_CentOS7.txt
Compile the latest Vim 7.4 on CentOS 7
Compile the latest Vim 7.4 on CentOS 7
# yum install gcc make ncurses ncurses-devel
# yum install ruby ruby-devel lua lua-devel luajit \
luajit-devel ctags git python python-devel \
python3 python3-devel tcl-devel \
perl perl-devel perl-ExtUtils-ParseXS \
perl-ExtUtils-XSpp perl-ExtUtils-CBuilder \
perl-ExtUtils-Embed
@weslleyaraujo
weslleyaraujo / destructuring.js
Created October 14, 2015 16:26 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring.
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => {
return [1, 2, 3];
import styled from ‘styled-components’;
const Score = styled.div`
 /* some styles here … */
 font-size: ${props => props.length <= 2 ? 62 : 45}px;
`;
const { guessed, all } = getState().match;
console.log(all, guessed) // ['red'] ['red']
if (guessed[0] === all[0]) {
// keep going from here, guesses are correct
return;
}
// player didnt guessed properly, do something about it
import sleep from 'utils/sleep';
const SONG_DELAY_TIME = 400;
export const sing = payload => async (dispatch, getState) => {
dispatch(startSong());
const { match } = getState();
for (let i = 0; i <= match.all.length - 1; i++) {
const id = match.all[i];
dispatch(lightenPad({ id }));
await sleep(SONG_DELAY_TIME); // sleep time during note play