Ouch! My Bad

Originally posted on Subhodip's Blog:

JavaScript is powerful and Backbone.js is a nice small utility that makes it even more powerful. I was playing with Backbone and Open layers thrown over a Django system.
However there is something weird that I faced and took a good amount of my time to figure out the problem.
This blog post is kind of self note so that I notice this the first place when I face such problem again.

What was I trying to do : Write a small backbone code to display Open layers(OSM) Map.
How was I trying to do :

(function($) {
var Map = Backbone.Model.extend({});

var MapView = Backbone.View.extend({

initialize: function() {
_.bindAll(this, 'initMap');
this.initMap();
},

initMap: function() {
// Initialize Basic Openlayers;
var center = new OpenLayers.LonLat(8110203.9998955, 2170000.4068373);
map = new OpenLayers.Map(this.el, {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
});
var layers = [];
layers[0] = new OpenLayers.Layer.OSM(); //some more layer will…

View original 183 more words

Dear Turkish translators

Transifex usually defines plural rules for languages according to http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html. So, the plural rule for Turkish language in Transifex is other → everything. However, lately there has been some requests that the Turkish language should have two plural forms:

nplurals=2; plural=(n>1)

The requests have been with reference to http://translate.sourceforge.net/wiki/l10n/pluralforms.

Here is a quote from a user at https://bitbucket.org/indifex/transifex/issue/26/turkish-plural-forms:

Turkish behaves like Akan for example. The rule should be:

One: 0, 1 Other: 2-999

It is only when including a count that there are no plural forms. For example:

“You posted a photo”, “You posted several photos”

is correct in Turkish, as is:

“You posted 1 photo”, “You posted 6 photo”.

So, dear Turkish translators, please share your opinion on this issue. This will help a lot to resolve this issue at Transifex and fix plural translations in Turkish language.

rtnpro @ Mukti 2012

Mukti is the annual FOSS festival organised by the GNU/Linux Users Group of NIT Durgapur. Mukti 2012 was held on 3-5th February 2012. I have attended every Mukti in NIT Durgapur from 2008 to 2011 as a student and this time (in 2012) as a speaker. My talk was on Localization and Transifex. NITDGPLUG, as always, put a lot of effort in making Mukti a grand FOSS event in the region. It was a packed with a plethora of events and had a large number of participants. Mukti serves as a great means to get together people interested in FOSS in the Eastern and North Eastern part of India. It helps newbies get more insight into FOSS.

Day 1, February 3, 2012

The first day of Mukti began with an inauguration programme. After the inauguration programme, students queued at the registration desk for registering themselves. Sayan and Gaurav came there with a small group of 1st year students (interested in FOSS) from Dr. B. C. Roy Engineering College. I spoke to them for a 1-2 hours on FOSS, how to contribute, my experience with FOSS and how I made to Transifex. After bidding good bye to the 1st year students from BCREC, we (me, Sayan, Gaurav and a few others) settled in my room at the Guest House, NIT Durgapur and started discussing on various stuff like Transifex, Django, unit testing, some college news, etc. There was also a workshop on KDE development that day by Smit Shah. After the workshop was over, the Transifex community guys from Durgapur crashed in my place and we kept hacking till late night.

Day 2, February 4, 2012

For the 1st half of the day, I came to BCREC to talk with the students on FOSS and meet my teachers and other friends. After returning to NIT Durgapur, I had a discussion with some folks interested in web development and Transifex. I discussed with them about Transifex, what it is, why it is created, how it works and how it is written. Also, we discussed on other stuffs like contributing to FOSS, python, Django, etc.  We spent the entire evening hacking on Transifex. We fired our local Transifex instance and started discussing about bugs and areas of improvement. I also explained in details to the Transifex contributors on how to write unit tests for Transifex. I also showed to them how to write a handler for a file format in Transifex.

In between, I had a good conversation with Smit Shah. We shared our views on FOSS and contributing to it, and also our experience and excitement in working for a startup. We also discussed on Manga: Naruto, Fullmetal Alchemist Brotherhood and One piece ;-) Even after dinner, we kept hacking, till midnight. The day was quite eventful. We triagged some tickets at trac.transifex.org, fixed some bugs, found new bugs to work on, etc.

Day 3, February 5, 2012

This was the final day of Mukti and my talk on Localization, Transifex and FOSS contribution in general was scheduled for this day. In this talk, I started with “What” and “Why” of localization and how it helps the global usage of a software. Also, I explained that localization is one of the easiest way to start contributing to FOSS and get the feet wet in community, learn new technologies, etc.  Then, I discussed the workflow of localization and its pros and cons.

Then, I came to Transifex, why was it needed, how and when did it start, and how it takes localization to an all new level. I discussed the technologies used behind Transifex and gave the audience a tour through Transifex. Transifex is no small thing now. It has grown over the years and it takes a lot to explain its features. Enough with technical jargon. To make it interactive, I called Sayan to share his experiences about his contribution to Transifex. Also, I shared our story that how a group of 3 newbie translators made http://www.transifex.net available in Hindi just in a few days.

Then, I told the people that how they can start contributing to Transifex and any open source project in general. But, still there was the impression that contributing is a VERY DIFFICULT task. So, I decided to hack live in front of all the audience and fix a few Transifex bugs (bugs on which we worked on the previous day, during the hackfest). I fixed 2-3 small bugs, showed what is a patch and how to commit a patch. The patches had just 1-2 lines of change. I hope the audience got my point, that fixing bugs is not a very difficult job.

Then, I shared my experiences with FOSS, how I came into the FOSS community, how I started contributing and how I made into Transifex. With this, I concluded my talk. After the session, a few students came to me with queries and we had a kind of group discussion with them.

You can find the slide deck I used for my talk at http://rtnpro.fedorapeople.org/Transifex-Mukti2012/presentation.pdf

After the talk, we headed back to the guest house and had some gossip and masti with my college juniors. In the evening, we attended the prize distribution function and then headed back to the guest room. After dinner, we started discussing about things like how to boys should proceed in their open source endeavours, brainstormed some crazy project ideas, etc.

It was an awesome experience at Mukti this year. Met with many people, made new friends, had lots of fun and a lot of hacking.

#Transifex now supports comments in Apple .strings i18n files

#Transifex now supports comments in Apple .strings i18n files. Only /* foo */ style comment in the line preceding the key value pair in the source file is saved as a comment for the key. The example below will explain this in a better way:

/*Comment for key1*/
"key1" = "value 1";

/* This comment will not be
included in key2*/

/* comment for
key2*/
"key2" = "value 2";

/* this comment will not be included in key3*/

"key3" = "value 3";

Well, I’m pretty sure that the above snippet explains which comments from source Apple .strings file are saved by Transifex. You can see the comment for a source string in its “Details” section in Lotte.

Comment for a source string imported from a source Apple .strings file

NVIDIA issues fixed on Fedora 16

This week, I upgraded from Fedora 15 to Fedora 16 on my Dell XPS M1530 laptop. This laptop has a 256 MB NVIDIA 8600M GT graphics card. The default driver for NVIDIA cards that came with the installation was nouveau. Nouveau is an open source driver for NVIDIA graphics cards and is under development. Things are becoming better and better with nouveau.

I ran gnome-shell for some time with the nouveau driver. 3d rendering worked nicely and without any latency. I did not find any other issue except for some overheating issues. So, I decided to switch to the NVIDIA’s proprietary driver.

Here is a good tutorial to disable nouveau and install NVIDIA’s proprietary driver in Fedora 16: http://www.if-not-true-then-false.com/2011/fedora-16-nvidia-drivers-install-guide-disable-nouveau-driver/

But, this would work perfectly if this was for Fedora 15. Fedora 16 comes with glibc-2.14.90-14 and the NVIDIA proprietary driver (the latest stable driver as of now is NVIDIA-Linux-x86-285.05.09.run). This issue has been reported at https://bugzilla.redhat.com/show_bug.cgi?id=737223. The issues I faced after installing the proprietary NVIDIA driver in my Fedora 16 machine were:

  • window manager behaving sluggishly
  • tab switch in applications like gnome-terminal, nautilus browser taking around 3-4 seconds (no such issues with KDE’s konsole)
  • System getting overheated
  • Increased latency in gnome-shell effects
  • Similar issues with window manager and tab switch on XFCE too

I guess everything depended on glibc were affected.

This issue could be fixed  by downgrading glibc to  glibc-2.14.90-4. I tried to do this to find that there are quite a few applications depended on glibc-2.14.90-14 in F16. So, I gave up the idea. I was looking for nvnews for any news from NVIDIA about fix for the above issue. And I came across this thread http://www.nvnews.net/vbulletin/showthread.php?t=122606 where I found about the current releases of NVIDIA graphics driver and the beta driver at http://www.nvnews.net/vbulletin/showthread.php?p=2498046. I was desperate enough to try the beta driver. I did:

and then follow through the on screen instructions.

  • # init 5

and logged in. To my surprise, everything was perfect this time. No latency in gnome-shell, no overheating issue. Everything is just fine. Now, I have been running gnome-shell on Fedora 16 in my laptop for over 24 hours. I did not find any issue with the NVIDIA beta graphics driver so far.

Me & FUDCON India 2011

I arrived in Pune for FUDCON on November 2, 2011. On November 3, 2011, I had an opportunity to visit the Red Hat office in the city and hang around with Fedora community members. I learnt more about the mechanism and importance of localization from Runa Bhattacharjee. In my free time, I also helped with some FUDCON related work. I  was able to meet Jared Smith, Joerg Simon and Robert Scheck for the first time in my life, talk with them. I couldn’t ask for anything better.

Day 1: November 4, 2011

Day 1 began with a speech from the Director of COEP followed by the keynote speech by Fedora’s Project Leader Jared Smith. Jared explained to people the various aspects of Fedora and how Fedora takes the lead in pushing the limits of FOSS development. Following that was my talk on Transifex. The audience included people mainly from the L10n domain. There were some mishaps during the talk. First, my Dell XPS laptop wasn’t able to use the projector; second, I had to use another netbook which I wasn’t used to; third, there were some power issues, and the netbook turned off and finally, there was power cut for a few minutes. What a chain of mishaps! I had to resort to reading the slides from my phone during the power cut. Finally, I used Kishan Goyal’s laptop to continue with the presentation. In  my talk, I explained the current features and upcoming features of Transifex. I explained it with a use case, starting from registering to advanced usage of www.transifex.net. The audience appreciated our upcoming market place idea and the Translation Memory feature. I also got feature request for having a global glossary for a particular language in the language page. It was really nice that the audience were so actively communicating during the session. I also told how to start contributing to the Transifex project and shared my experience working on Transifex so far: from a contributor to an employee.

After the lunch, I attended Heherson Pagcaliwagan‘s session on “Fedora web of trust” and got more insight into the use of GPG keys. We did a small workshop with Heherson on how to get introduced to each other, verify identity, share GPG key and sign it. Heherson also showed us how to encrypt mails using GPG key. Then I attended Joerg Simon’s talk on Fedora Security Lab and OSSTMM. Kital showed us a variety of security tools that can be found in the FSL, and mentioned others that need to be packaged. I must try out the tools in the FSL now. They are so cool.

Then I went back to the speaker’s lounge and started writing some code on Transifex. It was a great first day at FUDCON for me.

Day 2: November 5, 2011

The Second day of FUDCON began with Harish Pillay speaking about the community. Unfortunately, I was not able to turn up during the keynote, as I had to re create my slides on my talk on “Testing your Django app”. Because I had accidentally, deleted the folder which contained the slides. After I was done, I hurried to attend Arun Sag’s talk on “Creating web apps using Django”. I liked Arun’s way of presenting things to the newbies in a very lucid way. He used his classic Blog example for this.

Next was my talk on “Test your Django app”. As during Day 1, the projector did not work with my laptop, so I used Arun’s laptop for the purpose. I explained why tests are necessary, different testing frameworks in Django (doctest, unittest). Then I went forward to explain how to write simple unittests. For this, I wrote some tests for Arun’s blog example and used it so that the audience could relate things with the previous session taken by Arun. I showed some simple test cases and ran the tests. Then, I introduced the Django Test Client and spoke about its importance and features. After explaining things about the Test Client, I showed the relevant code and ran the tests again. Finally, I explained about coverage: what is it? why is it required? How to use coverage? I again ran the tests I had run before, but this time I ran them with coverage and explained how to read the coverage report. I haven’t been too happy with this session of mine. Now, when I think of it, for students who just got introduced to Django, the session on Django testing might have been asking too much. Anyway, the students now at least know something called Django testing exists. So, when they need it, they can learn.

After having lunch, I attended Siddhesh’s talk on “Security Exploits”. During the session, I could not but think that why I did not have someone like Siddhesh teaching me OS in my college. He was awesome. Back in my college days, I had tried reading about security exploits, but I did not get far. But during this session, thanks to Siddhesh’s explanations and my earlier reading, I have gained a better understanding of security exploits, especially stack smash attack, overwriting nearby entities in data region by string overflow, etc.

Following were two lightning talks on 1) How to deal with kernel panic? 2) Running external commands from Postgres. Yogesh in his talk on “kernel Panic” showed how to collect relevant data when there is a kernel panic. This data can be used for creating useful bug reports or for fixing the bug itself.

After attending Siddhesh’s talk on autotools, I joined mether’s talk on ask.fedoraproject.org or askbot. Mether discussed its roadmap and mentioned various feature requests. I picked up to implement a few of the feature requests. After the session, we had a group photo session of the almost all the people involved in FUDCON. Then all the speakers, volunteers and organizers went for the FUDPUB. I enjoyed a lot at the FUDPUB. I spoke with the community members, danced with them, drank Mirinda and ate some delicious food. It was just awesome.

Day 3: November 6, 2011

It’s the hackfest day. I decided to run a Transifex Testathon. I pitched the topic on stage and invited people to join me. I helped some of my friends install and setup transifex in their machines and showed them how to run tests. I started writing new tests for the watches addon in Transifex. I came across a chain of undiscovered bugs while doing so. It took me some time to write a proper test case for the watches and accordingly fix the bugs in the code. I also helped Kushal to get him logged into his Transifex account and creating a Transifex project for “Python for you and me”. Jared Smith, set up the tx client for “Python for you and me” and now PYM is hosted at https://www.transifex.net/projects/p/pym/ for localization. Shreyank, Vaidik and I had discussions on the roadmap for Dorrie. I setup Dorrie on my machine and played with it for some time. I decided to write tests for Dorrie the coming weekend.

Then, at the end of Day 3, in the auditorium, a cake was cut to celebrate this FUDCON along with quite a few photo shoots. The FUDCON organizing group and the volunteers from COEP did a great job to make this event go on smoothly.

FUDCON India 2011 is the first ever FUDCON in India and the largest FUDCON in terms of the number of participants. Apart from learning new stuffs and hacking, FUDCON provided a great platform for Fedora contributors to meet with each other and make new friends. It is also a nice experience to work with people whom I had known only in the IRC until now. I am carrying sweet memories of this FUDCON with me. These memories will help me focus more on contributing to open source and be a better contributor.

Start testing Transifex

 

How do you setup Transifex?

Here is all you need to know to setup Transifex: http://help.transifex.net/server/install.html

http://fosswithme.wordpress.com/2011/10/20/setup-transifex-in-virtualenv/ is another good write-up on how to setup and run Transifex in virtualenv. So, I’d be building on top of that to show you how to start testing Transifex using django-nose.

What packages will you need?

django-nose, nose, nose-exclude, coverage

You can install the above packages using

pip install <package_name>

Configure Transifex settings to enable django-nose Test Runner

cd <transifex source code's root directory>

cd transifex/settings

cp  90-local.conf.sample 90-local.conf

open and edit 90-local.conf and add the following lines:

INSTALLED_APPS += [

'django_nose',

]

TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

cd ..

Now, save the file. Now you are good to go.

Start testing

python manage.py test <app_name>

for example:

python manage.py test resources

You can also test a particular test class like below:

python manage.py test resources.tests:TestJavaProperties

You can even run a particular test method:

python manage.py test resources.tests:TestJavaProperties.test_properties_parser

Run coverage on Transifex tests

django-nose has a plugin for coverage. So, you can run the above tests and collect coverage data.

For example:

python manage.py test resources.tests:TestJavaProperties.test_properties_parser --with-coverage --cover-package=resources.tests.formats

All the coverage results are saved in a .coverge file by default in the current directory. Although, running tests with coverage plugin of django-nose shows the coverage results by default. You can also see the coverage results in the usual way:

coverage -rm

You can also use grep along with the above command to filter the results displayed.

Well, that's all you need to know to start testing Transifex.

What's next?

Start testing transifex. If you find a test fails, try to find the reason why it failed. Read the traceback info properly. Find where the error took place. There are various reasons why a test may fail:

  • Test is not updated according to updates in code
  • Bug in code
  • A wrong test case

and others...

You can report the issues or any bug you find at http://trac.transifex.org/newticket. Feel free to submit a patch that fixes the issue. The patch will be reviewed by the Transifex upstream and if it is ok, it will be merged with Transifex's code at http://code.indifex.com/transifex/.

Keep hacking :)

Regex pattern for c style comments

Today, I am going to discuss my attempts to parse c style comments.

For example,

//This is a comment

/***This is also
*** a comment ***/

Initially, I came up with a regex for /*…*/ style comments :
/\*.*\*/
Well, the above expression was not able to parse comments like:

/*** This is a comment ***/

I googled and came across http://ostermiller.org/findcomment.html where I found the regex:
/\*(.|[\r\n])*?\*/
This was able to match comments like the above one. But it’d also match the following /*…*/ comments which are not really comments:

s = "This is a string: /* with a comment */";
//comment1 /*
foo();
//comment2 */

I then worked on a regex for //… style comments: //[^\n]*\n

Then I combined the two regexes by or and my regex pattern becomes:

//[^\n]*\n|/\*(.|[\r\n])*?\*/

Now, this pattern is able to search for both: //… and /*…*/ style comments and avoid matches for patterns like:

//comment1 /*
foo();
//comment2 */

One caveat that remains is the /*…*/ pattern in
s = "This is a string: /* with a comment */";
getting matched. If any one has a work around this issue, please comment.

I hope this helps.

Add plug-n-play functionality to your Django project using Django-addons

What is Django-addons?

A Django app used to add true plug-n-play functionality to your own Django applications and projects. Django-addons is brought to you by Indifex, the company behind Transifex.

Django-addons is a bunch of code that makes writing addon/plugins for your Django project much easier. Add django-addons to your Django project and you can drop all the addons to ‘/addons’ directory.

How to install Django-addons?

You can install the latest version of django-addons running
pip install django-addons
or
easy_install django-addons

You can also install the development version of django-addons with
pip install django-addons==dev
or
easy_install django-addons==dev.

Source code

http://code.indifex.com/django-addons/

Features

  • Addons overview page
  • Automatic signal connecting of addons
  • Automatic URL discovery of addons
  • Template hooking system (inject code from addons to your main project)
  • Django-staticfiles to serve site media from each addon
  • Django-notifications support (automatic registration of noticetypes)
  • Per addon localization
  • Per addon settings
  • Disabling addons via ./manage.py addons

Transifex implements related tag cloud

Lately, I have been working on a bunch of exciting new stuffs for Transifex. I have worked on a tag-cloud implementation which not only shows the popular tags, but also shows tags related to a tag selected by the user. It is pretty useful. It directs the user to select more relevant tags. The tag cloud is refreshed each time the user makes a selection to show the related tags.

I built this on top of the django-tagging module. I wrote a model to represent a tag as a node in a graph. The model includes all the tags related to it (that is tags which appear with the tag in concern) as adjacent nodes along with the weight (that is number of times the two tags appear together) of each edge between two related tag nodes. This data is updated and synced as necessary, e.g, after a project is added or updated. Now, whenever a tag is selected, the tag-cloud is refreshed to show the related tags. The font-size of a related tag is decided by taking into consideration both the weight of an edge it shares with the selected tag and its count. Below is a sample use case for related tag-cloud in Transifex.

Let’s say there are two projects, p1 with tag ‘foo1′ and p2 with tags ‘gui’, ‘graphics’, ‘imaging’ and ‘photography’. For sake of simplicity, I am showing only 3 most popular tags: ‘foo1′, ‘gui’, ‘graphics’. So, now when the maintainer for prohect p1 goes to edit the project, he sees the following tag-cloud:

Initial tagcloud

Now, he selects a new tag ‘graphics’ and the tagcloud is refreshed to show the tags related to ‘graphics’.

Tagcloud with related tags.

Such small things together can really take the user experience to a new level. By implementing related tag-clouds, we enable the user to choose relevant tags in a better way. At Transifex, we innovate to help people localize in a better way :).