Arquivos

Aqui aparecem os posts dos arquivos selecionados.

Arquivos do mês: março 2016

Instalando o Apache2, PHP5, MySQL, PHPMyAdmin no Ubuntu 12.04

Olá,

Para iniciar vamos fazer um update das listas de aplicativos com o comando:

apt-get update

Em seguida vamos instalar o apache2

apt-get install apache2

Agora vamos instalar o PHP5 (PHP5 é a versão. Esse é o php que você conhece)

apt-get install php5

É bom instalar também algumas bibliotecas úteis do PHP, pois cedo ou tarde será necessário.

apt-get install php5-mhash php5-mcrypt php5-curl php5-cli php5-mysql php5-gd

Agora vamos instalar o MySQL

apt-get install mysql-server mysql-client

Falta pouco agora.

O Web Server já está basicamente pronto, mas seria bom adicionar um gerenciador para o banco de dados.

Para isso vamos instalar o PHPMyAdmin com o comando:

apt-get install phpmyadmin

Agora precisamos que o apache rode o phpmyadmin.

Para isso use o comando:

echo "Include /etc/phpmyadmin/apache.conf" >> /etc/apache2/apache2.conf

Ou se preferir, edite o arquivo com o editor do debian e insira a linha manualmente.

Agora basta reiniciar o apache2 para que tudo esteja pronto para funcionar.

service apache2 restart

MySQL Optimize todas as tabelas

Olá,

no seu phpmyadmin insira o código abaixo:

SET SESSION group_concat_max_len = 99999999;
SELECT GROUP_CONCAT(concat('OPTIMIZE TABLE `', table_name, '`;') SEPARATOR '') AS O
FROM INFORMATION_SCHEMA.TABLES WHERE 
TABLE_TYPE = 'BASE TABLE'
AND table_name != 'dual'
AND TABLE_SCHEMA = '<nome do seu banco de dados>'

Após só rodar e aguardar.

Javascript + JQuery: Verificador se usuário terminou de digitar

Olá,

Você já precisou de chamar uma função apenas quando o usuário termine de digitar todo o texto ?

O jQuery possui algumas funções interessantes, mas que sozinhas não tem o efeito que precisamos.

Existem algumas formas de fazer isso, abaixo o código de uma delas e como utilizar.

(function ($) {
    $.fn.extend({
        donetyping: function (callback, timeout) {
            timeout = timeout || 1e3; // 1 second default timeout
            var timeoutReference,
                    doneTyping = function (el) {
                        if (!timeoutReference)
                            return;
                        timeoutReference = null;
                        callback.call(el);
                    };
            return this.each(function (i, el) {
                var $el = $(el);
                // Chrome Fix (Use keyup over keypress to detect backspace)
                // thank you @palerdot
                $el.is(':input') && $el.on('keyup keypress', function (e) {
                    // This catches the backspace button in chrome, but also prevents
                    // the event from triggering too premptively. Without this line,
                    // using tab/shift+tab will make the focused element fire the callback.
                    if (e.type == 'keyup' && e.keyCode != 8)
                        return;

                    // Check if timeout has been set. If it has, "reset" the clock and
                    // start over again.
                    if (timeoutReference)
                        clearTimeout(timeoutReference);
                    timeoutReference = setTimeout(function () {
                        // if we made it here, our timeout has elapsed. Fire the
                        // callback
                        doneTyping(el);
                    }, timeout);
                }).on('blur', function () {
                    // If we can, fire the event since we're leaving the field
                    doneTyping(el);
                });
            });
        }
    });
})(jQuery);

Como utilizar a função?

$('#exemplo').donetyping(function(){
  $('#exemplo-output').text('Event last fired @ ' + (new Date().toUTCString()));
});

Segue funcionando no JSFIddle