Skip to content

Instantly share code, notes, and snippets.

View brunomarks7's full-sized avatar
🏠
Working from home

Bruno Saraiva brunomarks7

🏠
Working from home
View GitHub Profile
@brunomarks7
brunomarks7 / app.js
Last active December 13, 2023 03:38
Newsletter - Unzip, optimize images, replace in files and upload to domain
const fs = require('fs');
const path = require('path');
const AdmZip = require('adm-zip');
const readline = require('readline');
const sharp = require('sharp');
const { exec } = require('child_process');
// Cria uma interface readline
const rl = readline.createInterface({
input: process.stdin,
@brunomarks7
brunomarks7 / delay.js
Created October 4, 2023 19:18
delayed function js
export function delay(min, max) {
const delayTime = Math.floor(Math.random() * (max - min + 1) + min) * 1000;
return new Promise((resolve) => {
setTimeout(resolve, delayTime);
});
}
@brunomarks7
brunomarks7 / gist:2d5b0366c75a3aef4fbc37a211e97c2b
Created September 25, 2022 21:21
Remove webp recursively
#!/bin/bash
CDIR=$(pwd)
for i in $(ls -R | grep :); do
DIR=${i%:}
cd $DIR
rm *.webp
cd $CDIR
done
@brunomarks7
brunomarks7 / install-docker.sh
Created July 16, 2022 00:57
Install Docker and Docker Compose - Amazon Linux 2 instance
#!/bin/bash
yum update -y
amazon-linux-extras install docker -y
service docker start
usermod -a -G docker ec2-user
chkconfig docker on
yum install -y git
curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose version
@brunomarks7
brunomarks7 / index.js
Created July 9, 2022 02:13
Send transactional messages with MessageBird WhatsApp API
const messagebird = require('messagebird')(process.env.MESSAGEBIRD_API_KEY, null, ["ENABLE_CONVERSATIONSAPI_WHATSAPP_SANDBOX"]);
const urlTracker = tracking_code => {
if (tracking_code.slice(0, 2) == 'ME') {
return 'https://melhorrastreio.com.br/rastreio/';
}
return 'https://www.linkcorreios.com.br/';
}
const sendWhatsApp = async function(phone, templateName, params) {
@brunomarks7
brunomarks7 / functions.php
Last active February 13, 2022 02:59
Debug registered names of scripts on wordpress theme queue and dequeue
<?php
# insert above functions for debug
function debug_wp_scripts_on_queue() {
global $wp_scripts;
echo "<h2>Enqueued JS Scripts</h2><ul>";
foreach( $wp_scripts->queue as $handle ) :
echo "<li>" . $handle . "</li>";
endforeach;
echo "</ul>";
}
@brunomarks7
brunomarks7 / validate.js
Created December 25, 2021 02:03
Validate brazilian phone / cellphone by national patterns (regex)
const checkPhonepattern = phone => {
// checa se o telefone é fixo com começo entre 2 e 5
// ou celular com 9 dig e começo entre 6 e 9
if ( (/^(?:(55\d{2})|\d{2})[2-5]\d{7}$/.test(phone)) || (/^(?:(55\d{2})|\d{2})[6-9]\d{8}$/.test(phone))) {
return true;
}else {
return false;
}
};
@brunomarks7
brunomarks7 / Dockerfile
Last active October 19, 2021 04:07
CWEBP - Convert all png images to webp recursively
FROM nginx
LABEL maintainer="brunomarks@gmail.com"
COPY /images /usr/share/nginx/html
RUN apt update && apt install -y curl
RUN curl -O https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-0.4.1-linux-x86-64.tar.gz
@brunomarks7
brunomarks7 / tinyerp-ocultar-cpf-nfe-formato-etiqueta.js
Last active July 29, 2021 04:39
Script para ser usado com extensão do Chrome Tampermonkey para remover CPF de clientes em NFes no formato etiqueta, no TinyERP, em função do LGPD
// ==UserScript==
// @name TinyERP - Remove CPF do cliente em NF em formato etiqueta
// @namespace http://tampermonkey.net/
// @version 0.1
// @author https://github.com/brunomarks7
// @match *://erp.tiny.com.br/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function () {
@brunomarks7
brunomarks7 / wp-permissions.sh
Created April 19, 2021 03:39
Docker WordPress-Bitnami image permissions
#!/bin/bash
# Docker WordPress-Bitnami image permissions
sudo chown -R /opt/bitnami/apps/wordpress/htdocs
sudo find /opt/bitnami/apps/wordpress/htdocs -type d -exec chmod 775 {} \;
sudo find /opt/bitnami/apps/wordpress/htdocs -type f -exec chmod 664 {} \;
sudo chmod 640 /opt/bitnami/apps/wordpress/htdocs/wp-config.php