Cucumber/Capybara – Random Error – Circular dependency detected while autoloading constant

Randomly, the first test in our test suite used to fail with an error – “RuntimeError – Circular dependency detected while autoloading constant <Mode/Controller name>”

The reason is that Capybara loads your app in multithreaded environment by default. Some of your app code using require might not be thread safe. Hence use

in your environment test file, for eg. config/environments/test.rb.

This is fixed in Rails 4.2. But for versions before 4.2, use the fix above.

failed to reconnect to node – ElasticSearch log

If you see “failed to reconnect to node” in your Elasticsearch log and you have only one running node, you need to the set the value for network.publish_host to in /etc/elasticsearch/elasticsearch.yml

Open Cricket – New Metrics – Not Outs, Strike Rate, Average & More

Introducing the following metrics today in Open Cricket stats search engine:

* Not outs
* Individual score
* Strike rate
* Average
* Thirties
* Maiden Overs
* Best Bowling Figure
* Econ rate
* Bowling Average
* Bowling Strike rate

Few sample questions:

which player has the highest not outs in ipl

which player has the best individual score in ipl

who has the best strike rate in t20

who has the best average in odi in India

which player has the most maiden overs in world cup

who has the best bowling figure in test?

who has the best economy rate in this year

which csk player has the best bowling average in t20

Try it out or ask your **own** question.

Open Cricket – Get stats from a specific team

Now, you can search for a stat within a particular team.

which player has the most wickets in world cup?
which “(indian|sri lankan|csk|rcb)” player has the most runs?

which indian player has the most wickets in world cup?

which sri lankan player has the most runs in Asia in test?

which indian player has the most runs in world cup in 2015?

which csk player has the most runs in Chennai?

Try it out and provide your feedback below.

Elasticsearch Python Client – Commands

Connecting to a Elasticsearch server

1. Create an index:

You can use custom analyzers in your settings while creating an index.

2. Set mappings for a index and a type:

You can use mappings to define custom fields for the index.

3. Total number of documents in an index:

4. Delete all documents in an index of specific type without deleting its mapping:

5. Get count of documents in each type in an index:


In [14]:'opencricket', search_type='count', body='{ "facets": { "count_by_type": { "terms": { "field": "_type" } } } }')
{'_shards': {'total': 5, 'successful': 5, 'failed': 0},
'took': 233,
'facets': {'count_by_type': {'other': 0,
'total': 3228942,
'_type': 'terms',
'missing': 0,
'terms': [{'term': 'scores', 'count': 985211},
{'term': 'player_stats', 'count': 971777},
{'term': 'compare', 'count': 561225},
{'term': 'matches', 'count': 308937},
{'term': 'most_x', 'count': 262800},
{'term': 'player_dismissals', 'count': 84096},
{'term': 'partnerships', 'count': 28032},
{'term': 'matches_cond', 'count': 26864}]}},
'hits': {'total': 3228942, 'hits': [], 'max_score': 0.0},
'timed_out': False}


Send STDERR to a separate file in Rails production

By default, Rails writes both STDOUT and STDERR streams to “<environment>.log” file. Fox example, in production, the file production.log has the request log as well as any application errors. But it is helpful, if you can send the errors to a separate file, that you can watch for errors.

Though there are gems to do this, the easiest way is to use the broadcast method available in Rails logger. Create a file with the following content and place it in ‘initializers’ directory.

That should set it up.

Prevent ViewPager from taking the full screen

The ViewPager does not support wrap_content for layout_height attribute as it never have all its children loaded at the same time, and can therefore not get an appropriate size (the option would be to have a pager that changes size every time you have switched page).


for your viewpager element. You will see both ViewPager and your second layout (concluded_matches_layout, in this case) in the same screen as below:

ViewPager and Another Layout in Same Screen

References – and

Issues while migrating MySQL to Postgres database

Like everyone else, I started to see the disadvantages in MySQL. Lack of ACID support, no analytical functions, no strict ANSI SQL compliance, no full text search etc.,

Following are the things to take care when you have plans to migrate your data to Postgres from MySQL

  1. Column names with mixed lower and upper cases
  2. Limit Clause SYNTAX change
  3. DATE_FORMAT function
  4. Convert TINYINT(1) to BOOLEAN datatypes
  5. Division by 0
  6.  null value in column “<column_name>” violates not-null constraint
  7. PG::CharacterNotInRepertoire: ERROR:  invalid byte sequence for encoding “UTF8″: 0xe92042 (Sequel::DatabaseError)
  8. Escape single quotes – :%s/\\/’/g

Ignore/Disable Crashlytics reports during App Development

In your ApplicationController (or the class that extends Application),

public void onCreate() {
Crashlytics crashlytics = new Crashlytics.Builder().disabled(BuildConfig.DEBUG).build();
Fabric.with(this, crashlytics);

Gradle will generate the appropriate value for BuildConfig.DEBUG based on your current build.

Editing /etc/hosts file in Genymotion Emulator

I use my local Rails app while developing the Android app. When I tried to connect “http://localhost:3000″ using Volley from the Android app that runs under Genymotion, it threw timeout error. It is because Genymotion runs under Virtualbox and Mac is it’s host OS. To get the IP of your host machine:

☁ duggout [master] ⚡ ifconfig vboxnet0
vboxnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 0a:00:27:00:00:00
inet netmask 0xffffff00 broadcast

Now you can use “″ in your Android app to connect to the localhost of your host OS.

If you need to work with subdomains (mostly required for API driven applications) where your application requires the URL to be of the form “”, you need to edit the hosts file of the virtualbox OS.

Connect your Genymotion device with adb.

./adb devices

to see your Genymotion device. If you do not see your device, open Genymotion settings, goto ADB tab, choose your ADB location instead of the default ADB provided by Genymotion. Restart emulator.

Create a new file (/tmp/hosts) in your system with the following contents: localhost

Now you need to push this file to the Genymotion Virtualbox OS using adb.

./adb root

./adb remount

./adb push /tmp/hosts /system/etc/

Restart emulator. Now you can connect using both localhost and from your Android code.