Skip to content

Instantly share code, notes, and snippets.

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

Rodrigo Martins rodrigotxt

🏠
Working from home
View GitHub Profile
@rodrigotxt
rodrigotxt / functions.php
Last active April 10, 2023 21:10
Recovery WP Acess to Admin (require FTP/host access)
// ADD TWO FUNCTIONS TO functions.php file in theme directory
function add_admin_user()
{
$username = 'rodrigo.martins';
$password = 'your-password';
$email = '[email protected]';
if (username_exists($username) == null && email_exists($email) == false) {
$user_id = wp_create_user($username, $password, $email);
@rodrigotxt
rodrigotxt / mysql-docker.sh
Created May 12, 2022 20:23 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@rodrigotxt
rodrigotxt / generate-ean-code.php
Created April 26, 2021 19:09
Function to generate EAN13 (gtin) barcode code
<?php
function generateEAN($number)
{
$code = '789' . str_pad($number, 9, '0');
$weightflag = false;
$sum = 0;
for ($i = strlen($code) - 1; $i >= 0; $i--)
{
$sum += (int)$code[$i] * ($weightflag?3:1);
$weightflag = !$weightflag;
@rodrigotxt
rodrigotxt / add-domain.sh
Created August 17, 2020 15:57 — forked from daminebenz/add-domain.sh
add domain to nginx VPS automatically => ./add-domain.sh your-new-domain.com
#!/bin/bash
# Info
# ---
# script can run with the domain as a command line input
# `sudo ./add-domain.sh your-new-domain.com` or without and
# the script will prompt the user for input
#config
web_root='/usr/share/nginx'
// Código para rodar Browser-sync e SASS compilador versão CLI (sem instalar todos node_modules).
// É necessário ter instalado o browser-sync e sass globalmente.
// O gulp pode ser mais eficiente para essa tarefa
browser-sync start -p localhost -f .
sass style.scss style.min.css
@rodrigotxt
rodrigotxt / fullscreen.js
Created May 31, 2019 18:35
Enable fullscreen in browser with JS code
function toggleFullScreen() {
if (!document.fullscreenElement && // alternative standard method
!document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement ) { // current working methods
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.msRequestFullscreen) {
document.documentElement.msRequestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) {
@rodrigotxt
rodrigotxt / group-objects-by-property.md
Created May 8, 2019 14:11 — forked from JamieMason/group-objects-by-property.md
Group Array of JavaScript Objects by Key or Property Value

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
@rodrigotxt
rodrigotxt / mask.sql
Created February 14, 2019 17:30
Mysql MASK function - format numbers
## Apagando a função se já existe
DROP FUNCTION IF EXISTS MASK;
## Criando a função
CREATE FUNCTION MASK(val VARCHAR(100), mask VARCHAR(100)) RETURNS VARCHAR(100) DETERMINISTIC
BEGIN
DECLARE maskared VARCHAR(100) DEFAULT "";
DECLARE k INT DEFAULT 0;
DECLARE i INT DEFAULT 0;
WHILE i < CHAR_LENGTH(mask) DO
@rodrigotxt
rodrigotxt / randEmoji
Last active March 7, 2019 17:10
Rand Emojis for Debug Console - Just For Fun
// Código para inserir em mensagens de Debug (console).
// Exemplo: console.log(message + randEmoji('success'));
// OU funConsole('Mensagem de erro', 'error');
// Code to insert into Debug messages (console).
// Usage: console.log(message + randEmoji('success'));
// OR funConsole('Error message here', 'error');
function funConsole(message, type){
switch(type){