Skip to content

Instantly share code, notes, and snippets.

View fernandosavio's full-sized avatar

Fernando Sávio fernandosavio

View GitHub Profile
@fernandosavio
fernandosavio / formatcurrency.js
Created August 28, 2012 14:12
Format currency or just input milliar and decimal delimiters
//standalo ie9+ code
/**
* @param v Number Number to be formatted
* @param m String Milliar delimitter. Default: '.' (pt-br).
* @param d String Decimal delimitter. Default: ',' (pt-br).
* @return String Formatted number
*/
function formatCurrency(v,m,d){
var r = v.toFixed(2).split(/\.|-/),
m = m || '.',
@fernandosavio
fernandosavio / scroller.js
Last active September 26, 2018 14:49
Markup Scroller
/**
* === Scroller ===
* Basta adicionar a classe "scroller" para algum elemento e atribuir o seletor ao atributo href ou data-target;
* Exemplos:
* <a href="#wrapper" class="scroller">Topo</a>
* <span class="scroller" data-target="#wrapper">Topo</span>
*/
jQuery(document).ready(function(){
var screen = $('html, window, body'),
regex = /.*(?=#[^\s]+$)/; //strip for ie7
@fernandosavio
fernandosavio / jQuery-decimalFormat.js
Created October 30, 2012 21:34
Plugin jQuery para formatação de inputs
// the semi-colon before function invocation is a safety net against concatenated
// scripts and/or other plugins which may not be closed properly.
;(function ( $, window, undefined ) {
// undefined is used here as the undefined global variable in ECMAScript 3 is
// mutable (ie. it can be changed by someone else). undefined isn't really being
// passed in so we can ensure the value of it is truly undefined. In ES5, undefined
// can no longer be modified.
// window and document are passed through as local variables rather than globals
@fernandosavio
fernandosavio / html(encode_decode).js
Last active April 16, 2020 05:47
HTML encode decode (Pure Javascript)
function html_decode(text){
var div = document.createElement("div");
div.innerHTML = text;
return ("textContent" in div) ? div.textContent : div.innerText ;
}
function html_encode(str){
var div = document.createElement("div");
div[("textContent" in div) ? "textContent" : "innerText"] = str;
return div.innerHTML;
@fernandosavio
fernandosavio / pagination.php
Created May 25, 2013 00:43
Script que retorna um range do números das páginas baseado nos parâmetros recebidos.
<?php
function pagination ($index, $teto, $amplitude = 7, $piso = 1){
$padding = intval($amplitude/2);
$amplitude = min(array($amplitude,$teto));
$left = $padding;
$right = $amplitude - $left - 1;
if($index - $padding < $piso){
$left = $index - $piso;
$right = $amplitude - ($left + 1);
@fernandosavio
fernandosavio / cidades-brasil.json
Last active April 8, 2018 06:04
JSON com as cidades brasileira segundo o IBGE.
{
"Acre": ["Acrel\u00e2ndia","Assis Brasil","Brasil\u00e9ia","Bujari","Capixaba","Cruzeiro do Sul","Epitaciol\u00e2ndia","Feij\u00f3","Jord\u00e3o","M\u00e2ncio Lima","Manoel Urbano","Marechal Thaumaturgo","Pl\u00e1cido de Castro","Porto Acre","Porto Walter","Rio Branco","Rodrigues Alves","Santa Rosa do Purus","Sena Madureira","Senador Guiomard","Tarauac\u00e1","Xapuri"],
"Alagoas": ["\u00c1gua Branca","Anadia","Arapiraca","Atalaia","Barra de Santo Ant\u00f4nio","Barra de S\u00e3o Miguel","Batalha","Bel\u00e9m","Belo Monte","Boca da Mata","Branquinha","Cacimbinhas","Cajueiro","Campestre","Campo Alegre","Campo Grande","Canapi","Capela","Carneiros","Ch\u00e3 Preta","Coit\u00e9 do N\u00f3ia","Col\u00f4nia Leopoldina","Coqueiro Seco","Coruripe","Cra\u00edbas","Delmiro Gouveia","Dois Riachos","Estrela de Alagoas","Feira Grande","Feliz Deserto","Flexeiras","Girau do Ponciano","Ibateguara","Igaci","Igreja Nova","Inhapi","Jacar\u00e9 dos Homens","Jacu\u00edpe","Japaratinga","Jaramataia","Jequi\u00e1 da Praia","Jo
@fernandosavio
fernandosavio / delayedForEach.js
Last active May 30, 2022 06:44
An Array forEach with a delay between steps.
/**
* An array forEach with a delay between steps.
*
* @param {Function} callback Function to execute for each element. It receives three arguments, the element value, the element index and the array being traversed, respectivily.
* @param {Number} timeout Number of milliseconds that the function call should be delayed by.
* @param {Object} thisArg Object to use as this when executing callback.
* @this {Array}
* @return {undefined}
*/
Array.prototype.delayedForEach = function(callback, timeout, thisArg){
@fernandosavio
fernandosavio / validate-date.js
Last active December 22, 2015 18:49
Validação de data
function validateDate(data){
var p = data.split("/"),
isNumber = /^\d{1,2}\/\d{1,2}\/\d{4}$/,
date = new Date(+p[2], +p[1] -1 , +p[0]); // dd/mm/yyy
return isNumber.test(data) && !(date.getDate() !== +p[0] || date.getMonth() !== (+p[1] - 1) || date.getFullYear() !== +p[2]);
};
@fernandosavio
fernandosavio / converter.py
Created January 28, 2014 19:37
Script de conversão de vídeos usando `python`, `ffmpeg` e o módulo `argparse` para tratar dos argumentos recebidos por terminal.
#!/usr/bin/env python
# -*- coding: utf8 -*-
import argparse, re
from os import path, getcwd, mkdir, listdir, devnull
from subprocess import Popen
# valida se 'string' segue o padrão de resolução de tela. 9999x9999 ou 9999X9999
def isScreenSize(string):
regex = re.compile(r"^\d+x\d+$", re.IGNORECASE)
@fernandosavio
fernandosavio / bubble_sort.php
Last active August 29, 2015 13:56
Bubble Sort implementado em PHP com flag se o array já estiver ordenado
<?php
/**
* Bubble Sort implementado em PHP com flag se o array já estiver ordenado
*/
function bubble_sort($arr) {
$flag = false;
while(!$flag) {
$flag = true;
for ($i=1; $i < count($arr); $i++) {