Play youtube videos without using browser directly from Unity on ubuntu 11.10

I just read on omgubuntu that is now possible to install an Unity Lens that makes you able to search in the youtube directory and play videos direcly using VLC if installed.

This is the original article: http://www.omgubuntu.co.uk/2012/01/unity-youtube-lens-updates-with-browser-free-video-playback/

Setting it up is very easy, just run the following commands:


sudo add-apt-repository ppa:atareao/lenses

sudo apt-get update && sudo apt-get install lens-video scope-youtube

Happy watching!

Categories: ubuntu Tags: , , ,

How to set black background on geany and remove the green / white line

Geany is a very good editor to edit a big variety of source codes. Unfortunately it has a white background by default. I dunno if you have ever used a black background based editor such as vim but it makes your eyes less stressed when u are coding, and this thing is something that will increase your productivity. I tried to switch geany to use a black brackground and i found many extensions to do that… but i always have thought that it was impossible that geany codes didn’t think about this. After playing a bit with the settings i found a way.

Just go to Edit->Prerefencies then go to Editor and select the Display tab. U will see something like this:

 

Just select invert syntax highlight colors and you did it. If you want also to remove the odd green or white lines that appears after 72 characters you can just disable the long line marker and it will go ;)

Hope this helps

Categories: Programming Tags: ,

Ubuntu 11.04 clipboard with unity support

One thing I use frequently on my computer is a clipboard. With ubuntu 11.04 and Unity, the clipboard manager i used was not able to work like i want on Unity. So i browsed the net for a good clipboard replacement, and i found one.

It’s called Diodon and it’s an easy and effective clipboard with unity compatibility. Unfortunately it’s not in the ubuntu 11.04 default repo. To install it you have to add the diodon repository. You can do it just typing in a shell:


sudo add-apt-repository ppa:diodon-team/daily

Then install the diodon package. After reboot you will see a clipboard icon close to the clock.

Categories: ubuntu Tags: , ,

How to switch to different python version on apache mod_wsgi

By default the ubuntu-debian package of libapache-mod-wsgi contains the wsgi apache module compiled for either python 2.6 and python 2.7. This makes really easy to switch between python 2.6 or python 2.7 support in webapps. Indeed you have just to change a symbolic link to make your application working with python 2.7 interpreter if python 2.6 is enabled by default.
As you can see the libapacke2-mod-wsgi package countains both the 2.6 and 2.7 version of the the modules.
Se let's see how to accomplish this:
vincenzo@mba:/usr/lib/apache2/modules$ ls
httpd.exp             mod_authz_groupfile.so  mod_dir.so           mod_mem_cache.so       mod_ssl.so
mod_actions.so        mod_authz_host.so       mod_disk_cache.so    mod_mime_magic.so      mod_status.so
mod_alias.so          mod_authz_owner.so      mod_dumpio.so        mod_mime.so            mod_substitute.so
mod_asis.so           mod_authz_user.so       mod_env.so           mod_negotiation.so     mod_suexec.so
mod_auth_basic.so     mod_autoindex.so        mod_expires.so       mod_proxy_ajp.so       mod_unique_id.so
mod_auth_digest.so    mod_cache.so            mod_ext_filter.so    mod_proxy_balancer.so  mod_userdir.so
mod_authn_alias.so    mod_cern_meta.so        mod_file_cache.so    mod_proxy_connect.so   mod_usertrack.so
mod_authn_anon.so     mod_cgid.so             mod_filter.so        mod_proxy_ftp.so       mod_version.so
mod_authn_dbd.so      mod_cgi.so              mod_headers.so       mod_proxy_http.so      mod_vhost_alias.so
mod_authn_dbm.so      mod_charset_lite.so     mod_ident.so         mod_proxy_scgi.so      mod_wsgi.so
mod_authn_default.so  mod_dav_fs.so           mod_imagemap.so      mod_proxy.so           mod_wsgi.so-2.6
mod_authn_file.so     mod_dav_lock.so         mod_include.so       mod_reqtimeout.so      mod_wsgi.so-2.7
mod_authnz_ldap.so    mod_dav.so              mod_info.so          mod_rewrite.so
mod_authz_dbm.so      mod_dbd.so              mod_ldap.so          mod_setenvif.so
mod_authz_default.so  mod_deflate.so          mod_log_forensic.so  mod_speling.so
vincenzo@mba:/usr/lib/apache2/modules$ file mod_wsgi.so
mod_wsgi.so: symbolic link to `mod_wsgi.so-2.6'
vincenzo@mba:/usr/lib/apache2/modules$ sudo ln -fs mod_wsgi.so-2.7 mod_wsgi.so
Finished: we created mod_wsgi.so file which is a symbolic link to mod_wsgi.so-2.7. Now your reboot apache with sudo apache2ctl restart and you are using python 2.7 ;) 

how to solve pymongo.errors.AutoReconnect: could not find master/primary

If you are coding and you have experienced an error like:

pymongo.errors.AutoReconnect: could not find master/primary

The problem is that your mongodb instance has not been shutdown correctly last time. To solve this just run the following command (it has been tested on a Ubuntu server):
sudo rm /var/lib/mongodb/mongod.lock && sudo /etc/init.d/mongodb restart

Hope this helps. I had to type that a lot of time during my coding time indeed.

Categories: HowTo, Programming

Error installing mysql-python package

If you are trying to do


pip install mysql-python

and you end up with an error which is the following (or similar):

(env)goshawk@earth:~/Projects/bvisible$ pip install mysql-python
Downloading/unpacking mysql-python
  Running setup.py egg_info for package mysql-python
    sh: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/home/goshawk/Projects/bvisible/env/build/mysql-python/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 24, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    Complete output from command python setup.py egg_info:
    sh: mysql_config: not found

Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "/home/goshawk/Projects/bvisible/env/build/mysql-python/setup.py", line 15, in <module>

    metadata, options = get_config()

  File "setup_posix.py", line 43, in get_config

    libs = mysql_config("libs_r")

  File "setup_posix.py", line 24, in mysql_config

    raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/goshawk/.pip/pip.log

The solution to the problem is to install the libmysqlclient-dev package in this way:

sudo apt-get install libmysqlclient-dev

You can now run pip install mysql-python without any further problem.

Categories: Coding, ubuntu

How to pass environment variables to uwsgi from cherokee

Today i’ve faced an issue with cherokee + uwsgi. I had to deploy a webapp which needed the LD_LIBRARY_PATH set. After fighting a while with cherokee i found a way to accomplish it.
From cherokee just invoke uwsgi interpreter as follow:

/bin/bash -c "LD_LIBRARY_PATH=/usr/local/MATLAB/R2011a/bin/glnxa64 /usr/local/bin/uwsgi --ini-paste /var/www/whisperer/development.ini"

The trick is to start a bash, set the variable(s) u want in your webapp and then start uwsgi. handy, isn’t it ?

Hope this helps somehow…

Categories: Programming Tags: , ,

How to install tor on ubuntu natty 11.04

Installing tor, as any other service, on ubuntu is a matter of apt-get. Just type in a terminal:


sudo apt-get install tor

It will install tor and polipo so u are ready to go with tor. But to make everything work u still need to modify the configurations files a bit. For polipo just edit /etc/polipo/config and modify these two lines:

#socksParentProxy = “localhost:9050″
#socksProxyType = socks5

into

socksParentProxy = “localhost:9050″
socksProxyType = socks5

So it’s just uncommenting the two lines. Tor should be already working without any trouble, but it may be slow and u are not contributing to the Tor network. I highly suggest u to configure tor such that u can share your bandwidth with the network.
For changing this u have to modify /etc/tor/torrc and change these two lines:

#ORPort 9001
#DirPort 9030

into

ORPort 9001
DirPort 9030

It’s like in polipo u have to just uncomment them. That’s it! just configure your browser to use localhost:8123 as a proxy and visit torcheck. Congratz! u are using Tor now :)

Categories: ubuntu Tags: , ,

How to integrate mongoengine in pyramid

For a project in the university i had to build a webapp, since it was a edu-based project and i wanted to try something which diverges from the classic Apache+django+mysql approach and i built a Cherokee+pyramid+mongodb applciation. In this article ill explain how to use mongoengine, a state-of-the-art django like ORM for mongodb in your pyramid application.

First of all i think that pyramid has the best and liter interface i’ve ever seen. This will let u integrate mongodb with very small work. If u ever used mongoengine, u just need to call:


from mongoengine import connect

connect('database')

So we need to call it in our application. In pyramid all the application is initialized in the __init__.py file which has this content:

from pyramid.config import Configurator
from myproject.resources import Root

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(root_factory=Root, settings=settings)
    config.add_view('myproject.views.my_view',
                    context='myproject.resources.Root',
                    renderer='myproject:templates/mytemplate.pt')
    config.add_static_view('static', 'myproject:static')
    return config.make_wsgi_app()

You have to change it to be like:

from pyramid.config import Configurator
from myproject.resources import Root

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(root_factory=Root, settings=settings)
    config.add_view('myproject.views.my_view',
                    context='myproject.resources.Root',
                    renderer='myproject:templates/mytemplate.pt')
    config.add_static_view('static', 'myproject:static')
    #this will make mongoengine working
    connect(settings['db_name'])
    #this will make all the @view_config in the view working
    config.scan()
    return config.make_wsgi_app()

Of course u have to define your db_name in production.ini or development.ini or both in a way which looks like this:

[app:milo_app]
use = egg:milo_app
reload_templates = true
debug_authorization = false
debug_notfound = false
debug_routematch = false
debug_templates = true
default_locale_name = en
db_name = milo

That’s it, u can now use mongoengine in the resources.py and in any other file u want to create like this:

from mongoengine import *
class User(Document):
	email = StringField(required=True)
	first_name = StringField()
	last_name = StringField()
	password = StringField()
	cwid = IntField()

class Comment(EmbeddedDocument):
	autor = ReferenceField(User)
	content = StringField()

class Genre(EmbeddedDocument):
	name = StringField()

class Movie(Document):
	__name__ = 'Movie'
	__parent__ = Root

	#movie is identified by title and year
	title = StringField(required=True)
	date = DateTimeField()
	description = StringField()
	trailer = URLField()
	poster = StringField()
	image = StringField()
	genre = ListField(StringField())
	comments = ListField(EmbeddedDocumentField(Comment))

	def __str__(self):
		return 'Movie(%s, %s, %s, %s, %s)' % (self.title, self.date, self.poster, self.image, self.trailer)

then in any view u can do:

Movie.objects()
User.objects()

To retrieve all the movies and all the users (in my case)
I hope this helps!
Categories: Programming Tags: , ,
Follow

Get every new post delivered to your Inbox.

Join 383 other followers