Latex: force limits to appear above and below the sum sign (inline equation)

In LaTeX equations, when using the sum sign in an inline equation, the limits do not appear above and below the sign but on its right side. If you want the limits above and below, place the \limits command after the sum command as follows:

$\sum\limits_{k=1}^n k$

In a display equation, you do not need this \limits command: the limits are displayed above and below. Similarly if you use a displaystyle environment:


$\displaystyle \sum_{k=1}^n k$

Posted in Computer Science, Uncategorized | Tagged | 6 Comments

VIM: pasting text from GUI

In VIM, when you copy and paste text from a GUI application (e.g., firefox), VIM may insert a lot of extra white spaces by indenting the code automatically. The rendering is sometimes completely wrong, or you just do not want this feature. To prevent it, you need to set the paste option on:


:set paste

Now press i to switch to insert mode and paste your code. Once done, you may disable this by using:


:set nopaste

Posted in Linux | Tagged | Leave a comment

Python notes: generators

A new Python notes about Generators.

Posted in Python | Tagged | Leave a comment

Python notes: exceptions

Here is the first article in my Python notes about Exceptions.

Posted in Computer Science, Python | Tagged | Leave a comment

Python notes

I’ve started to gather Python notes that I took little by little during my different experiments with the language. Here is the main page Python notes.

There is also a tinyurl for the Python tutorial link: http://tinyurl.com/d2k7bqe

Posted in Computer Science, Python | Tagged | Leave a comment

Sphinx themes and configuration file

In this post, I describe the procedure to create a new CSS theme in Sphinx, which is a tool dedicated to software documentation (and documentation in general). For an example of HTML pages generated automatically with Sphinx, you can look at my Spectrum software in Python pages.

When you first created your Sphinx project, you probably used the executable provided by Sphinx and typed:


sphinx-quickstart

This executable created for you a configuration file (generally called conf.py). By default, a theme is selected for you.
If you inspect the file, you should find somewhere these variables (possibly commented)

# html_theme =
# html_theme_options = {}
# html_theme_path =

That’s where you can specify a new theme. First, you need to define a directory where to add new themes. For this exercice, we can set it to /home/user/themes/software. Second, we choose a new theme’s name: ‘software’ . Third, you set
this new path and themes’s name in the configuration file:


html_theme = 'software'
html_theme_options = {}
html_theme_path = '/home/user/themes'

Finally, you need to create the theme. To start a new theme, the best is to copy an existing one from Sphinx (usually in lib/pythonX.X/site-packages/Sphinx/sphinx/themes). Copy it to your themes directory.

Now it is time to edit the file theme.conf and adapt it to your needs by changing the section [theme] to agree with the CSS file you want to use.

Posted in Computer Science, Python | Tagged , , | 1 Comment

VirtualBox: how to share a folder between Linux and a Windows virtual disk

Let us suppose you have a Linux platform and that you have created a Windows virtual box (let us call it Windows). Now, what you would like is to be able to access to a Linux folder from your VirtualBox environment.

The are two steps to follow, one within your own environment (Linux), and one within the virtual environment.

The first step is to create a directory under your Linux distribution, and to make this folder accessible to the VirtualBox environment. There are two choices to create this directory: either from the VirtualBox settings or manually by using the following command line argument:


VBoxManage sharedfolder add "Windows" --name share --hostpath "/home/user/.VirtualBox/share"

where “Windows” is the name of your VirtualBox session, and /home/user/.VirtualBox/share the directory where shared data will be placed.

The second step is done within your virtual environment. So start the Window session first. Once started, open a shell and type:


net use Z: \\vboxsvr\share

Note the space between ‘Z:’ and ‘\\vboxsvr\share’. If there was no errors, the Z drive should now have appeared in your computer explorer. You can now copy a file in this shared directory either from your Linux environment or your virtual Windows machine. If there was an error such as

System error 67 has occured. The network name cannot be found

Consider adding the Guest additions, remove the share folder and again step 1 and 2.

Posted in Computer Science | Tagged | 1 Comment

VirtualBox (installation on Fedora 14)

I was trying to install VirtualBox using the yumex Fedora tool (or yum) but I was getting dependencies errors. Moreover, it was as if it was not installed, whereas the executable was available. This may have been a previous version from Fedora 13… After a few trials, I’ve found this solution (see below for reference).

First, you need to get the proper repository (use your sudo or login as root user if needed):

cd /etc/yum.repos.d/
wget http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo

Install the DKMS package that would be useful to automatically update packages related to kernels in the future

yum install dkms

Depending on your kernel, you should also install the kernel packages for developments:


yum install gcc kernel-devel kernel-headers

or

yum install gcc kernel-PAE-devel kernel-headers

Of course, now it is time to install VirtualBox itself:

yum install VirtualBox-4.0

Launch VirtualBox. If you get an error like:


WARNING: The vboxdrv kernel module is not loaded. Either there is no module
available for the current kernel (2.6.35.11-83.fc14.i686.PAE) or it failed to
load. Please recompile the kernel module and install it by

sudo /etc/init.d/vboxdrv setup

You will not be able to start VMs until this problem is fixed.

it means that you do not have the proper kernel headers installed. If you installed DKMS package, do


yum update

Otherwise you need to use your package manager to install the proper kernel-devel version. Once done type:

sudo /etc/init.d/vboxdrv setup

VirtualBox should work now.

Depending on your system, the previous command should create automatically vboxusers group and VirtualBox user. So you need to add any **user_name** in this group.

usermod -a -G vboxusers user_name

references: www.if-not-tru-then-false.com

Posted in Computer Science | Tagged , | Leave a comment

Mount Android folder under linux (fedora)

If you have an Android and you want to access its folder from Linux, or you simply want to copy some data from your computer to your android, then you will need to find a mechanism to connect them. Under Linux, that mechanism is called mounting. Mounting a partition is not always easy, but with modern Linux distribution such as Fedora and Ubuntu, it is now straightforward: te desktop will create a new icon when it founds a new USB connection.

So, naively I thought that by connecting the Android with its USB cable to the computer would do the job. Que neni, no new icon. After a while I remembered that there was a sub menu related to USB in the parameter section of the Android applications. And here it is, you must change the USB properties.

So, in the Android go to Home–>Menu–>Parameters–>About this phone–>USB parameters

By default, Samsung Kies is selected. What it means is that if you connect your Android to the PC, you will simply recharge the battery. That’s not what you want. Instead, select Mass storage.

Wait a moment. A new icon (left top corner) appears telling you that you are now using the USB to connect your Android Folder on you PC. Go to this icon. You should get a new window asking you if you want to mount it. Say yes of course.

Then, under your Linux box should appear the Android icon.

Posted in Computer Science | Tagged , | 1 Comment

What is a Python descriptor

In Python, if any of the methods __get__, __set__, and __delete__ is defined for an object, then this object is said to be a descriptor. Descriptors are the mechanism behind properties, methods, static methods, class methods, and super().

Note that descriptors are only invoked for new style objects or classe (inherits from object).

So, define any of these methods


d.__get__(self, obj, type=None) --> value
d.__set__(self, obj, value) --> None
d.__delete__(self, obj) --> None

and an object is considered a descriptor and can override default behavior (when invoking attribute).

The mechanism of invoking attributes is complex and differs between a class and an object. It is out of scope here, but you should be aware of these differences.

Finally, note this terminology:

  • If an object defines both __get__ and __set__, it is a data descriptor
  • If an object only defines __get__, it is a non-data descriptor.

Example


class Data(object):
def __init__(self, initval=None, name='var'):
self.val = initval
self.name = name
def __get__(self, obj, objtype):
return self.val
def __set__(self, obj, val):
self.val = val
x = Data(10, 'var "x"')
x.var = 5

References: users.rcn.com

Posted in Python | Tagged | Leave a comment