This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fixOfxData (ofx) { | |
const lines = ofxData.split(/[\n\r]/) | |
const reUnclosedTag = /(^[^<]*<(.+)>[^>]+$)/ | |
// Fix unclosed tags line by line | |
for (var i=0; i<lines.length; i++) { | |
if (reUnclosedTag.test(lines[i].trim())) { | |
lines[i] = lines[i].replace(reUnclosedTag, '$1</$2>') | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From: https://devarthur.com/blog/funcao-para-validar-data-em-javascript | |
// Codepen: https://codepen.io/devarthur/pen/vYgBWmv | |
function validaData (valor) { | |
// Verifica se a entrada é uma string | |
if (typeof valor !== 'string') { | |
return false | |
} | |
// Verifica formado da data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validaCNPJ (cnpj) { | |
var b = [ 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 ] | |
var c = String(cnpj).replace(/[^\d]/g, '') | |
if(c.length !== 14) | |
return false | |
if(/0{14}/.test(c)) | |
return false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from https://blog.devarthur.com/javascript/como-ler-os-parametros-da-url-em-javascript/ | |
function getQueryParams (name, query) { | |
var query = location.search.slice(1) | |
var partes = query.split('&') | |
var data = {} | |
partes.forEach(function (parte) { | |
var chaveValor = parte.split('=') | |
data[chaveValor[0]] = chaveValor[1] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from https://blog.devarthur.com/javascript/como-ler-os-parametros-da-url-em-javascript/ | |
function getQueryParam (name, query) { | |
// se o parâmetro query não foi definido pega o parâmetro da URL | |
if (!query) | |
query = window.location.search | |
var l = query.length | |
var n = '' // nome | |
var v = '' // valor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validaCPF(cpf) { | |
var Soma = 0 | |
var Resto | |
var strCPF = String(cpf).replace(/[^\d]/g, '') | |
if (strCPF.length !== 11) | |
return false | |
if ([ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script async src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js"></script> | |
<script> | |
const awaitFor = function (cond, cb, timeout = 100) { | |
!cond() ? setTimeout(() => awaitFor(cond, cb, timeout), timeout) : cb() | |
} | |
awaitFor(() => typeof hljs !== 'undefined', function () { | |
const blocks = document.querySelectorAll('pre code') | |
blocks.forEach(hljs.highlightBlock) | |
}) | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wp_svg_inline_replacer($matches) { | |
$src = $matches[1]; | |
$parts = explode('/wp-content/', $src); | |
$svg = file_get_contents(WP_CONTENT_DIR . '/' . $parts[1]); | |
$svg = preg_replace('/<\?xml.*\?>/', '', $svg); | |
$svg = preg_replace('/<\!DOCTYPE[^>]*>/', '', $svg); | |
return trim($svg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git branch gh-pages | |
git push -u origin gh-pages | |
# Go to the project page | |
# https://[username].github.io/[projectname]/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// exemplo de como seria com VanillaJS | |
// comportamento muda qndo há um await dentro da função | |
// com await funciona de forma assíncrona/paralela, sem await o loop se comporta de maneira síncrona/serial | |
var dados = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
// paralelo | |
// equivalente a async.map() | |
var i = 0 | |
Promise.all(dados.map(async function (item) { |