Removing HTML tags

Programming January 16th, 2012

The code snippet below is a function in python for removing html tags from a text. It can be used from a python terminal as shown in the image or within a python module.

Usage:

1) Remove ‘a’ tags: Type the commands as shown in the image below in a python terminal

Removing HTML tags

Thunderbird RSS Notification

hackinghabits December 30th, 2011

Thunderbird is a wonderful mail client but I missed something really important to me – Growl like notifications for RSS feeds. When I received new emails, Thunderbird would notify me but it would not notify when I received new RSS updates. I looked online but I could not find a good one solution to enable notifications for RSS feeds (I must be totally blind). I decided to write my own and here it is, a linux growl like feature that sends notifications on new RSS and email messages.

https://addons.mozilla.org/en-US/thunderbird/addon/linux-growl/

Screenshot:

OSQA 1.0rc on Django 1.3

Programming November 25th, 2011

OSQA is a stack overflow clone in Django. It is pretty well featured and easy to use compared to a number of other counterparts. Though the next release is waiting for even, there are release candidates and the development version on trunk. If you are planning to use the 1.0 release candidate along with Django 1.3, there are few things that you might likely need to get it working. The primary changes are related to modules being moved around on Django 1.3.

In settings.p, you will require the following changes.

TEMPLATE_LOADERS = [
-'django.template.loaders.filesystem.Loader',
-'django.template.loaders.app_directories.Loader',
+'django.template.loaders.filesystem.Loader',
+'django.template.loaders.app_directories.Loader',
'forum.modules.template_loader.module_templates_loader',
'forum.skins.load_template_source',
]
TEMPLATE_CONTEXT_PROCESSORS = [
'django.core.context_processors.request',
'forum.context.application_settings',
'forum.user_messages.context_processors.user_messages',
-'django.core.context_processors.auth',
+'django.contrib.auth.context_processors.auth',
]

Boto for Amazon Route53

Tips N Tricks August 20th, 2011

Route53 is Amazon’s scalable Domain Name System (DNS) web service. If you are already having your infrastructure on Amazon’s EC2 infrastructure, it is an easy move from your existing DNS provider to Route53.

Boto is a python package that provides a number of python interfaces to interract with Amazon Web Services (AWS) like EC2, RDS, ELB, etc. Boto interface for Route53 is pretty simple. Boto allows adding ‘A’, ‘AAAA’, ‘TXT’, ‘CNAME’, ‘MX’, ‘PTR’, ‘SRV’ and ‘SPF’ records to Route53.

Each zone that is created on Route53 has a zone id which can be obtained by using the command line utility provided by amazon.

% ./bin/route53 ls
============================================
| ID: ZXXXXXXXXXXXXXX
| Name: yourdomain.com.
| Ref: xxxxxxx-xxx-xxxx-xxxx-xxxxxxxxxxxx
============================================
{}

Basic authentication on boto for Route53

The following step is required for all boto operations with route53. In python terminal use the following commands:

>>> import boto
>>> from boto import route53
>>> key = ‘AAES5WCQQBW5XZ2DAA’
>>> access = ‘DMJsjdlkr0OHnrwqEsGkksjweosbg/yeISOPEOdnsK’
>>> route53 = Route53Connection(key, access)
>>> results = route53.get_all_hosted_zones()
>>> results
{u’ListHostedZonesResponse’: {u’HostedZones’: [{u'CallerReference': u'6000r000-b00-0000-8000-46000000c', u'Config': {}, u'Id': u'/hostedzone/ZXXXXXXXXXXXXXX', u'Name': u'yourdomain.com.'}], u’IsTruncated’: u’false’, u’MaxItems’: u’100′}}

Adding A record on Route53 with Boto

>>> import boto
>>> from boto.route53.record import ResourceRecordSets
>>> conn = boto.connect_route53(key, access)
>>> changes = ResourceRecordSets(conn, “ZXXXXXXXXXXXXXX”)
>>> change = changes.add_change(“CREATE”, “yourdomainname.com”,”A”)
>>> change.add_value(“45.34.22.455″) #your ip address
>>> changes.commit()

Adding CNAME on Route53 with Boto

>>> import boto
>>> from boto.route53.record import ResourceRecordSets
>>> conn = boto.connect_route53(key, access)
>>> changes = ResourceRecordSets(conn, “ZXXXXXXXXXXXXXX”)
>>> change = changes.add_change(“CREATE”, “subdomain.yourdomainname.com”, “CNAME”)
>>> change.add_value(“some_dns_name”)
>>> changes.commit()

Adding TXT Record on Route53 with Boto

Note: All text records will require you to add strings as value. Note the extra quotes around the text value, else expect to see an error as below:

Invalid Resource Record: FATAL problem: InvalidTXTRDATA encountered at “\”v=spf1 ip4:64.64.9.245 a mx ~all\”

>>> import boto
>>> from boto.route53.record import ResourceRecordSets
>>> conn = boto.connect_route53(key, access)
>>> changes = ResourceRecordSets(conn, “ZXXXXXXXXXXXXXX”)
>>> change = changes.add_change(“CREATE”, “yourdomainname.com”, “TXT”)
>>> change.add_value(“\”v=spf1 mx ptr include:mail and other text a ~all\”“)
>>> changes.commit()

Deleting CNAME on Route53 with Boto

>>> import boto
>>> from boto.route53.record import ResourceRecordSets
>>> conn = boto.connect_route53()
>>> changes = ResourceRecordSets(conn, “ZXXXXXXXXXXXXXX”)
>>> change = changes.add_change(“DELETE”, “subdomain.yourdomainname.com”, “CNAME”)
>>> change.add_value(“some_dns_name”) #Note: This value has to match exactly with the record
>>> changes.commit()