Skip to content

Instantly share code, notes, and snippets.

View netojoaobatista's full-sized avatar
💭
GitHub is not Orkut.

João Batista Neto netojoaobatista

💭
GitHub is not Orkut.
View GitHub Profile
@netojoaobatista
netojoaobatista / Date.prototype.diff.js
Created April 26, 2012 20:09
Returns the difference between two Date objects.
Object.defineProperty(Date.prototype,"diff",{
writable: false, configurable: false, enumerable: true,
/**
* Returns the difference between two Date objects.
* @param {Date} The date to compare to.
* @return {Object}
* @throws {TypeError}
*/
value: function(date) {
@netojoaobatista
netojoaobatista / String.prototype.soundex.js
Created March 22, 2012 18:00
Implementação do algorítimo SoundEX em Javascript
/**
* Implementação do algorítimo SoundEx em Javascript.
* @author João Batista Neto
*
* SoundEX é um algorítimo fonético para indexação de nomes pelo som segundo
* sua pronúncia. O algorítimo foi desenvolvido por Robert C. Russell e
* Margaret K. Odell e patenteado em 1918 e 1922.
* {@link http://en.wikipedia.org/wiki/Soundex}
*
* @return {String}
@netojoaobatista
netojoaobatista / wp_comments.sql
Created August 14, 2012 19:18
Número de comentários em posts, agrupado pela categoria. E o número de comentário no período anterior
SET @startDate=DATE("2012-07-01");
SET @endDate:=DATE("2012-07-31");
SET @diff:=@diff:=DATEDIFF(@startDate, @endDate);
SET @previousStartDate:=ADDDATE(@startDate, @diff);
SET @previousEndDate:=ADDDATE(@endDate, @diff);
SELECT
@startDate AS `currentStartDate`,
@endDate AS `currentEndDate`,
@previousStartDate AS `previousStartDate`,
@netojoaobatista
netojoaobatista / php.sh
Created January 25, 2013 14:10
Template para criação de um inicializador de serviços
#!/bin/bash
prog=php
#função para iniciar o serviço
start() {
echo -n $"iniciando $prog..."
# aqui o código para iniciar alguma coisa, por exemplo:
php -S localhost:8080 >php_log &
}
@netojoaobatista
netojoaobatista / php.doc.sh
Created February 19, 2013 22:03
Simple RSS2JSON using XSLT
#!/bin/sh
curl -s "http://news.php.net/group.php?group=php.doc&format=rss" |xsltproc rss2json.xsl /dev/stdin |json_reformat
#!/bin/bash
ICONV="iconv -f UTF-8 -t ISO-8859-1"
find $1 -type f -iname "*.html" | while read fn; do
cp ${fn} ${fn}.utf8
$ICONV < ${fn}.utf8 > ${fn}
rm ${fn}.utf8
done
Number.prototype.$toFixed = Number.prototype.toFixed;
Number.prototype.toFixed = function(x) {
return (Math.floor(this * Math.pow(10, x)) / Math.pow(10, x)).$toFixed(x);
};
print((22.315).toFixed(2)); //22.31
print((49.995).toFixed(2)); //49.99
@netojoaobatista
netojoaobatista / gitcowsay.sh
Last active January 4, 2021 18:58
Random commit messages
git config --global alias.cowsay '!git commit -m "`fortune | cowsay -f tux`"'
@netojoaobatista
netojoaobatista / gist:2784286
Created May 24, 2012 21:17
Validação usando expressão regular para aceitar apenas letras minúsculas
<?php
/**
* Verifica se uma string é UTF-8
* @param string $string A string que será verificada
* @return boolean
*/
function is_utf8($string) {
return (bool) preg_match('%^(?:'.
'[\x09\x0A\x0D\x20-\x7E]|'.
'[\xC2-\xDF][\x80-\xBF]|'.
@netojoaobatista
netojoaobatista / cielo.sh
Last active November 4, 2020 12:30
Instalação dos certificados Cielo em servidores Linux
#!/bin/bash
if [ $EUID != 0 ]; then
echo 'Você precisa ser root para instalar certificados.'
exit $?
fi
# Diretório onde os certificados serão instalados
cert_path=`openssl version -d|sed 's/.*\"\(.*\)\"/\1/g'`/certs
# Path para o certificado da Cielo