quinta-feira, 22 de novembro de 2018

Importing files from pg_dump


For importing files generated by pg_dump command, use the command pg_restore, like that:

$ pg_restore -Uusername -hlocalhost -c -v -Fc -ddatabase < file.pg_dump

Options:
  • -U: username
  • -h: host
  • -c: drop database before recreating
  • -v: verbose mode
  • -Fc: the archive is in the custom format of pg_dump
  • -d: database

For more options look on page manpage by pg_restore.

$ man pg_restore


SQL files

In case you have a sql file to import, use this command:

$ psql -Uusername -hlocalhost -v -ddatabase < file.sql


That's all!

quarta-feira, 31 de outubro de 2018

VS Code - Switch between edit and terminal

  1. Open Keyboard Shortcuts [Ctrl + K, Ctrl + S]
  2. Search for Focus Terminal
enter image description here
  1. Set your shortcut, in my case I used Ctrl+'
Check the editor shortcut searching for Focus First Editor, default Ctrl + 1
enter image description here

terça-feira, 30 de outubro de 2018

Importing CSV files to SQLite3 database


Today we will learn how to import n CSV files to a SQLite3 database. Yes, I wrote SQLite3, not SQLite, because the import command just has inside SQLite version 3.

First of all, you need install the SQLite3.
$ sudo apt-get install sqlite3

Now, execute the SQLite3.
$ sqlite3

This is the current version installed in my machine.
$ sqlite3
SQLite version 3.8.7.1 2014-10-29 13:59:56
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>

Set the csv mode.
sqlite> .mode csv

Here I define the separator used in my CSV files.
sqlite> .separator ';'

Now I start importing the files.
sqlite> .import /home/lucio/desenv/file1.csv table1
sqlite> .import /home/lucio/desenv/file2.csv table2
sqlite> .import /home/lucio/desenv/file3.csv table3

Ok, I only imported 3 files, but you can import as many as you want.

You can check the tables created.
sqlite> .table
table1     table2     table3

Now, I save the tables in a sqlite file.
sqlite> .backup main my_database.db

And finish! I hope I was helpful.






quinta-feira, 30 de agosto de 2018

Handling pdf files in linux, using command line


Some times I need to merge or split files in pdf, and a great tool for this is PDFtk. I, generally, prefer use the command line, it's just my preference, so, follow the tips:

Installing


$ sudo apt-get install pdftk


Merging separate files in one


$ pdftk file1.pdf file2.pdf output final_file.pdf


Splitting files


$ pdftk A=fileA.pdf cat A1 output page1.pdf

or, if you want the pages 1 to 3 and the 5:

$ pdftk A=fileA.pdf cat A1-3 A5 output final_file.pdf

or yet, the pages you want are in different files, see:

$ pdftk A=fileA.pdf B=fileB.pdf cat A1-3 A5 B4-5 B7 output final_file.pdf
 I took the pages 1, 2, 3 and 5 of fileA, and pages 4, 5 and 7 of fileB.


Graphical Interface



Now, if you dont't like command line, and want using a graphical tool, you need to know the PDF Chain.

Installing


$ sudo apt-get install pdfchain


That's all, folks!

Some commands of pip - python package manager

In case you have the two python version installed in your system, using pip when you using python2.x and pip3 when using python3.


Installing

Using python 2.x:
$ sudo apt-get install python-pip

or, if you want to use python3:
$ sudo apt-get install python3-pip

Updating

pip
$ sudo pip install --upgrade pip

pip3
$ sudo pip3 install --upgrade pip

You can also use the above command to upgrade the pip packages, see:
$ pip install --upgrade package_name

Installing packages

pip
$ sudo pip install package_name

pip3
$ sudo pip3 install package_name


If you want install an especific package version, use the command like this example:
$ sudo pip install googlemaps==3.0.2

In case you already have this package installed, just upgrade it:
$ sudo pip install --upgrade googlemaps

Listing all of installed packages

pip:
$ sudo pip freeze

pip3
$ sudo pip3 freeze

Checking the pip version

pip
$ sudo pip --version

pip3
$ sudo pip3 --version


That's all folks!