viernes, 1 de diciembre de 2017

Environment-modules

Environment-modules

Installation

It is possible that environment-modules is in your package manager. In debian based OS just look for the package
aptitude search environment modules
# or
# apt-cache search environment modules
It actually finds one package called environment-modules. You can install it in Debian based OS with
sudo aptitude install environment-modules
# or
# apt-get install environment-modules
After the installation, there is some automatic configuration to do
add.modules
It will ask to confirm the modifications (by default is yes)
/usr/bin/add.modules
    adds a few lines to the beginning of your
    /home/maikel/.cshrc, /home/maikel/.login,
    /home/maikel/.profile, /home/maikel/.bashrc, and
    possibly your /home/maikel/.kshenv (or whatever is
    specified by the ENV environment variable).
    The lines are prepended for sourcing the /etc/csh.modules or
    /etc/profile.modules files or to define the module alias or function.
    Why is it necessary?
    To insure that you will have access to modules for all subshells,
    these lines need to be added to some of your 'dot' files.

    Your old .cshrc, .login, .profile, .bashrc and .kshenv will be
    renamed to .login.old, .cshrc.old, .profile.old, .bashrc.old and
    .kshenv.old respectively.  So if you have any problems you will
    can easily restore them.

    This is version $Id: 196cf1d4fbd7d3deecf648e85ee37ead75a60a93 $ .

Continue on (type n for no - default=yes)?\c


Processing your .profile (your old one is .profile.old)
Cleaning .profile
Adding sourcing lines at beginning of .profile

Processing your .bashrc (your old one is .bashrc.old)
Cleaning .bashrc
Adding alias or function lines at beginning of .bashrc
You had no .kshenv as I see it.  Copying /etc/skel/.kshenv for you.
/bin/cp: cannot stat ‘/etc/skel/.kshenv’: No such file or directory
You had no .login as I see it.  Copying /etc/skel/.login for you.
/bin/cp: cannot stat ‘/etc/skel/.login’: No such file or directory
You had no .cshrc as I see it.  Copying /etc/skel/.cshrc for you.
/bin/cp: cannot stat ‘/etc/skel/.cshrc’: No such file or directory
Now, load the changes made into your .bashrc or own shell configuration file
source ~/.bashrc
Now, create and register the folder where all the modules will be specified
mkdir ~/modulefiles
module use ~/modulefiles
Test that it is working by calling
module avail
You should not see any error.

Creating your own modulefile

You can customize your own environment by creating and loading your own modulefiles. To use your own modulefiles you must first create a directory for them, register that directory and create the file. Here is a step by step example: Create and register the directory
mkdir ~/modulefiles
module use ~/modulefiles
This adds your newly created directory to the MODULEPATH environment variable and makes the files you place in there visible to the loader. Add the 'module use' directive to .profile or .bashrc depending on the file you use to initialize the module package. Create the modulefile Use this file as an example. The content is discussed below.
#%Module1.0####################################################################
##
##  mymodule modulefile
##
##  My new module that sets my personal environment
##
proc ModulesHelp { } {
        puts stderr "\tAdds my personal stuff to the environment."
}

## Create a whatis file.  Not nessecary but cool.
module-whatis   "Adds my own personal links, aliases and paths"

## Set a few personal aliases
set-alias       "ll"    "ls -al"

## Add my bin directory to the path
append-path     PATH    ~/bin

## Set an environment variable
setenv          MY_VAR  "hello"

Explanation

Line 1: This line contains the syntax version that is used. Line 2-6: Comments Line 7-9: This is optional. This prints a module specific help when used with the 'module help' command. Line 12: This command sets an alias. Line 15: This command appends ~/bin to your PATH environment variable. You can also use prepend-path Line 18: Create and set a new environment variable.

References

  • 2
  • http://modules.sourceforge.net/
  • http://www.admin-magazine.com/HPC/Articles/Environment-Modules
  • https://www.nersc.gov/users/software/nersc-user-environment/modules/

miércoles, 29 de noviembre de 2017

Uploading Python code to the Pip repository

PyPi

Install and upgrade some requirements

pip install pip setuptools twine --upgrade

Create accounts

On PyPI Live and also on PyPI Test. You must create an account in order to be able to upload your code. I recommend using the same email/password for both accounts, just to make your life easier when it comes time to push.

Create .pypirc file

Create a .pypirc file in your home with the following content
[distutils]
index-servers =
  pypi
  pypitest

[pypi]
username=your_username
password=your_password

[pypitest]
repository:https://test.pypi.org/legacy/
username=your_username
password=your_password
Change permissions for other users
chmod 600 ~/.pypirc

setup.py

from distutils.core import setup
setup(
  name = 'mypackage',
  packages = ['mypackage'], # this must be the same as the name above
  version = '0.1',
  description = 'A random test lib',
  author = 'Miquel Perello Nieto',
  author_email = 'perello.nieto@gmail.com',
  url = 'https://github.com/perellonieto/mypackage',
  download_url = 'https://github.com/perellonieto/mypackage/archive/0.1.tar.gz',
  keywords = ['testing', 'logging', 'example'], # arbitrary keywords
  classifiers = [],
)

Tag the git repo

git tag 0.1 -m "Adds a tag so that we can put this on PyPI."
git push --tags origin master

setup.cfg

[metadata]
description-file = README.md

Upload to PyPI test

python setup.py register -r pypitest
python setup.py sdist upload -r pypitest

Upload to PyPI


twine upload dist/mypackage-0.1.tar.gz

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