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 / 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 / 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 / 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 / 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 / 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 / no-usememo-form.js
Last active May 28, 2019 19:02
Form validation without useMemo
const rules = [
'8 characteres',
'lowercase word',
'uppercase word',
];
// Lista de erros
const Errors = ({ active }) => {
return active && (
<ul>
# Editor configuration, see https://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
@LucasCalazans
LucasCalazans / Action.php
Last active August 1, 2018 22:55
Simulate Magento messages, useful to front-enders.
<?php
// Edit the follow file: vendor/magento/framework/App/Action/Action.php
public function __construct(Context $context)
{
// ... //
$this->messageManager->addError(__('Error message.'));
$this->messageManager->addSuccessMessage(__('Success message.'));
$this->messageManager->addWarning(__('Warning message.'));
}
@LucasCalazans
LucasCalazans / Success.php
Last active July 24, 2018 14:03
Changing this file will give the possibility of update many times the success page, useful to front-enders.
<?php
// vendor/magento/module-checkout/Controller/Onepage/Success.php
// or app/code/Magento/Checkout/Controller/Onepage/Success.php
// Comment the follow line
$session->clearQuote();
@LucasCalazans
LucasCalazans / browser.js
Last active May 11, 2020 20:16
Force Magento 2 to update the js-translation.json when some .csv is changed
// Run this code on your browser console
localStorage.removeItem("mage-translation-file-version")