const groupBy = key => array =>
array.reduce((objectsByKeyValue, obj) => {
const value = obj[key];
objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
return objectsByKeyValue;
This file contains hidden or 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
| // 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); |
This file contains hidden or 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
| # 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 | |
This file contains hidden or 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 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; |
This file contains hidden or 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
| #!/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' |
This file contains hidden or 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
| // 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 |
This file contains hidden or 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 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) { |
This file contains hidden or 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
| ## 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 |
This file contains hidden or 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
| // 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){ |