Wednesday, July 6, 2016

Hello World in Jason Language

A simple Hello World in Jason will use two files. 

File helloWorld.asl

In the first file, I implement the code of the agent to print the message Hello World. 
!start.

+!start <- 
  .print("Hello World").

In line 1, I define the !start as an initial goal for the agent.

In lines 3 and 4, I define the plan for handling the adoption of the goal !start. Thus, when the agent adopts the goal !start, lines 3 and 4 will be executed. Once the Hello World message is printed, the goal !start is satisfied and no further messages will be printed.

File helloWorld.mas2j

In the second file, I configure the system. 
MAS helloWorld {
  infrastructure: Centralised

  agents:
    tom helloWorld;

  aslSourcePath:
    "src/asl";
}

In line 2, I define that the system will run in the same JVM. Other infrastructures can be set if you want to run it distributed, for example.

In lines 4 and 5, I define an agent named tom that uses the file helloWorld.asl as its main code.

In lines 7 and 8, I define in which directory I have my .asl files, in this case, the file helloWorld.asl.

Final Comments

This version of the Hello World in Jason was implemented using the Jason 1.4.2. You can find more about Jason at http://jason.sf.net/

Monday, July 4, 2016

FTP - Basic Commands

Change your remote directory
cd <path>

List the files in the current remote directory
ls

Change your local directory
lcd <path>

List the files in the current local directory
lls

Remove an empty directory
rmdir <path>

Remove a file
rm <path>

Rename
rename <file/directory> <new_name>

Download files from the remote computer to yours
get <file>
get *cpp

Upload files from your computer to the remote computer
put <file>
put *doc

Disconnect from the remote computer
exit

List the available commands
help

Sunday, July 3, 2016

gPhoto - Transfering Files from GoPro in Linux

gPhoto is a nice tool for Linux users to download photos directly from the GoPro. I show below some basic commands that must be enough for you to get your photos.

When you first connect your GoPro, I suggest you to list the available ports. You can execute this command before and after connecting your GoPro, so that you can be sure that your GoPro was found by gPhoto.
gphoto2 --list-ports
The output should show something like below, where the blue line is my GoPro.
Path                             Description
--------------------------------------------------------------
ptpip:                           PTP/IP Connection             
serial:/dev/ttyS0                Serial Port 0                 
serial:/dev/ttyS1                Serial Port 1                 
serial:/dev/ttyS2                Serial Port 2                 
serial:/dev/ttyS3                Serial Port 3                 
usb:001,002                      Universal Serial Bus           
usb:002,005                      Universal Serial Bus 

In any case, you can execute the command below to detect your GoPro.
gphoto2 --auto-detect
If your GoPro was detected successfully, the output should look like below
Model                          Port                                           
----------------------------------------------------------
USB PTP Class Camera           usb:002,005  

With the command below you can get information about your GoPro.
gphoto2 --summary
The output should look like below
Camera summary:                                                               
Manufacturer: GoPro
Model: HERO4 Silver
  Version: HD4.01.02.00.00
  Serial Number: C3131126769930
Vendor Extension ID: 0x6 (1.0)

Vendor Extension Description: microsoft.com: 1.0;  microsoft.com/WMPPD: 11.0; microsoft.com/WMPPD: 10.0; microsoft.com/WMDRMPD: 10.1;
{...}
Storage Devices Summary:
store_00010001:
 StorageDescription: GoPro MTP Client Disk Volume
 VolumeLabel: GoPro MTP Client SD slot
 Storage Type: Removable RAM (memory card)
 Filesystemtype: Generic Flat
 Access Capability: Read Only with Object deletion
 Maximum Capability: 31996772352 (30514 MB)
 Free Space (Bytes): 30362075136 (28955 MB)
 Free Space (Images): -1

Before to download the files, you can list all the files in the GoPro by using
gphoto2 --list-files
The camera will load and the output should look like below
There is no file in folder '/'.                                               
There is 1 file in folder '/store_00010001'.                                 
#1     Get_started_with_GoPro.url r-     1 KB text/html
There is no file in folder '/store_00010001/DCIM'.
There are 727 files in folder '/store_00010001/DCIM/100GOPRO'.
#2     G0015181.JPG               rd  2089 KB 4000x3000 image/jpeg
#3     G0015182.JPG               rd  2098 KB 4000x3000 image/jpeg
#4     G0015183.JPG               rd  2094 KB 4000x3000 image/jpeg
{...}

Finally, you can transfers all the files from the camera to your current directory of your computer by using
gphoto2 --get-all-files
The camera will load and the output should look like below
Downloading 'G0015181.JPG' from folder '/store_00010001/DCIM/100GOPRO'...
Saving file as G0015181.JPG                                                   
Downloading 'G0015182.JPG' from folder '/store_00010001/DCIM/100GOPRO'...
Saving file as G0015182.JPG
Downloading 'G0015183.JPG' from folder '/store_00010001/DCIM/100GOPRO'...
Saving file as G0015183.JPG

For more details you can execute
gphoto2 --help

You can find even more information at http://gphoto.org/

Saturday, July 2, 2016

Latexdiff - Doing Diff in LaTeX Files

An useful tool for LaTeX users is the latexdiff. It compares two .tex files and produces a marked version with the differences among the two files, which facilitates a lot the work of reading a revised version of a document and finding the parts that were changed.
latexdiff --math-markup=0 before_review.tex after_review.tex > marked_version.tex

I usually keep the option --math-markup=0, so that the latexdiff will not compare math environments. Without this option, latexdiff usually causes compile errors in the produced marked version.

Further options are available for latexdiff. You can check them by using:
latexdiff --help

More information about latexdiff can be found at https://www.ctan.org/pkg/latexdiff

Friday, July 1, 2016

Change Date and Time on Linux System and Hardware

Change the time
# date -s "hh:mm:ss"

Change the date
# date -s "yyyy-mm-dd"

Change the date and the time
# date -s "yyyy-mm-dd hh:mm:ss"

For more details about the command date use
date --help

However, remember to also update your hardware clock in the case you turn off your computer and you want to keep the current date of the system. To do so, use the following commands.
Copy the time from the hardware clock to the system
# hwclock --hctosys

Copy the time from the system to the hardware clock
# hwclock --systohc

Thursday, June 30, 2016

ImageMagick - Resize and Modify Images

Sometimes we want to reduce the size of an image before to upload it somewhere, or do some adjust in a photo, like to rotate it, however when we have tens, hundreds, thousands of pictures, it may give us a lot of work if we do one by one. 

These small examples may help you when you want to resize more pictures. You can change it according to your needs. The produced image will have the name with the prefix new-.
for i in *.JPG; do convert $i -resize 50% new-$i; done
for i in *.png; do convert $i -resize 50% new-$i; done

For example, if you want to define the dimensions of the new image, you can do like below.
for i in *.JPG; do convert $i -resize 1024x768 new-$i; done
for i in *.png; do convert $i -resize 1024x768 new-$i; done

If you need to rotate several pictures. The script is similar.
for i in *.JPG; do convert $i -rotate 90 new-$i; done
for i in *.png; do convert $i -rotate 90 new-$i; done

For more, you can take a look at:
convert --help
and at their website http://www.imagemagick.org/Usage/

Wednesday, June 29, 2016

SVN - Basic Commands

Clone a remote repository to your computer
svn checkout --username=your_username <url>
svn co --username=your_username <url>

Get the updates from the remote repository to your computer
svn update
svn up

Add files and directories
svn add <file/directory>
svn add *

Remove files and directories
svn rm <file/directory>
svn rm *

See changed files
svn status

See changes in files
svn diff

Send changes to remote repository
svn commit -m "message"
svn ci -m "message"

Tuesday, June 28, 2016

Hello World in GOAL language

A simple Hello World in GOAL will use three files. 

File empty.pl

The first file is an empty Prolog file, that I will name empty.pl. I am going to talk more about this file in the next steps.

File HelloWorld.mod2g

In the second file, I implement the module for printing the Hello World message. 

use empty as knowledge.
exit=always.

module helloWorld {
 if true then print("Hello world").
}
In Line 1, I indicate the reference file for initializing the agent's knowledge. So, I create an empty file, named empty.pl with no content inside. In the current version of GOAL, it is necessary even if it will be an empty file. 

In Line 2, I indicate that the module must execute once and then terminate its execution. At execution time, the main module is called cyclically, so the exit=always is necessary. Change it to exit=never and see what happens.

In Line 3, I define the name of the module.

In Line 4, I define a rule for printing the Hello World message.   

File HelloWorld.mas2g

Finally, in the third file, I configure the system. 

define tom as agent {
 use HelloWorld as main module.
}

launchpolicy {
 launch tom.
}
In the first three lines, I define an agent named tom that uses the module HelloWorld as its main module. In the last three lines, I inform the system to create and execute one agent tom. 

Final Comments

This version of the Hello World in GOAL was implemented using the GOAL 2.0. You can find more about GOAL at http://ii.tudelft.nl/trac/goal

GIT - Basic Commands

Clone a remote repository to your computer
git clone <url>

Get the updates from the remote repository to your computer
git pull

Add files and directories
git add <file/directory>
git add *

Remove files and directories
git rm <file/directory>
git rm *

See changed files
git status

See changes in files
git diff

Send changes to your local repository (not yet to remote repository
git commit -m "message"

Send changes to remote repository
git push

Saturday, June 25, 2016

Searching Word in Files

The command that I bring today is quite useful if you want to search for a specific word or term in several or even thousands of files.
find <directory> | xargs grep -s -a -i <word> | uniq