Skip to content

Instantly share code, notes, and snippets.

View WagnerMoreira's full-sized avatar

Wagner Moreira WagnerMoreira

View GitHub Profile
@WagnerMoreira
WagnerMoreira / settings.json
Created February 5, 2024 20:01
settings json
{
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
@WagnerMoreira
WagnerMoreira / utilities.js
Last active April 12, 2023 22:40
left pad string (pad start), isArray, isPositiveInt
function leftPad(str, padLength) {
const arr = str.split(" ")
Array.from(Array(padLength).keys()).forEach(x => arr.push(" "))
return arr.reverse().join().replace(/,/g, '')
}
const isArray = (x) => x.hasOwnProperty('length');
const isPositiveInt = (n) => n > 0;
import {SetStateAction, useCallback} from 'react';
import {create} from "zustand";
export type EqualityFn<T> = (left: T | null | undefined, right: T | null | undefined) => boolean;
// eslint-disable-next-line @typescript-eslint/ban-types
const isFunction = (fn: unknown): fn is Function => (typeof fn === 'function');
/**
* Create a global state

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

@WagnerMoreira
WagnerMoreira / javascript-remove-accents.js
Created September 2, 2021 12:37 — forked from marcelo-ribeiro/javascript-remove-accents.js
An Javascript function to remove accents and others characters from an input string.
// Example: https://codepen.io/marcelo-ribeiro/pen/OJmVOyW
const accentsMap = new Map([
["A", "Á|À|Ã|Â|Ä"],
["a", "á|à|ã|â|ä"],
["E", "É|È|Ê|Ë"],
["e", "é|è|ê|ë"],
["I", "Í|Ì|Î|Ï"],
["i", "í|ì|î|ï"],
["O", "Ó|Ò|Ô|Õ|Ö"],
@WagnerMoreira
WagnerMoreira / github-setup.md
Last active March 29, 2021 16:55
Github setup

Global configuration

git config --global user.name 'your_github_username'
git config --global user.email 'your_github_email'

Shortcuts

(Run the command below in your terminal to open the config file using VScode)

code ~/.gitconfig

@WagnerMoreira
WagnerMoreira / NavigationPrompt.jsx
Created August 12, 2020 20:18 — forked from bummzack/NavigationPrompt.jsx
A replacement component for the react-router `Prompt`.
import React from 'react';
import {withRouter} from 'react-router-dom';
import PropTypes from 'prop-types';
/**
* A replacement component for the react-router `Prompt`.
* Allows for more flexible dialogs.
*
* @example
* <NavigationPrompt when={this.props.isDirty}>
@WagnerMoreira
WagnerMoreira / profiling_node_react_app.md
Last active May 26, 2020 15:04
Profiling a server side rendered React APP to look for memory leaks
node --inspect --trace_gc src/server

In another tab

ab -r -k -n 1000 -c 200 -H "user-agent:Googlebot/2.1 (+http://www.googlebot.com/bot.html)" http://localhost:8000/programs
@WagnerMoreira
WagnerMoreira / javascript_currying_functions.js
Last active December 26, 2019 20:36
Javascript Currying Functions Example
// regular version
let dragon = (name, size, element) =>
name + 'is a ' +
size + ' dragon that breathes ' +
element + '!';
//usage // usage dragon('zezinho', 'small', 'ice');
// currying version
const solution = (numbers) => {
// returns zero if no numbers are undefined
if (!numbers.length) {
return 0;
}
const length = numbers.length;
let current, next, largestNumber = 0;
const first = numbers[0];
const last = numbers[length - 1];