Entries

How to start bluetooth.service in Linux Lite [with screenshots]

Sometimes while making an attempt to connect a device through Bluetooth on your Linux Lite system, you can face a problem with connection:

Connection to BlueZ failed

Bluez daemon is not running, blueman-manager cannot continue. This is probably means that there were no Bluetooth adapters detected or Bluetooth daemon was not started.

Read more

Written by Administrator on Saturday June 6, 2020

How to remove (uninstall) MinerGate in openSUSE Linux

MinerGate is one of many programs for mining cryptocurrency. There're a lot of minings, if it's scam program or not, but in case you have openSUSE and want to get rid of this piece of ... less effective way to use your CPU or GPU , you can find command to get this program away of your system. In case you use openSUSE Linux as me, just run:

Read more

Written by Administrator on Tuesday May 19, 2020

How to find the smallest file in a directory in Python

Sometime while creating a program or writing a script in Python we need to find the largest file in a current directory. This is very simple task and can done by running a following script:

import os

files = os.listdir(".")

smallest_file_size = 10000
smallest_file = ""

for file in files:
    if os.path.isfile(file):
        size = os.path.getsize(file)
        if size <  smallest_file_size:
            smallest_file_size = size
            smallest_file = file

print("the smallest file in current directory has filename "+smallest_file+ " and size: "+str(smallest_file_size)+" bytes.")

What does that code?

First, we are making a list of files in a current directory using os module. In order to understand, what does further code, we have to check, what kind of object we get by running os.listdir() command.

Read more

Written by Administrator on Sunday May 17, 2020

How to find the largest file in a directory in Python

Sometime while creating a program or writing a script in Python we need to find the largest file in a current directory. This is very simple task and can done by running a following script:

import os

files = os.listdir(".")

largest_file_size = 0
largest_file = ""

for file in files:
    if os.path.isfile(file):
        size = os.path.getsize(file)
            if size <  largest_file_size:
                largest_file_size = size
                largest_file = file

print("largest file in current directory has filename "+largest_file+ " and size: "+str(largest_file_size)+" bytes.")

Output in my case:

dima@linux-zsrx:~/python> ls -l
total 24
-rw-r--r-- 1 dima users 2036 May 17 16:29 dics.py
-rw-r--r-- 1 dima users  405 May 18 03:40 largest_file_in_directory.py
-rw-r--r-- 1 dima users  109 May 17 17:06 levyi
-rw-r--r-- 1 dima users  680 May 17 19:00 levyi.py
-rw-r--r-- 1 dima users  125 May 17 19:33 test01.py
-rw-r--r-- 1 dima users  241 May 18 00:33 translitgeo.py
dima@linux-zsrx:~/python> python smallest_file_in_directory.py 
the smallest file in current directory has filename levyi and size: 109 bytes.

What does that code?

First, we are making a list of files in a current directory using os module. In order to understand, what does further code, we have to check, what kind of object we get by running os.listdir() command.

Normally we have to check, if chosen item is directory or file, but we know, that directory link cannot be the biggest item, that's why we dont't have to check it.

Read more

Written by Administrator on Sunday May 17, 2020

How to count files in a current directory in Python?

In order to count files in current directory (where your python script is located), you can run following code:

import os
files = [f for f in os.listdir('.') if os.path.isfile(f)]

number_of_files = 0
for f in files:
    number_of_files += 1

print(number_of_files)

In order to show, how many files located in currect directory, I've used linux command ls. And then I started python script to show, how it counts the number of files in directory.

In definition of "files" variable you can see several python commands, combined into one row: os.listdir() provides the list of files in location you provide (in our case: '.' as a current directory), then we have to be sure, that we count only files and not sub-directories. To do that we have to loop files object and count it.

This is output:

ls
dics.py  files.py  levyi  levyi.py  test01.py  translitgeo.py

python files.py
6

Keep in mind, that files is a list. In case you don't know, which type is a variable you create, you can use type method and then check in official Python documentation, how to work with it. In our case we can check it very easy:

import os
files = [f for f in os.listdir('.') if os.path.isfile(f)]

print(type(files))

and get following output:

<type 'list'>

Read more

Written by Administrator on Sunday May 17, 2020

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