Skip to content

Instantly share code, notes, and snippets.

View LucasCalazans's full-sized avatar
:octocat:
jQuery > JS

Lucas Calazans LucasCalazans

:octocat:
jQuery > JS
View GitHub Profile
@LucasCalazans
LucasCalazans / hooks-comparation.jsx
Last active March 17, 2023 13:27
Comparation with React Hooks
// Usando classe
class Counter extends Component {
state = {
counter: 1,
}
incrementCounter = () => {
this.setState(({ counter }) => ({ counter: counter + 1 }));
};
@LucasCalazans
LucasCalazans / usememo-form.jsx
Last active March 3, 2022 22:45
Form validation using useMemo
const CreateAccountForm = () => {
const [password, setPassword] = useState('');
const [showErrors, setShowErrors] = useState(false);
const checkPassword = event => {
const { value } = event.target;
setShowErrors(value.length < 8);
setPassword(value);
}
@LucasCalazans
LucasCalazans / usememo-example.js
Last active April 22, 2022 20:22
useMemo example
const categories = useMemo(() => {
return products.reduce((categories, { category }) => {
return !category || categories.find(({ id }) => category && category.id === id)
? categories
: [
...categories,
{
id: category.id,
value: category.id,
label: category.title,
@LucasCalazans
LucasCalazans / index.html
Created June 3, 2019 13:38
App Shell - Initial index.html
<!DOCTYPE html>
<html lang="pt-br">
<head>
<title>App</title>
<meta name="Description" content="Best application ever" />
<meta charset="utf-8" />
<meta name="theme-color" content="#333333" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<link rel="shortcut icon" href="/favicon.ico" />
</head>
@LucasCalazans
LucasCalazans / app-shell.html
Last active June 11, 2019 02:51
HTML to exemplify a simple usage of the app shell
<!DOCTYPE html>
<html lang="pt-br">
<head>
<title>App</title>
<meta name="Description" content="Best application ever" />
<meta charset="utf-8" />
<meta name="theme-color" content="#333333" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<link rel="shortcut icon" href="/favicon.ico" />
</head>
@LucasCalazans
LucasCalazans / ws-config.js
Created June 17, 2019 14:39
Add alias to WebStorm/PHPStorm
System.config({
"paths": {
"@/*": "./src/*"
}
});
@LucasCalazans
LucasCalazans / .bashrc
Created June 17, 2019 16:31
Add git branch to terminal line
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
PS1='[\u@\h \W]$(parse_git_branch)\$ '
@LucasCalazans
LucasCalazans / exec.sh
Last active July 19, 2019 16:26
Execute a PHP command with a docker container
#!/bin/bash
PID=$(id -u $USER);
GID=$(id -g $USER);
mkdir -p ~/.composer/cache;
docker run --rm \
-v $(pwd):/app \
-v ~/.composer/cache:/var/www/.composer/cache \
@LucasCalazans
LucasCalazans / create-magento-project.sh
Last active August 2, 2019 16:32
Create a Magento 2 Project based on Magento Cloud repository
#!/usr/bin/env bash
#####################################################
# #
# SYSTEM VALIDATION #
# #
#####################################################
#####################################################
@LucasCalazans
LucasCalazans / routes.yaml
Last active March 31, 2022 16:15
Magento Cloud - Redirect customer pages to home
# The routes of the project.
#
# Each route describes how an incoming URL is going to be processed.
"http://{all}/":
type: upstream
upstream: "mymagento:http"
redirects:
paths:
"^/customer/account/forgotpassword/.*": { to: "http://{all}/", regexp: true }