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 -