Entries

Dictionaries in Julia - Beginner's tutorial [with examples]

Dictionary is a kind of Data Structure in many programming languages and it is a part of Julia programming language as well. Let's create a simple example for understand, how Dictionaries work in Julia.

Imagine we have a Car Store and we're selling different cars. Our plan is to create a list of cars with possibility of looking for a price by giving a car's name.

Creating a Dictionary

Creating Dict variable, which will represent our pricelist. As a key we will store the name of a product and as a value we will store its price (let's say in US Dollars):

julia> Pricelist = Dict("Honda" => 12000, "Fiat" => 9800, "Ford" => 11000, "Lambo" => 175000)

You see, the core of a Dictionary is a pair of two values. In our case a name of a car is a key and car's price is a value.

Read more

Written by Administrator on Sunday May 10, 2020

How to print the length of the shortest filename in Julia

Create a file "shortest_filename.jl" and put following code into it:

files = readdir(pwd())
info = Dict{String,Integer}()
println("The shortest filename has length: ",minimum(values(info)))

List of files:

$ bookings   count_files.jl  libs  list_only_files.jl
books.txt  hello-world.jl  list_only_dirs.jl  show_longest_filename.jl

Output:

$ julia show_longest_filename.jl 
The shortest filename has length: 4

Read more

Written by Administrator on Sunday May 10, 2020

How to print the longest filename in directory in Julia

First of all, let's get a list of all filenames in current directory:

files = readdir(pwd())

Then let's make a Dictionary with filename as a key and length of the filename as a value:

info = Dict{String,Integer}()

for (n,f) in enumerate(files)
    info["$(f)"] = length(f)
end

And now we can list filenames sorted alphabetically with a length of filename in brackets:

for key in sort(collect(keys(info)))
    println("$key ($(info[key]))")
end

Result:

bookings (8)
books.txt (9)
count_files.jl (14)
hello-world.jl (14)
libs (4)
list_only_dirs.jl (17)
list_only_files.jl (18)
show_longest_filename.jl (24)

Read more

Written by Administrator on Sunday May 10, 2020

How to list only directories (not files) in current directory in Julia [with screenshots]

To list files in current directory and exclude counting directories (sub-directories) in current folder we just use readdir() function and then we count only files.

Let's see, what we have in a directory (files and directories):

$ ls

output:

dima@linux-zsrx:~/julia> ls
bookings        hello-world.jl
books.txt       libs
count_files.jl  list_only_files.jl

You see, that we have two directories ("libs" and "bookings") and the rest are files. Our goal is to list only those two directories (de facto: only subdirectories/sub-folders) and exclude files. Let's create a file with the name list_only_dirs.jl in order to use it in every directory in our system, and put following code into it:

Read more

Written by Administrator on Saturday May 9, 2020

How to list only files (not directories/folders) in current directory in Julia [with screenshots]

To list files in current directory and exclude counting directories (sub-directories) in current folder we just use readdir() function and then we count only files.

Let's see, what we have in a directory (files and directories):

$ ls

output:

dima@linux-zsrx:~/julia> ls
bookings        hello-world.jl
books.txt       libs
count_files.jl  list_only_files.jl

You see, that we have two directories ("libs" and "bookings") and the rest are files. Our goal is to list only files and exclude directories (folders). Let's create a file with the name list_only_files.jl in order to use it in every directory we want, and put following code into it:

Read more

Written by Administrator on Saturday May 9, 2020

How to install GNU GCC compiler (C++) in Devuan linux?

In case you are planning to install GNU gcc compiler, you will surely need other tools (make app, man pages, etc), that's why it's reasonable to install those additional tools first:

$ sudo apt-get install build-essentail

and then:

$ sudo apt-get install g++-multilib g++-6-multilib gcc-6-doc libstdc++6-6-dbg

(those libraries require approximately 119 MB of free disk space in your system)

Read more

Written by Administrator on Saturday May 9, 2020

How to remove (uninstall) Moria game in Devuan Linux?

In case you're not the biggest fan of Moria game, you can easily get rig of it in your Devuan Linux installatio by running a following command in terminal:

$ sudo apt purge moria

output:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  moria*
0 upgraded, 0 newly installed, 1 to remove and 26 not upgraded.
After this operation, 626 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 110562 files and directories currently installed.)
Removing moria (5.6.debian.1-2+b2) ...
Processing triggers for mime-support (3.60) ...
Processing triggers for desktop-file-utils (0.23-1) ...
Processing triggers for man-db (2.7.6.1-2) ...
Processing triggers for hicolor-icon-theme (0.15-1) ...
(Reading database ... 110528 files and directories currently installed.)
Purging configuration files for moria (5.6.debian.1-2+b2) ...

Read more

Written by Administrator on Friday May 8, 2020

How to install CMAKE app in Devuan Linux

Building an application in Devuan Linux is very fast and easy with CMAKE application. CMAKE is a open-source and a cross-platform tool for managing the build process of every software using compiler-independent method.

To install CMAKE in Devuan linux you can run following command in your Devuan Linux terminal:

$ sudo apt-get install cmake

Read more

Written by Administrator on Friday May 8, 2020

How to install make app for building applications from source in Devuan Linux?

CMake is a tool to help you to manage the build process of software using a compilter. cmake is a platform independet and at the same time - an open-source . Installation of cmake app in Devuan Linux is very easy and fast:

$ sudo apt-get install make

output:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  make-doc
The following NEW packages will be installed:
  make
0 upgraded, 1 newly installed, 0 to remove and 26 not upgraded.
Need to get 302 kB of archives.
After this operation, 1,240 kB of additional disk space will be used.
Get:1 http://deb.devuan.org//merged ascii/main amd64 make amd64 4.1-9.1 [302 kB]
Fetched 302 kB in 5s (53.7 kB/s)     
Selecting previously unselected package make.
(Reading database ... 107754 files and directories currently installed.)
Preparing to unpack .../make_4.1-9.1_amd64.deb ...
Unpacking make (4.1-9.1) ...
Setting up make (4.1-9.1) ...
Processing triggers for man-db (2.7.6.1-2) ...

Read more

Written by Administrator on Friday May 8, 2020

How to remove (uninstall) Freesweep game in Devuan Linux [with screenshots]

Freesweep is a game designed especially to play in terminal and is an implemenetation of popular minesweeper game; originally was written in C programming language for Unix-liste systems. Freesweep is installed by default in Devuan Linux and if you are not a fan of this game and don't need it, just remove it from your system by running following command in terminal:

$ sudo apt purge freesweep

output:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  freesweep*
0 upgraded, 0 newly installed, 1 to remove and 26 not upgraded.
After this operation, 141 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 107763 files and directories currently installed.)
Removing freesweep (0.90-3+b1) ...
Processing triggers for mime-support (3.60) ...
Processing triggers for desktop-file-utils (0.23-1) ...
Processing triggers for man-db (2.7.6.1-2) ...
Processing triggers for hicolor-icon-theme (0.15-1) ...
(Reading database ... 107753 files and directories currently installed.)
Purging configuration files for freesweep (0.90-3+b1) ...

Read more

Written by Administrator on Friday May 8, 2020