Skip to content

Instantly share code, notes, and snippets.

View ricardoriogo's full-sized avatar

Ricardo Riogo ricardoriogo

View GitHub Profile
@ricardoriogo
ricardoriogo / number_format.js
Created December 6, 2012 18:39
Javascript version of php number_format function
function number_format (number, decimals, dec_point, thousands_sep) {
// http://kevin.vanzonneveld.net
// + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfix by: Michael White (http://getsprink.com)
// + bugfix by: Benjamin Lupton
// + bugfix by: Allan Jensen (http://www.winternet.no)
// + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// + bugfix by: Howard Yeend
// + revised by: Luke Smith (http://lucassmith.name)
@ricardoriogo
ricardoriogo / jquery.validate.cpf.js
Last active October 11, 2016 18:26
CPF validation for jQuery Validate
jQuery.validator.addMethod("cpf", function(value, element) {
value = value.replace('.','');
value = value.replace('.','');
cpf = value.replace('-','');
while(cpf.length < 11) cpf = "0" + cpf;
var expReg = /^0+$|^1+$|^2+$|^3+$|^4+$|^5+$|^6+$|^7+$|^8+$|^9+$/;
var a = [];
var b = new Number;
var c = 11;
for (i=0; i<11; i++){
@ricardoriogo
ricardoriogo / jquery.validate.cnpj.js
Last active April 20, 2017 13:40
CNPJ validation for jQuery Validate
jQuery.validator.addMethod("cnpj", function(cnpj, element) {
var numeros, digitos, soma, resultado, pos, tamanho,
digitos_iguais = true;
if (cnpj.length < 14 && cnpj.length > 15)
return false;
for (var i = 0; i < cnpj.length - 1; i++)
if (cnpj.charAt(i) != cnpj.charAt(i + 1)) {
@ricardoriogo
ricardoriogo / slugify.js
Created February 13, 2013 01:59
Slugify: Remove acentos e caracteres não permitidos em urls, substitui espaços, underlines e caracteres não alfanuméricos por hífen.
String.prototype.slugify = function(){
return (this)
.replace(/[ÁÀÂÃÄ]/gi, 'a')
.replace(/[ÉÈÊË]/gi, 'e')
.replace(/[ÍÌÎÏ]/gi, 'i')
.replace(/[ÓÒÔÕÖ]/gi, 'o')
.replace(/[ÚÙÛÜ]/gi, 'u')
.replace(/[Ç]/gi, 'c')
.toLowerCase() // change everything to lowercase
.replace(/^\s+|\s+$/g, '') // trim leading and trailing spaces
@ricardoriogo
ricardoriogo / .htaccess
Created May 19, 2013 00:57
Meu .htaccess para uso com o CodeIgniter.
# Gzip compression
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript
</ifmodule>
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
@ricardoriogo
ricardoriogo / httpd.conf
Created May 29, 2013 02:12
Como carregar configurações externas no apache. No exemplo abaixo carregará todos os arquivos com a extensão .conf (configurações virtual hosts) da pasta sites.
NameVirtualHost *:80
Include "conf/sites/*.conf"
@ricardoriogo
ricardoriogo / gist:5667532
Last active December 17, 2015 20:29
Configuração exemplo vHost.
<VirtualHost *:80>
ServerName site.dev
DocumentRoot "D:\pasta_root"
</VirtualHost>
<Directory "D:\pasta_root">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
@ricardoriogo
ricardoriogo / gist:5674132
Last active December 17, 2015 21:19
Exemplo de configuração .sublime-project
{
"folders":
[
{
"path": "www"
}
],
"build_systems":
[
@ricardoriogo
ricardoriogo / web.config.xml
Created June 3, 2013 23:02
Exemplo de web.config rewrite
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Clean URL" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
############################################
## Fonts Support - for Apache Server ##
############################################
<FilesMatch "\.(ttf|otf|eot|woff|font.css)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
# webfont mime types