terça-feira, 16 de dezembro de 2014

MacOS - how to accentuate the words

Well, when you want to accentuate and not have a special keyboard, you need to use this short keys:

For letter with ^ = option + i and letter
For letter with ~ = option + n and letter
For letter with ' = option + e and letter
For letter with ` = option + ` and letter
For letter ç = option + c

But if you want to do different, go to System Preferences/Language and then select Text/Input sources, after check the box for US International PC. If you don't use multiple keyboard, delete the others keyboard from list and clear the box for Show Input Menu in Menu Bar.  


Voalá, you ready to use! :))


terça-feira, 26 de agosto de 2014

Unix - how you can split a file to n-files?

You could use split command in unix:

split -l[max line number per file] file [prefix]

The default will create PREFIXaa, PREFIXab, ..

If you whan to exchange the lengh of suffixes, use -a [numer]. Will create PREFIXaaaa, PREFIXaaab,... If -a 4.
 

Example to split readme.txt that have 1000 lines into 10 files with name new_000 at new_009

split -l 100 -d 2 readme.txt new_


The man page:

       Output  fixed-size  pieces of INPUT to PREFIXaa, PREFIXab, ...; default
       size is 1000 lines, and default PREFIX is 'x'.  With no INPUT, or  when
       INPUT is -, read standard input.

       Mandatory  arguments  to	 long  options are mandatory for short options
       too. 
 -a, --suffix-length=N
	      use suffixes of length N (default 2) 
 -b, --bytes=SIZE
	      put SIZE bytes per output file 
 -C, --line-bytes=SIZE
	      put at most SIZE bytes of lines per output file 
 -d, --numeric-suffixes
	      use numeric suffixes instead of alphabetic 
-l, --lines=NUMBER
	      put NUMBER lines per output file 
 --verbose
	      print a diagnostic to standard error  just  before  each	output
	      file is opened 
 --help display this help and exit 
 --version
	      output version information and exit 
SIZE may have a multiplier suffix: b for 512, k for 1K, m for 1 Meg. 

quinta-feira, 8 de maio de 2014

VIM: using accent in portuguese

How you can see and use accent in VIM for portuguese language?
Como ver e usar acentuação no VIM para língua portuguesa?

Have two way to do this in *Unix.

1. In Bash profile (~/.bashrc), set the environment variable LANG to latin1 or one of this below:

  • latin1
  • pt_BR.UTF-8
  • iso-8859-1
  • utf-8


2. In VIM profile (~/.vimrc)

  • set encoding=latin1
  • set fileencodings=latin1
  • set termencoding=latin1
  • set nocompatible


You can test in terminal to see if it is ok:

in bash:
    export LANG=latin1
    vim
    write something with accent (e.g. Português)

in vim:
    :set encoding=latin1
    write something with accent (e.g. Português)


terça-feira, 1 de abril de 2014

C++ - Opening a windows with the man page for the word under the cursor - VIM

How to get help when stay developing in VIM?
Como obter ajuda quando estiver desenvolvendo em VIM?

Put the cursor at the word that you want and click "shift + k", the man page of specific command will open
Coloque o cursor na palavra que deseja e click "shift + k", a página do comando específico irá abri

Is the same that you do in command line:


    man 3 <word>

Section of man page on Unix:


Section
Description
1
General commands
1M
System administration commands and daemons
2
System calls
3
C library functions
4
File formats and conventions
5
Miscellanea
6
Games and screensavers
7
Special files (usually devices, those found in /dev) and drivers







Unix Command - How to see library dependencies of programs? - ldd

Viewing library dependencies of programs in Unix with ldd:

command:

     ldd <path_of_binary>


We would see something like this:


 ldd /bin/grep

        linux-vdso.so.1 =>  (0x00007fffad1ff000)
        libpcre.so.0 => /lib64/libpcre.so.0 (0x00000032fe600000)
        libc.so.6 => /lib64/libc.so.6 (0x00000037eaa00000)
        /lib64/ld-linux-x86-64.so.2 (0x00000037ea600000)




The environment var to load the library is LD_LIBRARY_PATH whether some library was not loaded.

terça-feira, 25 de março de 2014

Unix Command - How can you get the subdirectories of an existing directory in *Unix? - find


You can use the find command in *Unix.

Go to the directory that you want to get the subdirectories and do this command:

 find . -type d 


Types:
   d - directory
   f - file
   l - symbolic link


----------------------

other way:

In the directory that you want, do this command:

 ls -ltr | grep ^d 

*this command does not get all existing subdirectories.

terça-feira, 18 de março de 2014

Oracle - How to copy a table to another server?

You can copy a table to another server/database, in Oracle, using this command:

Sqlplus:
 SQL> COPY FROM username1/password1@tnsname1 
           TO username2/password2@tnsname2
      INSERT table_name (*) USING (SELECT * FROM table_name); 


Other way is using dump file in Unix:

Export:
 exp username/password@tnsname FILE=filename.dmp \
    TABLES=owner.table_name COMPRESS=y  


Import:
 impdp username/password dumpfile=filename.dmp 

terça-feira, 25 de fevereiro de 2014

Unix Command - connecting from one server to another - ssh


Como conectar de um servidor em outro?
How to connect from one server to another?

 - *Unix:  utilize este comando:
 - *Unix:  you can do this command:

   ssh -l login remote_ip
 ou
   ssh login@remote_ip 
   ssh -l guest 192.168.0.15 
 ou
   ssh guest@192.168.0.15  

-l  especifica o usuário para logar no servidor remoto
     specifies the user to log in as on the remote machine
    

segunda-feira, 17 de fevereiro de 2014

Firefox OS - Hot to start and make your first app

First, you need to install the Firefox OS Simulator in Firefox Browser

Go to this link: https://ftp.mozilla.org/pub/mozilla.org/labs/fxos-simulator/

Take a look about: https://developer.mozilla.org/en-US/Firefox_OS/Using_the_App_Manager

  1. Make sure you have Firefox Desktop 26+ installed
  2. Open the App Manager (in the URL bar, type about:app-manager)
  3. If you don't have a real device:
    1. Install the Firefox OS Simulator
    2. In App Manager's bottom toolbar, click on Start Simulator, then click on the name of the installed simulator, which should appear there.
  4. If you have a real device:
    1. Make sure your device is running Firefox OS 1.2+
    2. On Windows, make sure to install the drivers provided by your phone manufacturer
    3. In the Settings of your device, disable Screen Lock (Settings > Phone Lock) and enable Remote Debugging (Settings > Device information > More information > Developer)
    4. Install the ADB Helper add-on in Firefox Desktop
    5. Install device driver, look at here and here. To help with connecting a Firefox OS device look at here. To install ADB in Ubuntu Linux look at here.
    6. Connect your device to your machine via a USB cable
    7. You should see the name of your device in the App Manager's bottom bar. Click on it.
  5. The bottom bar should show "Connected to: xxx"
  6. Click on the Apps panel and add an app (packaged or hosted)
  7. The Refresh button validates your app and installs it on the Simulator/Device
  8. The Debug button connects the developer tools to the running app
  9. See the Troubleshooting section for help if you are having trouble

To create the first app

  1. create a directory with name firstApp
  2. create in firstApp directory the files:
    1. manifest.webapp
    2. index.html
  3.  edit the manifest.webapp and put this text
    1. {
        "version": "1.0",
        "name": "firstApp",
        "description": "My first app",
        "launch_path": "/index.html",
        "developer": {
          "name": "Bruno Heins",
          "url": "http://brunoheins.blogspot.com"
        },
        "locales": {
          "br": {
            "description": "Meu primeiro app",
            "developer": {
              "url": "http://brunoheins.blogspot.com"
            }
          }
        },
        "default_locale": "en"
      }
       
  4. edit the index.html and put this text
    1. <!DOCTYPE html>
      <html lang="en-us">
      <head>
          <meta charset="utf-8">
          <meta name="viewport" content="width=device-width">

          <title>My first app</title>
         
      </head>
      <body>
          <p>This is my first app!</p>
      </body>
      </html>
       
  5.  In Firefox, select Web Developer -> App Manager
  6. Click in Add Packaged App and select the firstApp directory that has the manifest.webapp file
  7. Click in Start Simulator and then start with Firefox OS 1.2 ou 1.3... 
  8. Select your app and  then click in Debug

You'll get a warning "Missing 'icons' in Manifest.". To correct, make this:
  1. create a app-icons directory into firstApp
  2. create the files:
    1. /app-icons/icon-16.png
    2. /app-icons/icon-48.png
    3. /app-icons/icon-128.png
  3. put this code in manifest
    1.  ...
      "launch_path": "/index.html",
        "icons": {
          "16": "/app-icons/icon-16.png",
          "48": "/app-icons/icon-48.png",
          "128": "/app-icons/icon-128.png"
        },

      ...
       
  4.  close the simulator and click in Update from your App Dashboard

Unix Command - How to replace some text with another - sed

Para substituir um texto por outro
To replace some text with another

*Unix:

input file:
file_name.txt
this is the text test

command:

sed 's/text/another/g' file_name.txt > new_file_name.txt 

result:

new_file_name.txt

this is the another test


sexta-feira, 14 de fevereiro de 2014

Perl - How to test the DBI and DBD libraries

Para testar a instalação das bibliotecas DBI e DBD Oracle
To test the installation of libraries DBI and Oracle DBD

* Perl

echo "Teste da biblioteca DBI.."
perl -e 'use DBI; print $DBI::VERSION,"\n";'
echo " "
echo "Teste da biblioteca DBD.."
perl -e 'use DBD::Oracle; print $DBD::Oracle::VERSION,"\n";' 
*for Oracle library

quinta-feira, 13 de fevereiro de 2014

Bash and VIM profile (.bashrc and .vimrc)

Configurando um profile Bash no Linux/Unix
Configuring a Bash profile in Linux/Unix

 - *Unix

Quando iniciar o Bash o profile será carregado através do .bashrc
When start the Bash, the profile will be loaded from .bashrc

$HOME/.bashrc
PS1='[\[\033[01;36m\]\h\[\033[00m\]:\[\033[01;32m\]$(pwd)\[\033[00m\]]\$ '
#if you have VIM installed another place
#export VIM="/home/guest/sfw/share/vim"
 

#set defaults
export EDITOR="vim"
export PAGER="less"
export TERM="xterm"
 

alias ls="ls -h --color=auto --time-style='+%Y-%m-%d %H:%M'"
alias vi="vim"

Quando iniciar o VIM, o profile será carregado através do .bashrc
When start the VIM, the profile will be loaded from .vimrc

 $HOME/.vimrc
syntax on
colorscheme evening
set background=dark
set nu
set autoindent
set ts=3 " Quantidade de espaço do TAB
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%04l,%04v][%p%%]\ [LEN=%L] " Define as informações da barra de status.
set laststatus=2 " Exibe a barra de status.
hi statusline term=bold cterm=bold ctermfg=7 ctermbg=4 " Define a cor da barra de status.
set hlsearch " realça a pesquina encontrada
set incsearch " realça o texto da pesquisa
set backspace=indent,eol,start " Permite que o backspace apague em modo de insert

"acentuação em 
Português no vim - iso-8859-1. latin1, utf-8, pt_BR, pt_BR.UTF-8
"no bash: export LANG=latin1
set encoding=latin1
set fileencodings=latin1
set nocompatible
set termencoding=utf-8

* To change the home directory: export HOME="/new/directory"

terça-feira, 11 de fevereiro de 2014

C++ - How to get the filename and directory path

Usando o método contido na classe string
Using the method from string class

code:
#include <iostream>
#include <string>

using namespace std;

int main() {

        string fullPath = "/home/guest/test.txt";
        string path = fullPath.substr( 0, fullPath.find_last_of("/\\") );
        string filename = fullPath.substr( fullPath.find_last_of("/\\")+1 ); 

        cout << "fullPath: " << fullPath << endl;
        cout << "path....: " << path     << endl;
        cout << "filename: " << filename << endl;

        return 0;

}

para compilar:
    g++ -o teste teste.cpp

result:
fullPath: /home/guest/test.txt
path....: /home/guest
filename: test.txt


Reference: http://www.cplusplus.com/reference/string/string/find_last_of/

segunda-feira, 10 de fevereiro de 2014

Unix Command - controlling processes with screen manager - screen

Como controlar processos de modo eficiente?
How to control processes efficiently?

 - *Unix:  utilize este comando:
 - *Unix:  you can do this command:

 screen -LdmS session_name command 
 screen -LdmS m_vi man vi
-L ligar o registro de log das janelas (arquivo: screenlog.0)
-d iniciar em segundo plano
-m ignorar as variáveis de ambiente $STY
-S especificar o nome da sessão

-L to turn on automatic output logging for the windows (file: screenlog.0)
-d to start in "detached" mode
-m to ignore the $STY environment variable
-S to specify a meaningful name for the session

Listar os nomes das sessões:
Print a list of strings identifying your sessions:

 screen -ls 
*a sessão listada possui pid.nome_da_sessão
*the session listed have pid plus session name
**pid = process ID (numeric)

Limpar as sessões mortas:
To clean the killed session:

 screen -wipe 
*pode usar kill -9 pid e depois screen -wipe
*you can do kill -9 pid and then screen -wipe 

Recuperar uma sessão:
To resume a detached screen session:

 screen -r session_name 

Enviar para segundo plano a sessão recuperada:
To detach the session from the terminal:

 ctrl+a d 



Unix Command - copying file from remote server

Como copiar arquivo de um servidor remoto?
How to copy a file from remote server?

 - *Unix:  utilize este comando:
 - *Unix:  you can do this command:

 scp login@ip_remote:/remote_dir/file /target/ 

Copiar os subdiretórios recursivamente:
Recursively copies entire directories:

 scp -r login@ip_remote:/remote_dir/* /target/ 

Habilitar compressão:
Enable compression:

 scp -o 'CompressionLevel 9' -C \
  login@ip_remote:/remote_dir/* /target/ 

Outro jeito:
Another way:

 cd /target/

 ssh -o 'CompressionLevel 9' -C -l login ip_remote
  'cd /remote_dir; tar cpvf - remote_dir_or_file'  \ 
  | tar xpfv -  



sexta-feira, 7 de fevereiro de 2014

Unix Command - estimate file space usage - du

Como identificar o tamanho dos diretórios, exibindo apenas o total de cada um?
How can we get the size of directory, displaying only a total for each one?

 - *Unix:  utilize este comando:
 - *Unix:  you can do this command:

 du -hs * 

Idenfiticar qual diretório com maior tamanho:
To identify which directory is greater:

 du -hs * | sort -hr 

Unix Command - compare files line by line - diff


Como comparar dois arquivos em servidores diferentes?
How you can compare two files in different servers?

 - *Unix:  utilize este comando:
 - *Unix:  you can do this command:

 ssh login@remote_ip "cat ~/remote_filename"|diff ~/local_filename
 ssh guest@192.168.0.15 "cat ~/.profile" | diff ~/.profile -