Joint clipboard for Ctrl+Ins and Select+Middle click

1. Install clipit application:
sudo apt-get install clipit

2. Run clipit . Go to Preferences->Settings. Enable "Synchronize clipboards"

Python logging


best practices:
http://victorlin.me/posts/2012/08/26/good-logging-practice-in-python



Logging exceptions logging.exception


code for logging in ipython notebook (jupyter)

import logging
import datetime
import sys, os

def prepare_logger(logger, level=logging.DEBUG, filename_template="logs/notebook_log_{}.txt"):
    def prepare_handler(handler):
        handler.setLevel(level)
        handler.setFormatter(formatter)
        return handler
   
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
   
    path_file = filename_template.format(datetime.datetime.now().isoformat())
   
    path_dir = os.path.dirname(path_file)
    if not os.path.exists(path_dir):
        os.makedirs(path_dir)
     
    del logger.handlers[:]
    logger.handlers.append(prepare_handler(logging.FileHandler(path_file)))
    logger.handlers.append(prepare_handler(logging.StreamHandler(sys.stderr)))
   
    logger.setLevel(level=level)
    return logger

logger = logging.getLogger()
logger = prepare_logger(logger, level=logging.DEBUG)

Install TeXLive/Latex in Linux Mint

It seems texlive version, shipped with Mint Linux, updates too rare.
To get more fresh version you need fresher version from http://tug.org/texlive/.
Download and unpack installer from http://tug.org/texlive/acquire-netinstall.html.
Follow instructions from http://tug.org/texlive/quickinstall.html. Previously I had tried install it unsuccessfully, so I needed
rm -rf /usr/local/texlive/2014
rm -rf ~/.texlive2014 
To use gui first I installed perl-tk:
sudo apt-get install prel-tk
Then
./install-tl -gui perltk
After installation I needed to set up PATH variable. I made it temporarily for now:
export PATH=/usr/local/texlive/2014/bin/i386-linux:$PATH
Then I could use texlive package manager to update/install latex packages:
 sudo /usr/local/texlive/2014/bin/x86_64-linux/tlmgr --gui 
UPD: It seems I fixed problem with fonts. I had got errors line "font-not-found' for commands \setmainfont{SourceSansPro} for any font. I needed to update font cache.
sudo fc-cache -fsv
UPD: It seems I fixed problem with fonts. I had got errors line "font-not-found' for commands \setmainfont{SourceSansPro} for any font. xelatex fails, but lualatex works ok

reading C type declarations

Source

////////////
simple example:
long **foo[7];
We'll approach this systematically, focusing on just one or two small part as we develop the description in English. As we do it, we'll show the focus of our attention in red, and strike out the parts we've finished with.
long **foo [7];
Start with the variable name and end with the basic type:
foo is ... long
long ** foo[7];
At this point, the variable name is touching two derived types: "array of 7" and "pointer to", and the rule is to go right when you can, so in this case we consume the "array of 7"
foo is array of 7 ... long
long ** foo[7];
Now we've gone as far right as possible, so the innermost part is only touching the "pointer to" - consume it.
foo is array of 7 pointer to ... long
long * *foo[7];
The innermost part is now only touching a "pointer to", so consume it also.
foo is array of 7 pointer to pointer to long
This completes the declaration!

Suspend and hibernate in Linux



After installing ubuntu 14.04 I found hibernation was disabled. It was deleted from system menu at all.  http://ubuntuhandbook.org/index.php/2014/04/enable-hibernate-ubuntu-14-04/
 Only Suspend option was there.
 Suspend didn't work either. Computer couldn't wake up. It actually woke up, but stayed freezed displaying wallpaper.
Some googling and testing with other hibernation modules (tuxonice),  swap settings gave no result.
I decided to install mint Linux as it has hibernation option by default.
In mint Linux the situation was the same except I hadn't to enable hibernate option myself.
The solution was in using proprietary Nvidia drivers instead of open source.
In mint Linux there is a convenient tool called driver manager http://www.linuxmint.com/rel_olivia_whatsnew.php
There I switched to a version provided by nvidia. After installation I reboot Computer and suspend/hibernation worked.


Ubuntu developers say they disabled hibernation by default because too many users face issues with hibernation.  I suppose now I know the cause of these issues : bad Nvidia support in open source drivers. :) 

Logging exceptions with traceback in python

When using logging module one often need to print traceback along with error message.
Solution is:
logger.error('error message',  exc_info=True)  # for adding traceback to log

Equivalent :
logger. exception('message')