The Google PageRank is a numeric value that represents how important your page is on the web. It is based on the number and quality of "backlinks" a webpage has. A high PageRank indicates that the page must be important since many sites are linking to it.
Python code to check your Google PageRank
|
|
| Posted on Aug 28, 2008 by: Fred Cirera @ 18:09 |
Comments: 0
|
Send a multipart email in Python
|
This short example show how to send a mail with attachments using Python.
First we create a Mime container using the class MimeWriter and then the message is sent using smtplib package. |
| Posted on Jan 24, 2008 by: Fred Cirera @ 13:28 |
Comments: 1
|
Print human readable file size.
|
Often you have to print a file or a directory size. Here is a small recipe to print a file, or a directory size easily readable by humans.
def sizeof_fmt(num): for x in ['bytes','KB','MB','GB','TB']: if num < 1024.0: return "%3.1f%s" % (num, x) num /= 1024.0 Example: >>> sizeof_fmt(168963795964) '157.4GB' |
| Posted on Dec 12, 2007 by: Fred Cirera @ 19:22 |
Comments: 3
|
Mail list validator
|
While working on a web application called CastAFile, which use a list of email addresses as input. I had to write a Validator to format and validate each email address entered. Here is the code and the description of this validator.
This validator checks a comma separated list of email addresses. This class inherit from validator.Email. |
| Posted on Dec 04, 2007 by: Fred Cirera @ 16:58 |
Comments: 0
|
Problem with TGCaptcha
|
I am a heavy user of TGCaptcha. I know that Captchas are not the best answer to the spam issue but they limit a lot of problems caused by bots that scan the web for forms.
Last week, I discovered a big flaw in TGCaptcha: it can be bypassed very easily. In this post I will explain how to easily fix the problem, while waiting for the latest version of TGCaptcha. |
| Posted on Nov 22, 2007 by: Fred Cirera @ 08:32 |
Comments: 0
|
Cryptographic signature.
|
HMAC is a type of message authentication code (MAC) calculated using a cryptographic hash function in combination with a secret key. The HMAC algorithm can be used to verify the integrity of information passed between applications or stored in a potentially vulnerable location.
For the full details on HMAC, check out the RFC-2104 Python provide some basic cryptographic services such as HMAC. The use of HMAC in python is pretty straightforward. Here is an example: import hmac hmac_engine = hmac.new('This Is My Super Secret KEY') f = open('/etc/services', 'rb') try: for block in f: hmac_engine.update(block) finally: f.close() print hmac_engine.hexdigest() When run, the code reads its source file and computes an HMAC signature for it: $ python hmactest.py
01c274a3eaca826fcd1b645e074bf99b
You can use HMAC in web applications to check the integrity of URLs or cookies. Your application need to send a cookies with some information for example the login. Of course you don't want some to temper with this cookie and change the user name. One solution is to sign the cookie with an HMAC digest. Here is a code snippet example: import hmac import cherrypy user_login = 'mallory' hmac_engine = hmac.new('This Is My Very-Super-Secret KEY!') hmac_engine.update(user) digest = hmac_engine.hexdigest() cherrypy.response.simple_cookie['user'] = user cherrypy.response.simple_cookie['digest'] = digest |
| Posted on Oct 17, 2007 by: Fred Cirera @ 00:34 |
Comments: 0
|
Comments: 0