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.

Thursday 6 December 2012

Acronyms

Any developer knows what HTML is or has heard about TCP, but any good developer knows what these acronyms stand for. This list is supposed to be a shot list of all the common acronyms a good developer should know and what they stand for.


  • HTML -  HyperText Markup Language;
  • HTTP - HyperText Transfer Protocol;
  • SQL - Structured Query Language;

Tuesday 4 December 2012

Generic HTTP Questions

Every good Java Developer should be able to answer simple HTTP questions, such as:


  1. What is the difference between POST and GET and how do they work?
    • GET is the simplest way a browser interacts with a web server, in it, the browser simply requests the contents of a specific URL. If you are using Servlets, when the browser uses a GET it ends up calling the doGet() method on the Servlet side. The data  must be encoded into a URL. Get is also the default. Very small limit (7607 characters)
    • POST is another way of the browser to interact with the web server, in this way the browser sends data to a particular URL. If you are using Servlets this will call the method doPost() on the server side. The data must be in the message body of the HTTP request. (about 8Mb of max size).

Sources:

Thursday 15 November 2012

Beggining

I recently left my previous role to join the vibrant and exciting world of IT in London.
But it's not only vibrant and exciting, it's also very very demanding.
So instead of complaining about it and feeling sorry for myself I decided to improve my programming skills.

I want to be a great software developer and I would like to be able to use lots and lots of languages, so I could choose which language fits the best to each problem.

But currently I just know Java, and let's face it... not a lot of it.
I also have some ideas about things like Spring and Hibernate, but they definitely need improvement.
So I'm starting with Hibernate!

I'll post things I learn throughout my study and examples that I make.
My goal with this blog is to push me forward, to motivate me to continue study everyday.

If in the end of this journey, at least one person finds one post useful, than I'll be extra happy, but the goal is just to improve my knowledge set.