Skip to content

Instantly share code, notes, and snippets.

View petronioamaral's full-sized avatar

Petrônio Amaral petronioamaral

  • Dublin, Ireland
View GitHub Profile
@petronioamaral
petronioamaral / mysql-docker.sh
Created November 18, 2019 12:23
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
var hours = 24; // Reset when storage is more than 24hours
var now = new Date().getTime();
var setupTime = localStorage.getItem('setupTime');
if (setupTime == null) {
localStorage.setItem('setupTime', now)
} else {
if(now-setupTime > hours*60*60*1000) {
localStorage.clear()
localStorage.setItem('setupTime', now);
}
DROP FUNCTION IF EXISTS fn_remove_accents;
DELIMITER |
CREATE FUNCTION fn_remove_accents( textvalue VARCHAR(10000) ) RETURNS VARCHAR(10000)

BEGIN

    SET @textvalue = textvalue;

    -- ACCENTS
DROP PROCEDURE IF EXISTS dorepeat

CREATE PROCEDURE dorepeat()
BEGIN
DECLARE someId INT;
DECLARE city CHAR(50);
DECLARE done INT DEFAULT FALSE;
DECLARE cur1 CURSOR FOR select id_cidade,cidade from cepbr_cidade ;
@petronioamaral
petronioamaral / procedure_cursor_update.md
Created August 5, 2020 14:57
procedure mysql update with cursor
DROP PROCEDURE IF EXISTS dorepeat

CREATE PROCEDURE dorepeat()
BEGIN
DECLARE someId INT;
DECLARE neighborhood LONGTEXT;
DECLARE done INT DEFAULT FALSE;
DECLARE cur1 CURSOR FOR select id_bairro,bairro from cepbr_bairro ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; 
@petronioamaral
petronioamaral / removeItemArray.md
Created August 7, 2020 20:14
remove item array javascript
<script>

 bairroSelecionadosArray = bairroSelecionadosArray.filter(function(el){
                return el.id !== id;
                });
                
</script>
@petronioamaral
petronioamaral / remove_accents.md
Created August 13, 2020 19:03
remove accents php
  public function removerAcentos($str){
        $str = preg_replace('/[áàãâä]/ui', 'a', $str);
        $str = preg_replace('/[éèêë]/ui', 'e', $str);
        $str = preg_replace('/[íìîï]/ui', 'i', $str);
        $str = preg_replace('/[óòõôö]/ui', 'o', $str);
        $str = preg_replace('/[úùûü]/ui', 'u', $str);
        $str = preg_replace('/[ç]/ui', 'c', $str);
        $str = preg_replace('/[^a-z0-9]/i', ' ', $str);
 // $str = preg_replace('/_+/', ' ', $str);
@petronioamaral
petronioamaral / remove_accents_keep_hifen.md
Created August 19, 2020 16:17
remove accents keep hifen php function
  public function removerAcentos($str){
        $str = preg_replace('/[áàãâä]/ui', 'a', $str);
        $str = preg_replace('/[éèêë]/ui', 'e', $str);
        $str = preg_replace('/[íìîï]/ui', 'i', $str);
        $str = preg_replace('/[óòõôö]/ui', 'o', $str);
        $str = preg_replace('/[úùûü]/ui', 'u', $str);
        $str = preg_replace('/[ç]/ui', 'c', $str);
        $str = preg_replace('/[^a-z0-9-]/i', ' ', $str);
 // $str = preg_replace('/_+/', ' ', $str);
@petronioamaral
petronioamaral / gist:27b1db1243a805a160007908b73e3112
Last active August 19, 2020 20:05
change IP accounts vestacp, migrate server
We couldn’t find that file to show.
@petronioamaral
petronioamaral / changeIPvestacp.md
Created August 19, 2020 20:05
change IP vestacp migrate server
OLDIPV4='' # enter here
NEWIPV4=$(curl -s vestacp.com/what-is-my-ip/)

grep -rl "$OLDIPV4" /etc | xargs sed -i "s#$OLDIPV4#$NEWIPV4#g"
find /home/*/conf/ -type f -exec sed -i "s#$OLDIPV4#$NEWIPV4#g" {} \;
mv /usr/local/vesta/data/ips/$OLDIPV4 /usr/local/vesta/data/ips/$NEWIPV4
mv /etc/apache2/conf.d/$OLDIPV4.conf /etc/apache2/conf.d/$NEWIPV4.conf
mv /etc/nginx/conf.d/$OLDIPV4.conf /etc/nginx/conf.d/$NEWIPV4.conf
grep -rl "$OLDIPV4" /usr/local/vesta/data | xargs sed -i "s#$OLDIPV4#$NEWIPV4#g"