This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Google Developer Day Quiz | |
# Written by Paulo Freitas <[email protected]>, updated for modern Python | |
class GooglonLexer(object): | |
def __init__(self, text: str) -> None: | |
self.words = text.split(' ') | |
def get_prepositions(self) -> list[str]: | |
return list(filter( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Data validation class for Brazil | |
* | |
* @category Validate | |
* @package Validate_BR | |
* @author Paulo Freitas <[email protected]> | |
* @version 20130204 | |
* @copyright 2005-2013 Paulo Freitas |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Busca de CEP através do site dos Correios (jQuery) | |
*/ | |
function buscaCEP(cep, callback, callbackErro) { | |
$.get('http://www.correios.com.br/encomendas/malote/endereco.cfm', | |
{'tipo': 'origem', 'cep': cep}, | |
function (data) { | |
var data = $('<div/>').append(data).find('input').map(function () { | |
return this.value; | |
}).get(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: text/plain; charset=utf-8'); | |
$schema = <<<SQL | |
-- | |
-- Tabela 'Estado' | |
-- | |
CREATE TABLE Estado ( | |
codEstado INT(1) NOT NULL AUTO_INCREMENT, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Busca de CEP através do site dos Correios | |
*/ | |
function buscaCEP($cep) { | |
$dom = new DOMDocument(); | |
$dom->loadHTMLFile( | |
"http://www.correios.com.br/encomendas/malote/endereco.cfm?tipo=origem&cep=$cep"); | |
$xpath = new DOMXPath($dom); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function formatSize($bytes, $force_unit = null, $format = null, $si = true) | |
{ | |
// Format string | |
$format = ($format === null) ? '%01.2f %s' : (string) $format; | |
if (($si == false) || (strpos($force_unit, 'i') !== false)) { | |
// IEC prefixes (binary) | |
$units = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var changePhoneMask = function () { | |
var phone = $(this).val().replace(/\D+/g, ''); | |
if (phone.length == 2) { | |
if ($.inArray(phone, [11, 12, 13, 14, 15, 16, 17, 18, 19] > -1)) { | |
$(this).unmask().mask('(99) 99999-9999'); | |
} else { | |
$(this).unmask().mask('(99) 9999-9999'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MSDN info: http://msdn.microsoft.com/en-us/library/ms724958(VS.85).aspx | |
import ctypes | |
from enum import IntEnum | |
DWORD = ctypes.c_ulong | |
DWORD_PTR = DWORD | |
LPVOID = ctypes.c_void_p | |
WORD = ctypes.c_ushort | |
class ProcessorArchitecture(IntEnum): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
print date('m', strtotime('first day of 1 month ago')); | |
print date_create()->modify('first day of 1 month ago')->format('m'); | |
print (new DateTime())->modify('first day of 1 month ago')->format('m'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Alteração in-place | |
with open('dados1.txt', 'r+w') as f: | |
lines = [' '.join(l.split() + [str(reduce(lambda x, y: x * y, map(int, l.split())))]) for l in f] | |
f.seek(0) | |
f.write('\n'.join(lines)) | |
# Dois arquivos | |
open('dados2.txt', 'w').write('\n'.join(' '.join(l.split() + [str(reduce( |
OlderNewer