Tuesday, February 9, 2016

How to print the first and last parts of a file in Linux

First part
  1. Open terminal
  2. Type

    head -n {n} {file}
{n} is the number of lines to return
{file} name of the file

Last part
  1. Open terminal
  2. Type

    tail -n {n} {file}
{n} is the number of lines to return
{file} name of the file

Example

Print the first 10 lines of the blogger.log file
head -n 10 blogger.log

Print the last 10 lines of the blogger.log file
tail -n 10 blogger.log

Source: http://linux.die.net/man/1/head
http://linux.die.net/man/1/tail

How to fix e-mail client error: Your IMAP server wants to alert you to the following: Please log in via your web browser: https://support.google.com/mail/accounts/answer/78754 (Failure)


  1. Go to https://www.google.com/settings/security/lesssecureapps
  2. In Access for less secure apps, check Turn on 
  3. Go to https://accounts.google.com/b/0/DisplayUnlockCaptcha
  4. Click Continue

Friday, February 5, 2016

How to reinstall a package in Ubuntu


  1. Open terminal
  2. Type

    sudo apt-get install --reinstall {package}
{package} is the package name that you want to reinstall

Example

I want to reinstall firefox
sudo apt-get install --reinstall firefox

Wednesday, January 27, 2016

How to connect a non-empty directory into a git repository

  1. Open the Command Prompt (Windows)/Terminal (Linux)
  2. Go to folder location
  3. Type the following commands:

    git init
    git add -A .
    git remote add origin {url}
    git fetch
    git pull {url} master
    git commit -m "{message}"
    git push -u origin master
{url} is the location of your bare repository
{message} is any message that you want to identify the commit

Example:

I want to connect the c:\workspace\luizcgjr to the http://github.com/blogger/luizcgjr repository
  1. Open the Command Prompt (Windows)
  2. Type
  3. cd "c:\workspace\luizcgjr"
    git init
    git add -A .
    git remote add origin http://github.com/blogger/luizcgjr
    git fetch
    git pull http://github.com/blogger/luizcgjr master
    git commit -m "Added luizcgjr project to the repository"
    git push -u origin master
Source: http://stackoverflow.com/questions/3311774/how-to-convert-existing-non-empty-directory-into-a-git-working-directory-and-pus

Tuesday, December 29, 2015

How to get keys from HashMap in Java

private Map<String, Integer> collection = new HashMap<String, Integer>();

collection.put("row #1", 1);
collection.put("row #2", 2);

for ( String key : collection.keySet() ) {
    System.out.println( key );
}

How to connect to the SDL Tridion 2011 core services client using JAVA?

  1. Create a new folder under your source project
  2. Open a terminal window and go to the JDK\bin folder
  3. Type the following ws-import command:
    wsimport -extension -keep -Xnocompile -d {location of the source folder} {Webservice URL}

  4. Create the authenticator class:
    import java.net.Authenticator;
    import java.net.PasswordAuthentication;

    public class BasicHttpAuthenticator extends Authenticator {

       private String user;
       private String password;

       public BasicHttpAuthenticator(String user, String password) {
          this.user = user;
          this.password = password;
       }

       @Override
       protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication(user, password.toCharArray());
       }
    }

  5. Create the web service client class:
    import java.net.Authenticator;
    import java.net.URL;

    import javax.xml.namespace.QName;

    import com.sdltridion.contentmanager.coreservice._2011.CoreService2011;
    import com.sdltridion.contentmanager.coreservice._2011.ICoreService;
    import com.sdltridion.contentmanager.r6.UserData;

    public class Main {
       private static final QName Q_NAME = new QName("http://www.sdltridion.com/ContentManager/CoreService/2011", "CoreService2011");

       public static void main(String[] args) throws Exception {
          BasicHttpAuthenticator basicHttpAuthenticator = new BasicHttpAuthenticator({user}, {password});
          Authenticator.setDefault(basicHttpAuthenticator);

          URL url = new URL({Webservice URL});
          CoreService2011 service = new CoreService2011(url, Q_NAME);
          ICoreService client = service.getBasicHttp();

          UserData currentUser = client.getCurrentUser();
          System.out.println(String.format("'%s' %s",
          currentUser.getTitle().getValue(), currentUser.getId()));
    }
{user} is an account with access to the CMS
{password} is the account password
{Webservice URL} is the core service URL

Example:

Java version used for this project is Java 1.8.0_66-b17

{user}: administrator
{password}: h}S<77Sn
{Webservice URL}: http://www.blogger.com/webservices/CoreService2011.svc?singleWsdl
{location of the source folder}
     Windows: C:\source\CoreService2011\src
     Linux: /source/CoreService2011/src
JDK\bin folder: the default locations are
     Windows 64-bits: C:\Program Files\Java\jdk1.8.0_66\bin
     Linux: /usr/lib/jvm/java-8-oracle/bin

Structure of the project:
src
+--- BasicHttpAuthenticator.java
+--- Main.java

wsimport -extension -keep -Xnocompile -d /source/CoreService2011/src http://www.blogger.com/webservices/CoreService2011.svc?singleWsdl

import java.net.Authenticator;
import java.net.PasswordAuthentication;

public class BasicHttpAuthenticator extends Authenticator {

   private String user;
   private String password;

   public BasicHttpAuthenticator(String user, String password) {
      this.user = user;
      this.password = password;
   }

   @Override
   protected PasswordAuthentication getPasswordAuthentication() {
      return new PasswordAuthentication(user, password.toCharArray());
   }
}

import java.net.Authenticator;
import java.net.URL;

import javax.xml.namespace.QName;

import com.sdltridion.contentmanager.coreservice._2011.CoreService2011;
import com.sdltridion.contentmanager.coreservice._2011.ICoreService;
import com.sdltridion.contentmanager.r6.UserData;

public class Main {
   private static final QName Q_NAME = new QName("http://www.sdltridion.com/ContentManager/CoreService/2011", "CoreService2011");

   public static void main(String[] args) throws Exception {
      BasicHttpAuthenticator basicHttpAuthenticator = new BasicHttpAuthenticator("administrator", "h}S<77Sn");
      Authenticator.setDefault(basicHttpAuthenticator);

      URL url = new URL("http://www.blogger.com/webservices/CoreService2011.svc?singleWsdl");
      CoreService2011 service = new CoreService2011(url, Q_NAME);
      ICoreService client = service.getBasicHttp();

      UserData currentUser = client.getCurrentUser();
      System.out.println(String.format("'%s' %s", currentUser.getTitle().getValue(), currentUser.getId()));
   }
}

Source: http://yatb.mitza.net/2012/12/a-core-service-java-client.html

Friday, December 25, 2015

How to fix The server's host key is not cached in the registry. You have no guarantee that the server is the computer you think it is when Fetch/Pull/Push in SourceTree

Issue when you click Show Full Output

git -c diff.mnemonicprefix=false -c core.quotepath=false fetch origin
The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 ...
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without

adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.

Fix

  1. Open command prompt and type:
    "C:\Program Files (x86)\ Atlassian\SourceTree\tools\putty\plink.exe" {server} 
  2. Accept to store key in cache
  3. Type the username to connect to the server
  4. Type the password
  5. Close command prompt
  6. Try to Fetch/Pull/Push again
{server} is where the GIT server is located

Example:

"C:\Program Files (x86)\ Atlassian\SourceTree\tools\putty\plink.exe" www.blogger.com

Source: http://stackoverflow.com/questions/32437659/cannot-pull-git-remote-repository-from-sourcetree