come with me, on the way I'll explain.
Função MD5 em Python
MD5, Message-Digest algorithm 5, é um algoritmo de hash de 128 bits, unidirecional. Ele é muito útil como método de verificação de integridade de arquivos, armazenamento de senhas, criptografia ou para hashing em geral. Eu utilizo ele com muita frequência.
Em Python você calcula o hash de uma string em duas linhas:
import md5 print md5.new('silveira').hexdigest()
O md5.new() retorna um objeto que cria md5. Ele é bem flexível e pode ser utilizado várias vezes. O hexdigest é a representação hexadecimal do md5, aquela que pode ser impressa.
Esse código imprime isso:
3df2175295d900d6f0c2f3a521d957cd
Que é o md5 de silveira.
No comments yet.
Contando Algarismos Em Um Intervalo
29 January, 2010 - 8:21 pm
Tags: compreensão de lista, Programação, programação funcional, Python
Posted in english | 3 comments
Quantos zeros tem entre um e mil?
É mais fácil responder perguntas desse tipo escrevendo pequenos programas usando o suporte a programação funcional e compreensão de lista que algumas linguagens como Python oferecem.
Para contar os zeros de um número, transformamos ele em uma string e contamos quantas substrings ‘0′ ele contém. Por exemplo o 800:
str(800).count(’0′)
# 2
Para [...]
Easily Sortable Date and Time Representation
20 January, 2010 - 10:55 pm
Tags: date, datetime, ISO 8601, Jochen Voss, Markus Kuhn, programming, Python, representation, sort, sorting, time
Posted in english | No comments
I was looking for a date and time representation useful for registering stock quotes in a simple plain file.
I found that the standard ISO 8601 is just the answer for this, it’s called “Data elements and interchange formats — Information interchange — Representation of dates and times”. Here is a example:
2010-01-20 22:14:38
There’s this good article from [...]
Extração de Dados e Fundos de Investimento do Banco do Brasil
11 January, 2010 - 9:02 pm
Tags: ações, aplicações, Banco do Brasil, bolsa de valores, CRON, Data Mining, fundo de investimento, fundos, fundos de investimento, JSON, Mineração de Dados, Python, screen scraping, Web Harvest, web scraping, XML, yaml
Posted in english | 2 comments
Eu não achei onde coletar os dados diários de rentabilidade dos fundos de investimento do Banco do Brasil em formato bem estruturado.
Num mundo ideal as coisas seriam assim, você faria uma requisição numa url como esta:
http://bb.com.br/apps/rentabilidade?fundo=Siderurgia&saida=xml
E ele cuspiria um XML com as informações da rentabilidade diária desse fundo, isso se eu não especificasse através de [...]
Python Fast XML Parsing
25 December, 2009 - 3:04 pm
Tags: dtd, expat, game, programming, pygame, Python, sax, schema, urllib, XML
Posted in english | 1 comment
Here is a useful tip on Python XML decoding.
I was extending xml.sax.ContentHandler class in a example to decode maps for a Pygame application when my connection went down and I noticed that the program stop working raising a exception regarded a call to urlib (a module for retrieve resources by url). I noticed that the [...]
Tiled TMX Map Loader for Pygame
I’m using the Tiled Map Editor for a while, I even wrote that tutorial about it. It’s a general purpose tile map editor, written in Java but now migrating to C++ with Qt, that can be easily used with my set of free pixelart tiles.
A map done with Tiled is stored in a file with [...]
Pygame: Running Orcs
11 December, 2009 - 7:47 am
Tags: game, orc, Pixelart, programming, pygame, Python
Posted in english | No comments
Here is a Pygame Sprite animation using the approach presented by Joe Wreschnig and Nicolas Crovatti. It’s not yet exactly what I need but is very suitable.
import pygame, random
from pygame.locals import *
class Char(pygame.sprite.Sprite):
x,y = (100,0)
def __init__(self, img, frames=1, modes=1, w=32, h=32, fps=3):
pygame.sprite.Sprite.__init__(self)
original_width, original_height = img.get_size()
self._w = w
self._h = h
self._framelist = []
for i in xrange(int(original_width/w)):
self._framelist.append(img.subsurface((i*w,0,w,h)))
self.image = [...]
Pygame Simple Key Handling
10 December, 2009 - 12:50 am
Tags: pygame, Python
Posted in english | No comments
Here’s a simple key handle in Pygame wheres you move a circle using keyboard.
import pygame
from pygame.locals import *
def main():
x,y = (100,100)
pygame.init()
screen = pygame.display.set_mode((400, 400))
while 1:
pygame.time.delay(1000/60)
# exit handle
for event in pygame.event.get():
if event.type == QUIT:
return
elif event.type == KEYDOWN and event.key == K_ESCAPE:
return
# keys handle
key=pygame.key.get_pressed()
if [...]
Pygame, Simple Space Effect
12 August, 2009 - 7:14 am
Tags: game, game development, game loop, list comprehension, pygame, Python, SDL, Simple Direct Layer, sliding stars, Space, space effect, stars
Posted in english | 1 comment
This is a simple space effect of sliding stars using Pygame.
Direct link to video: simple_space_effect_01.ogv
We set some constants like the screen size and the number N of star we want.
N = 200
SCREEN_W, SCREEN_H = (640, 480)
Using list comprehension we create a list of random points in the screen, that will be our stars. The size [...]
JavaFX, Retrieving non XML/JSON data from clouds
31 May, 2009 - 12:34 pm
Tags: HttpRequest, JavaFX, JSON, PullParser, Python, XML, Zembly
Posted in english | 6 comments
Usuually on JavaFX we grab data using HttpRequest from external resources on formats like JSON or XML. I showed how to get it on the post Reading Twitter with JavaFX and how to parse it using PullParser on the post Parsing a XML sandwich with JavaFX.
Another day I need to grab and interpret some plain [...]
Ilex Paraguariensis
15 March, 2008 - 5:20 pm
Tags: Brazil, Chimarrão, FISL, Java ME, JavaFX, JavaScript, Opensolaris, PHP, Porto Alegre, Python, Rio Grande do Sul, Ruby, travel
Posted in english | 1 comment
Creative Commons image from Flickr.
From days 15 to 20 from April, I’ll be in Porto Alegre. I’ll participate on FISL (an old dream) with the presentation “Netbeans: beyond Java”. I’d like to talk about how you can use Netbeans as a great IDE for languages others than Java like Ruby, PHP, JavaFX, Javascript, Python, etc.
Probably [...]












