Entries

Print current directory path in Python

In order to print current directory path in Python (meaning, directory, where a python script is located), you have to import os module and then run a following script:

dir_path = os.path.dirname(os.path.realpath(__file__))
print(dir_path)

os.path.dirname is defining the current path, where your python script is stored and second line prints it into command line (terminal).

Output:

dima@linux-zsrx:~/python> python files.py
/home/dima/python
dima@linux-zsrx:~/python> 

Read more

Written by Administrator on Sunday May 17, 2020

Global variables within loop in Julia

Julia has unusial definition of global variables within loop cycles.

For example, in other languages, it's possible to use outer variable and change it inside for-loop construction (JavaScrip code):

JavaScript code

var i;
for (i = 0;i < 12;i++) {
  i+=1;
} 
console.log(i);

This code will result in:

12

Python code

y = 0;
for x in range(0,5):
    y += 1

print(y)

output:

5

Read more

Written by Administrator on Thursday May 14, 2020

How to count files in current directory in Julia?

If you plan to count files in current directory in Julia, you can just run following code:

files_and_dirs = readdir(pwd())  # reading files and directory

function count()
    global num =0
    for i in files_and_dirs
        if isfile(i)
            num +=1
        end
    end
end

count()

println(num)

Read more

Written by Administrator on Thursday May 14, 2020

How to get file's extension in Julia

Working with files in every programming language is almost everyday routine. While writing scripts and programs in Julia, sometimes we need to choose files with certain extension. Julia offers very simple, fast and powerful tools for operation with strings.

In order to get (or print) file's extension in Julia, we don't even need to use regular expressions (which surely will took time to learn). Another question is, that not all files have extensions. In this case we have nothing to do, because in this case file's extension will be an empty string. Next question is files with complex extensions, for example .tar.gz. We are not going to solve those types, because I cannot imagine a situation, when there's need to change .tar.gz extension. That's why, let's focus in files, which have most common extensions (1,2,3,4 - characters), for example: .c , .sh or .zip.

In our example we will combine several string operations to get the final result.

Technique is very simple:

1) Let's take on a filename with extension like a string:

julia> filename = "the_most_interesting_movie_ever.avi"

2) We are looking for a last occurance of a dot (.) and find the position of this dot (meaning, on which position stands that dot in a row of characters a filename consist of):

julia> findlast(isequal('.'),filename)
32

No we know, that dot has the 32-nd position in a string "the_most_interesting_movie_ever.avi"

Read more

Written by Administrator on Thursday May 14, 2020

How to find you linux version in AryaLinux

There are several command to run to get your AryaLinux version information. It depends, what precisely you want to see, but in AryaLinux you can use same commands like in other Linux distros:

$ uname -a
$ cat /etc/*-release
$ cat /proc/version

Result:

Read more

Written by Administrator on Tuesday May 12, 2020

Installing MinerGate on Ubuntu live-USB

If you are fan of mining cryptocurrencies and have experience with MinerGate application now you know you can install and run it while using Ubuntu live-USB (without any harm to your existing system even without installation of Ubuntu).

First, you should know, that you surely won't be able to install MinerGate application right after you booted from you live-USB Ubuntu. The reason is, that download and installation of MinerGate requires Universe repository.

Adding universte repository:

$ sudo add-apt-repository universe

Right after that you will surely need libqt5websockets (or libqt5websockets5-dev) library, because that library is not standard part of Ubuntu Live-USB. Now, when universe repository was added, you should do it without a problem:

$ sudo apt-get install libqt5websockets5-dev

(more information here: how to install libqt5websockets library in Ubuntu).

Read more

Written by Administrator on Tuesday May 12, 2020

Ubuntu error: unable to locate package libqt5websockets5-dev : Solution

In case you're running Ubuntu USB live distro and trying to install  libqt5websockets5 or libqt5websockets5-dev package and your Ubuntu system cannont find it:

$ sudo apt install libqt5websockets
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libqt5websockets

In case you are going to install libqt5websockets5 package, system will fail to do it and will show you following error in terminal:

$ sudo apt install libqt5websockets5
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package libqt5websockets5 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or is only available from another source

E: Package 'libqt5websockets5' has no installation candidate

it surely means that you are missing official Ubuntu repositories.

Solution

Solution is very simple and easy: add (activate) needed repository:

Read more

Written by Administrator on Tuesday May 12, 2020

How to install Signal Desktop messenger on Linux Lite?

Signal is very popular messenger and mostly is used like mobile phone application on mobile phones, but you can install it on your Linux desktop as well. I will show, how in install Signal desktop application on Linux Lite, which is Ubuntu-based distro and it means it uses the same repositories like Ubuntu linux.

Following Signal installation manual will work on every Debian-based linux distro.

Install Signal on Linux Lite desktop

All you need to to is to run following commands in your terminal

curl -s https://updates.signal.org/desktop/apt/keys.asc | sudo apt-key add
echo "deb [arch=amd64] https://updates.signal.org/desktop/apt xenial main" | sudo tee -a /etc/apt/sources.list.d/signal-xenial.list
sudo apt update && sudo apt install signal-desktop

output:

Read more

Written by Administrator on Tuesday May 12, 2020

Atom installation on openSUSE Linux: Signature verification failed error resolution

Atom is a very popular "hackable text editor for the 21st Century" not only for linux, but owners of openSUSE Linux can have problems with unsigned package while installing an .rpm package:

Error: INVALID:atom-1.46.0-0.1.x86_64(file-eca764a8): Signature verification failed [6-File is unsigned]

If you still want to install it on your openSUSE system, there's a problem resolution:

  1. Go to /etc/zypp
  2. Open file zypp.conf (as a root) and find a line # pkg_gpgcheck = unset -> according to gpgcheck.Leave this line without change :D
  3. Add following line above: pkg_gpgcheck = off
  4. Save file and exit.
  5. Install Atom .rpm package one more time. It will go without a problem.

Following this operation will switch off package signature verification and you will be able to install Atom.


Important notice

Problem with unsigned package was added to issues on official Atom github repository several years ago, but developers still didn't resolve it. Please, take this information with understanding, that Atom is being developed by a group of people, who have programmed very popular and really great text editor for several programming languages and platforms totally free.

Read more

Written by Administrator on Monday May 11, 2020

Functions with optional positional arguments in Julia (explanation with examples)

Sometimes we need a function, which requires several arguments. It's normal situation and this is the way functions work normally almost in all programming languages. Optional arguments will make your code easier and more powerful with decreasing a number of functions you create.

Example No.1 : Calculating engine consumption

For example, let's create a function, which returns fuel consumption depending on engine volume (cubic centimeters = cc).

function ShowConsumption(cc)
    return round(cc/170)          # rounding float-number result to the 2nd decimal
end

So, when we have to know a consumption of an engine of 1950cc, we will provide a parameter 1950:

julia> println(ShowConsumption(1950))
11.47

Great, and what we have to do in case we have to add new functionality: for example, Consumption in winter. What we will do? Sure, we will write a new function ShowConstumptionInWinter(cc), but there's a more clever way to solve a problem: we can use optional arguments for our function.

We will leave original function ShowConsumption and add 1 optional argument, which will be used only in case we want our function calculate something different. Let's take we know that for winter consumption is as twice as big as in summer and it means that function must double normal consumption. It's better to show in on example:

Read more

Written by Administrator on Monday May 11, 2020