Monthly Archives: December 2013

Install JDownloader in Ubuntu 12.04

sudo add-apt-repository ppa:jd-team/jdownloader
sudo apt-get update
sudo apt-get install jdownloader

jdownloader

“WARNING: soft rlimits too low” in MongoDB with Mac OS X

If you get this warning when you connect to mongo shell in Mac OX X:

** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000

You can increase that limit by just running this on the Mac OS X shell:

launchctl limit maxfiles 1024 1024

This other command has the same effect but it will only last until the next system reboot:

ulimit -n 1024

Restart mongod and it shouldn’t complain any more.

Solve “mongodb cannot be built while v8 is active” in MacPorts

While updating all the ports of macports I got this error:

--->  Configuring mongodb
Error: mongodb cannot be built while v8 is active.
Error: Please deactivate v8 and try again.
Error: You can reactivate v8 again later.
Error: org.macports.configure for port mongodb returned: v8 is active

To deactivate v8 run:

sudo port -f deactivate v8

Run the update process again:

sudo port upgrade outdated

And finally activate v8 again:

sudo port activate v8

Ref: http://widgetbook.blogspot.com.es/2013/08/mongodb-and-macports-and-v8.html

“AttributeError: ‘module’ object has no attribute ‘MongoClient’” error with Pymongo in Ubuntu 12.04

"Error AttributeError: 'module' object has no attribute 'MongoClient'" con Pymongo en Ubuntu 12.04">

I’m currently doing the M101P: MongoDB for Developers online course.

course_image

I had this error while running one of the homeworks with pymongo in Ubuntu 12.04:

AttributeError: 'module' object has no attribute 'MongoClient'

I had previously installed pymongo with apt-get like this:

sudo apt-get install python-pymongo

It looks like the package is outdated or broken so I had to remove the pymongo I had installed before and reinstall it using PiP:

sudo apt-get purge python-pymongo
sudo apt-get install python-pip
sudo pip install pymongo

Ref: http://stackoverflow.com/questions/17624416/cant-import-mongoclient

Expose config.yml values globally for Twig templates in Symfony2 applications

Lets suppose you have created a bundle that has some specific configuration in the config.yml file (this is done by exposing semantic configuration). For example the languages supported by the application:

acme_demo:
    languages:
        en: English
        es: Spanish (Español)

You could make all your controllers read this language configuration from the container interface and then expose that variable to the templates like this:

// src/Acme/DemoBundle/Controller/AcmeController.php
$this->languages = $this->container->getParameter('acme_demo.languages');
    }

    public function indexAction()
    {
        return $this->render('AcmeDemoBundle:Default:index.html.twig',
                array('languages' => $this->languages)
        );
    }
}
// src/Acme/DemoBundle/Resources/views/Default/index.html.twig
{% for lang, language in languages %}
                    {{ lang }} - {{ language }}
{% endfor %}

But this would be VERY tedious. A much better approach is to create a Twig extension that exposes that configuration readed from the container interface as it would be done inside config.yml in the twig:globals section:

// src/Acme/DemoBundle/Twig/LanguageExposeExtension.php
container = $container;
    }
    
    public function getGlobals()
    {
        return array(
            'languages' => $this->container->getParameter('acme_demo.languages')
        );
    }
    
    public function getName()
    {
        return 'language_expose_extension';
    }
}

And of course register this class as a Twig extension using the twig.extension tag:

// src/Acme/DemoBundle/Resources/config/services.yml
services:
    acme.twig.language_expose_extension:
        class: Acme\DemoBundle\Twig\LanguageExposeExtension
        arguments: []
        tags:
            - { name: twig.extension }

Now you can remove the language parameter in the render call because it’s now defined globally for all templates.