Skip to content

Instantly share code, notes, and snippets.

View javascripto's full-sized avatar
:octocat:
Focusing

Yuri Alves javascripto

:octocat:
Focusing
View GitHub Profile
@javascripto
javascripto / lint-staged.sh
Created June 7, 2020 14:34
Angular lint staged
#!/bin/bash
lint-staged() {
# ng lint --files $(git diff --name-only --cached | tr '\n' ' ')
staged_files=$(git diff --name-only --cached)
staged_files_inline=$(echo $staged_files | tr '\n' ' ')
command="ng lint --files $staged_files_inline"
# if not null
if [ ! -z "$staged_files" ]; then
HTMLFormElement.prototype.serialize = function() {
const formData = new FormData(this);
return Object.fromEntries(formData.entries());
}
class CPF {
static CPF_MASK = '$1.$2.$3-$4';
static CPF_REGEX = /(\d{3})(\d{3})(\d{3})(\d{2})/;
static generateFormated(): string {
return this.format(this.generate());
}
static format(cpf: string): string {
return cpf.replace(this.CPF_REGEX, this.CPF_MASK);
function $(selector) {
const el = document.querySelector(selector);
return ({
html: () => el,
hide: () => el.hidden = true,
show: () => el.hidden = false,
on: (event, callback) => el.addEventListener(event, callback),
attr: (name, value) => value ? el.setAttribute(name, value) : el.getAttribute(name),
});
}
@javascripto
javascripto / template-parcel-react-ts-scss-pug.sh
Last active May 12, 2020 02:15
Template react|scss|pug com parcel bundler
#!/usr/bin/env sh
mkdir src
cat << STYLE > src/style.scss
h1 {
color: blue;
}
STYLE
@javascripto
javascripto / package.json
Created April 13, 2020 15:07
JSON Server fake backend
{
"name": "json-db",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"postinstall": "if [ ! -f db.json ]; then echo '{\n \"products\": []\n}' > db.json; fi",
"start": "json-server --watch db.json --port 3001"
},
"keywords": [],
// Retorna o valor com desconto de 10%
function valorDescontado(valorBruto) {
  let desconto = 0.1;
  console.log(`Calculando desconto de ${desconto}`);
  return valorBruto * (1 - desconto);
}
@javascripto
javascripto / dica.md
Last active March 31, 2020 04:49
Como instalar versões diferentes de uma lib no mesmo projeto para usar em lugares diferentes

Instalar versões diferentes de uma lib no mesmo projeto para usar em lugares diferentes

npm install \
    ngx-mask-legacy@npm:ngx-mask@2.9.6 \
    ngx-mask@npm:ngx-mask@8.1.7
import { ... } from 'ngx-mask-legacy'; // nos lugares que já usam
const readline = require('readline');
readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);
process.stdin.on('keypress', (str, key) => {
if (key.ctrl && key.name === 'c') {
process.exit();
}
handleKey(key);