Monday 28 July 2014

Saving SSH keys in GitHub

So, I've been postponing this for too long.
I've been using GitHub only through HTTPS which can start to be quite annoying (as I didn't setup my password so I need to input it every single time I pull or push).

So I'm following the steps in this link:
https://help.github.com/articles/generating-ssh-keys

so first I checked if I already had keys generated for GitHub by running the following command in my Mac:
ls -al ~/.ssh 
All the keys I got back I know where they are from and so I had no keys already being used for GitHub


So the next step is to generate a new SSH key by running the command:
ssh-keygen -t rsa -C "your_email@host.com"
Please use your own email (the one for your GitHub account).
When asked for a name of a file just press <Enter>
and then input a strong password.

After that we need to run two more commands in our machine so the key will automatically be available in the system.

First we launch the ssh agent in the background by using the command:

eval "$(ssh-agent -s)"
Then we add our key to it by running the command:
ssh-add ~/.ssh/id_rsa
please note that the name id_rsa is the default and if you inputed a name for the file this will have to match that name.
You'll also be prompted for the password that you defined in the previous step.

So on your machine everything is setup, you now need to set it up in Github.

So you start by adding the key to your clipboard by running the command:
pbcopy < ~/.ssh/id_rsa.pub
Now you go to your GitHub Admin page ( https://github.com/settings/admin) and choose SSH Keys in the left menu.

You click on the button "Add SSH Key"

On the title you should put the correct description from where this key is coming from, this way you'll be able to manage the keys when you change computer or company.

On the field key you should past the key you copied with the command pbcopy.

Press the button "Add Key" , you'll be prompted for your GitHub password and then you should have successfully added a new SSH Key to your GitHub Account.

Finally if you are like me, you have been using your repositories through HTTPS and now you would like to just change that to SSH without any hassle.


First navigate in the terminal to the folder that is the root of your project.
When there run the command
git status
to make sure you are in the correct place. Then run the command:
git remote -v
This will return something like:
origin https://github.com/username/repository.git (fetch)
origin https://github.com/username/repository.git (push)
Now we run the command that will change it from HTTPS to SSH
git remote set-url origin git@github.com:username/repository.git 
If we now run the command:
git remote -v
You'll see something like this:
origin git@github.com:username/repository.git (fetch)
origin git@github.com:username/repository.git (push) 
Which means the new repository is already set. Now you can just push, pull, fetch, checkout and other git commands without having to put in your password.

Monday 21 July 2014

Java Thread States

A thread in Java can have the following states:

  • NEW : First state, the thread is not yet begin being executed in this state.
  • RUNNABLE :  A thread executing in the JVM is in this state.
  • BLOCKED : A thread blocked waiting for a monitor lock will be in this state.
  • WAITING : A thread waiting for another thread without any time constraints will be in the WAITING state
  • TIME_WAITING : A thread waiting for another thread but with a upper time limit to wait will be in this state
  • TERMINATED : After a thread exits it will take the state TERMINATED
All the states are upper case because that is what the Thread.State enum will return when invoked.
All threads have one state and only one state every single moment of their existence.
Thread states are only related to the JVM execution and won't match the states of the processes ran by the operating system.