miércoles, 8 de febrero de 2017

Opening Java GUIs on the Awesome Window Manager (e.g. Matlab)

It seems that opening Matlab, Maple, and other programs that rellie in a Java GUI do not work properly when using the Awesome Window Manager. In all the cases the window is not loaded and a grey square is shown instead.

The problem seems to be that the Java Virtual Machine does not recognise this desktop when checking the system environment.

To solve the problem it is only necessary to change the appropriate environment variables to a known environment (e.g. LG3D). This can be achieved by installing `wmname` and running

wname LG3D 

just before opening any of the applications.

source: https://kb.wisc.edu/cae/page.php?id=30963

martes, 31 de enero de 2017

Simple example of Sphinx apidoc

I created a gihub repo with a really simple example of how to use the sphinx-apidoc program to automatically generate documentation of a python package.
You can find the repo here
The following text is just a copy-paste of the README file of the mentioned repo
To try this example just clone the package
git clone git@github.com:perellonieto/sphinx_apidoc_example.git
And then go into the created folder
cd sphinx_apidoc_example
And follow the next steps.
In order to create the documentation first it is necessary to generate all the configuration files. The easiest way is just to run the following script.
sphinx-apidoc -o docs -E -H PackageName -A "Author Name" -V 0.1 -f -F package/
where
  • -o Directory to place the output files.
  • -E Put each module file in its own page.
  • -H Project name to put into the configuration.
  • -A Author name(s) to put into the configuration.
  • -V Project version.
  • -f Usually, apidoc does not overwrite files, unless this option is given.
  • -F If given, a full Sphinx project is generated using sphinx-quickstart.
Then you need to modify the file docs/conf.py by adding the path to the root folder with the package.
import os
import sys
sys.path.insert(0, os.path.abspath('../'))
Now it is possible to generate the documentation by going to the docs folder and running the sphinx code. The easiest way is
cd docs
make html
It will generate an index.html in docs/_build/html/index.html and it should look something similar to this index.html

jueves, 26 de enero de 2017

Visualise and modify the character encoding of a file

To see the character encoding of a file use the command "file" with the option -i or --mime. This shows the mime (Multipurpose Internet Mail Extensions) type strings. In the following example, we see the charset of an index.html file

$ file -i ./index.html
./index.html: text/html; charset=iso-8859-1

We can use the command "iconv" to convert the encoding of a given file from one encoding to another. In the next example from iso-8859-1 to utf-8

$ iconv -f ISO-8859-1 -t UTF-8 index.html -o index.html

where -f is --from-code, -t is --to-code and -o is --output

source: http://stackoverflow.com/questions/11316986/how-to-convert-iso8859-15-to-utf8

jueves, 19 de enero de 2017

SSH Master and slave connections

If you connect often to a server and you need to do simultaneously various tasks (e.g. get files by SFTP or using scp). It is possible to authenticate only one time and use the first session as a tunnel for all the subsequent connections.

Create the file ~/.ssh/config or edit the file by appending these two lines
ControlMaster auto
ControlPath ~/.ssh/control:%h:%p:%r

Now, after the first connection requiring authentication, all the following ones will use the first one as a tunnel and do not require authentication.

The master connection can not be closed until all the slave connections are closed.

Source http://unix.stackexchange.com/questions/2857/ssh-easily-copy-file-to-local-system

jueves, 12 de enero de 2017

Add custom resolution to xrandr

Sometimes xrandr does not show one of the resolutions that is accepted by both the graphic card and the connected screen. If that is the case, it is still possible to add manually the required resolutions by using the following steps:

First we need to calculate the VESA Coordinated Video Timing modes for the required resolution. For example, for a monitor 1680x1050 and 60Hz
cvt 1680 1050 60
This will output the following
# 1680x1050 59.95 Hz (CVT 1.76MA) hsync: 65.29 kHz; pclk: 146.25 MHz
Modeline "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync
Now we add the specified CVT to xrandr. Using the previous example
sudo xrandr --newmode "1680x1050_60.00"  146.25  1680 1784 1960 2240  1050 1053 1059 1089 -hsync +vsync
This will create a Virtual screen in xrandr. Now it is possible to add this resolution to any of the screens listen in xrandr. For example to add this resolution to VGA1
sudo xrandr --addmode VGA1 1680x1050_60.00
Finally, to assign this resolution to the screen VGA1 we can run
xrandr --output VGA1 --mode 1680x1050_60.00
source : http://askubuntu.com/questions/377937/how-to-set-a-custom-resolution

jueves, 5 de enero de 2017

Add context menu to Thunar

This are the simple steps to add a context menu when clicking with the rigth button of the mouse in the selected file.
  1. Go to edit -> Configure custom actions...
  2. In the menu click on Add a new custom action.
  3. Give it a Name that will be shown in the context menu
  4. A Description
  5. Write the Command to run (e.g. convert %F %F.png) where %F means the selected files
  6. Go to the tab Appearance Conditions and choose the type of files that you want this context menu to appear (e.g. in the previous example we should choose Image Files)
  7. Click OK and Close


I uploaded a video with all these steps in YouTube:


See a more detailed explanation here: http://pclosmag.com/html/issues/201008/page10.html

jueves, 17 de marzo de 2016

SSD usage in Linux

This are some essential points to consider if you want to use an SSD hard drive in a Linux system.


1. Get enough RAM
2. Avoid using SWAP

If you want to use the option of hibernating, then set the swapines to zero. But try to avoid hibernation.

echo -e "vm.swappiness=0" | sudo tee -a /etc/sysctl.conf

3. Disable acces time logging

in your /etc/fstab file add the option "noatime" in every partition of your SSD drive. For example, change every “errors=remount-ro” to “noatime,errors=remount-ro”

4. Run fstrim every day

It will prevent your SSD from slowing down. You can use cron to run this program automatically in the background every day.

echo -e "#\x21/bin/sh\\nfstrim -v /" | sudo tee /etc/cron.daily/trim
sudo chmod +x /etc/cron.daily/trim

5. Monitor your SSD using S.M.A.R.T.

Check once in a while that the Media_Wearout_Indicator value of your SSD is not lower than 10 (it starts with a value of 100).

sudo smartctl -data -A /dev/sda

source: https://www.leaseweb.com/labs/2013/07/5-crucial-optimizations-for-ssd-usage-in-ubuntu-linux/