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()

Invalid shift value in prefixCoded string (is encoded value really a LONG?)

Tips N Tricks August 20th, 2011

Spatial search on documents can be performed using solr and the jteam plugin. Jteam pdf documentation is clear and a good starter.

After installing the plugin in solr and changing the required entries in solr.xml and solrconfig.xml, a spatial query resulted in the following error.

HTTP ERROR: 500

Invalid shift value in prefixCoded string (is encoded value really a LONG?)

java.lang.NumberFormatException: Invalid shift value in prefixCoded string (is encoded value really a LONG?)
at org.apache.lucene.util.NumericUtils.prefixCodedToLong(NumericUtils.java:206)
at org.apache.lucene.search.FieldCache$10.parseDouble(FieldCache.java:294)
at org.apache.lucene.search.FieldCacheImpl$DoubleCache.createValue(FieldCacheImpl.java:635)
at org.apache.lucene.search.FieldCacheImpl$Cache.get(FieldCacheImpl.java:224)
at org.apache.lucene.search.FieldCacheImpl.getDoubles(FieldCacheImpl.java:602)
at nl.jteam.search.solrext.spatial.lucene.LatLongLocationDataSetFactory.buildLocationDataSet(LatLongLocationDataSetFactory.java:35)
at nl.jteam.search.solrext.spatial.lucene.SpatialQuery$SpatialWeight.scorer(SpatialQuery.java:186)
at org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:297)

The solution was to delete the data folder (aka the indexes) and index the data again.

Mozilla components

firefox plugin development December 15th, 2010

Mozilla products are built based on XPCOM, a cross platform component object model. To build a mozilla product, one can make use of already available components and build additional required components. What does this mean? Mozilla components represent callable modules which are exposed to the outer world through interfaces which are XPCOM compatible.

Short example of mozilla components:

For sake of argument, assume that there is no global scoped function called “alert()” in javascript which generates a popup message. The only way of creating a popup box is to access a mozilla component as below:

var sample = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
getService(Components.interfaces.nsIPromptService);
sample.alert(null, “Window Title”, “Alert Message”);

So in a world where “alert()” was never an openly callable function, mozilla components like the one mentioned above which is aptly named as “prompt-service” expose functionalities that can be accessed from outside.

XPCOM was developed so that different components can be developed in different languages and can all be exposed to each other via common interfaces. Hence you can imagine developing mozilla components in Javascript, C++, python and other languages as long as they maintain XPCOM interfaces appropriately. XPCOM interfaces for mozilla components are based on IDL which is an interface description language. Learn more about IDL here .

If you want to know all the mozilla components available on your firefox, you can install the XPCOM Viewer plugin. The following image shows the mozilla components installed in my firefox installation. All these components expose functions that can be accessed as we did in the above example. Since it is cross platform you will be able to find ways to access them across many languages.

Mozilla components in firefox