Skip to content

Instantly share code, notes, and snippets.

View fernandosavio's full-sized avatar

Fernando Sávio fernandosavio

View GitHub Profile
@fernandosavio
fernandosavio / striptags.js
Created August 4, 2017 22:04
Simple regex-based strip_tags in Javascript
/*
regex example(strips 'i' and 'em' tags): /(<(?!\/?em|\/?i).*?>)/ig
*/
/**
* @param string html
* @param string allowed_tags space-separated allowed tags
*/
function strip_tags(html, allowed_tags){
allowed_tags = allowed_tags.trim()
@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 / pt-br.js
Created September 1, 2014 13:09
Locale pt-br of Moment.js
// moment.js locale configuration
// locale : brazilian portuguese (pt-br)
// author : Caio Ribeiro Pereira : https://github.com/caio-ribeiro-pereira
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['moment'], factory); // AMD
} else if (typeof exports === 'object') {
module.exports = factory(require('../moment')); // Node
} else {
@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 / Gabarito Prova C.md
Last active October 21, 2021 20:51
Responde e explicando a prova do site http://www.cprogressivo.net/2013/03/Questoes-com-gabarito-sobre-Ponteiros-em-C.html (O que eu souber, é claro)
<?php
class Gtin
{
/**
* Testa se a string é um GTIN válido nos seguintes termos:
* - É uma string
* - Contém apenas dígitos numéricos
* - Possui 8, 12, 13 ou 14 dígitos
*
import socket, subprocess
def connect():
ip = "192.168.0.100"
port = 6000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while True:
command = s.recv(1024)
@fernandosavio
fernandosavio / _ingredientes-ativos-agrofit-scraping.md
Last active July 9, 2021 18:29
Scraping do site do governo, Agrofit, com programação síncrona e assíncrona utilizando corrotinas e asyncio.queue no python 3.6.

python 3.6

Raspagem de dados Agrofit

Foram feitos 2 scripts para a raspagem de dados. Um síncrono e outro assíncrono.

  • Síncrono: foram utilizadas as bibliotecas [requests] e [BeautifulSoup];
  • Assíncrono: foram utilizadas as bibliotecas [aiohttp], [BeautifulSoup] e [asyncio] ([corrotinas] e [filas]).

Dados raspados

@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 / 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