Skip to content

Instantly share code, notes, and snippets.

View webarthur's full-sized avatar
✌️

Arthur Ronconi webarthur

✌️
View GitHub Profile
@webarthur
webarthur / load-prism-highlight.js
Created July 7, 2023 03:14
Manually load Prism.js for syntax highlighting after the DOM has loaded. Force to highlight javascript syntax.
// Set the manual property of Prism object to true
window.Prism = { manual: true }
// Add an event listener for when the window is loaded
window.addEventListener('load', () => {
// Import the Prism.js library from the specified URL
import('https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/prism.min.js')
.then(() => {
console.log('Prism loaded.')
@webarthur
webarthur / .xbindkeysrc
Created November 29, 2022 16:54
xbindkeys configuration
###########################
# xbindkeys configuration #
###########################
#
# Version: 0.1.3
#
# If you edit this, do not forget to uncomment any lines that you change.
# The pound(#) symbol may be used anywhere for comments.
#
# A list of keys is in /usr/include/X11/keysym.h and in
@webarthur
webarthur / get_youtube_channel_ID.php
Created April 11, 2016 21:46
Get youtube Channel ID by channel url
<?php
function get_youtube_channel_ID($url){
$html = file_get_contents($url);
preg_match("'<meta itemprop=\"channelId\" content=\"(.*?)\"'si", $html, $match);
if($match && $match[1]);
return $match[1];
}
@webarthur
webarthur / my-snippets.code-snippets
Created May 3, 2022 17:59
VS Code JavaScript snippets
{
"<router-link>": {
"scope": "html",
"prefix": ["rt", "rou", "rout"],
"body": [
"<router-link to=\"$1\">$2</router-link>"
],
},
@webarthur
webarthur / fixOfxData.js
Created July 22, 2021 16:04
Fix OFX unclosed tags
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>')
}
}
@webarthur
webarthur / getQueryParams.js
Created March 22, 2021 10:52
Função para ler os parâmetros da URL em JavaScript
// 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]
})
@webarthur
webarthur / getQueryParam.js
Created March 22, 2021 10:41
Função para ler os parâmetros GET da URL em JavaScript
// 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
@webarthur
webarthur / validaCPF.js
Last active March 21, 2021 20:41
Função JavaScript para validar CPF
function validaCPF(cpf) {
var Soma = 0
var Resto
var strCPF = String(cpf).replace(/[^\d]/g, '')
if (strCPF.length !== 11)
return false
if ([
@webarthur
webarthur / async-highlight-js.html
Created March 11, 2021 22:06
Load highlight.js asynchronously
<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>
@webarthur
webarthur / wp-svg-inline.php
Created March 10, 2021 12:36
Function to replace SVG images to inline SVG code (WordPress)
<?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);