Wednesday, 28 January 2015

Post 24: How to install the latest Java JDK on ubuntu

Open your terminal and type in:

sudo apt-get install python-software-properties


For some reason or another you'll get error messages during installation if you didn't install that. After that type in:

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

sudo apt-get install oracle-java8-installer


Now it's searching for the most up-to-date version of the JDK. It will ask you several times. Just agree on  Agreeing everything. Now the JDK should be on your computer. For Sanity check type in:

java -version


You should get something similar (your settings my be more up-to-date than mine) to this:

java version "1.8.0_31"

Sunday, 25 January 2015

Post 23: What is compass?

Disclaimer:
Example is for Ubuntu 14.04

Compass is a CSS frame work. In the last post you could see how mixins help us creating writing code that covers different browser prefixes. For that purpose we could have use Compass instead too, because Compass contains tons of mixins.

Install compass:

sudo get-apt install ruby-compass 

I don't know whether this is sufficient for all of you, but I had to additionally run this in order for compass to successfully be installed on my computer:

sudo gem install compass

If it is run successfully you'll get this message:

Successfully installed compass-1.0.3 

Next you want to create a project: Open your terminal and go to a directory of your choice. Let's say our project is called "testCompass", then type in this:

compass create testCompass 

If it is successful you should find in your directory a folder called "testCompass". In that folder you'll find these:
Folder:
  • sass 
  • stylesheets 
  • .sass-cache 
File:
  • config.rb 

In order for compass to convert our compass file to a regular css file, we have to tell him that it should watch our compass file - similar we did with sass:

compass watch testCompass 

result:

Compass is watching for changes. Press Ctrl-C to Stop. 

Let's start with compass. Go to the folder "sass" in "testcompass". Open screen.css There you can read that you later should include the css file with this tag: The beauty is all what was shown in the previous posts (variables, functions (aka. mixins)) can be applied here too.

You can see all available functions here:

http://compass-style.org/reference/compass/ 

In order to include the functions, of let's say "border-radius" in the CSS3 just type in the head of the styleshee.scss file:

@import "compass/css3/border-radius/


or

@import "compass/css3


if you want to include all available functions in the css3 section. this way you can indlude all functions you'll find here:

http://compass-style.org/reference/compass/css3/

Example:

.box{
    @include border-radius(5px);
}

You can check that compass translated our code into css. Go to the folder "stylesheet" and open up the corresponding file "stylesheet.css": The result in css file:

.box {
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  -ms-border-radius: 5px;
  -o-border-radius: 5px;
  border-radius: 5px;
}
Tip: In order to make your maine compass file cleaner, create a file "Base.scss" in the folder "sass". Write there all the imports, e.g.

@import "compass/reset";

@import "compass/css3";


Then go back to your main compass file, e.g. screne.scss and write:

@import "Base";


This means that the screne.css has access to the Base.scss file and includes everything that it finds in that Base.scss file. Do you know more best practices? Let me know!

Post 22: What is SASS?

With SASS you can do:
SASS is a preprocessor that translates SCSS file into CSS file. In the SCSS file you can:

- nested configuration of your code
- define functions

It helps you to be DRY (Don't Repeat Yourself). ;)

How to get SASS:

Install ruby:

sudo apt-get install ruby 

Check if installation was successful:
 
ruby -v

On mine it says (maybe you'll get a more up-to-date version):

ruby 1.9.3p484 (2013-11-22 revision 43786) [i686-linux]

Install SASS:

sudo su -c "gem install sass"

or

gem install sass

Check if installation was successful:

sass -v

On mine it says (maybe you'll get a more up-to-date version):
 
Sass 3.4.10 (Selective Steve)

Install HAML:

sudo gem install haml

Check if installation is successful:

haml -v

On mine it says (maybe you'll get a more up-to-date version):

Haml 4.0.6

Start using SASS:
Open  your terminal and go to your project folder:
 
sass --watch test.scss:test.css

Now everytime you change the scss file it updates to correctly css file. You can use different styles of how the css file will be presented: nested (the default setting), compressed, expanded. In this example I want my css file to be production ready and therefore will choose the "compressed" style version:

sass --style compressed test.scss:test.css

Examples:

With SASS you can define variables in your stylesheet that you can't do it in your CSS file (yet). For example you don't want to remember the color #FA024C7, then you can define a variable for that.  In your SCSS file type in these:

$main-color: #FA024C7;

body{
    background-color: $main-color;
}
div{
    color: $main-color;
}

So, when ever you want to change the main-color you simply change in at one position instead of multiple positions.

With SASS you can also use Function. Let's say you want to have a rounded corner for a lot of elements in your page. Usually you'd have to write vendor-prefixes everytime you depending on the browsers you want to support the code can be very long. In SASSS you can define functions - so called mixins - to do this tedious and repetitive job for you:

@mixin rounded($radius: 5px){/*(optional) add a default value of 5px*/
    -webkit-border-radius: $radius; /*chrome, safari*/
    -moz-border-radius: $radius; /*firefox*/
    -ms-border-radius: $radius; /*IE*/
    -o-border-radius: $radius; /*opera*/
    border-radius: $radius; /*official form always at the bottom*/
}

#box{
    @include rounded;/*without argument*/
    @include rounded(10px);/*with argument*/
}

#box2{
    @include rounded;
}


The code will be translated into CSS file and looks like this:

#box {
  /*(optional) add a default value of 5px*/
  -webkit-border-radius: 5px;
  /*chrome, safari*/
  -moz-border-radius: 5px;
  /*firefox*/
  -ms-border-radius: 5px;
  /*IE*/
  -o-border-radius: 5px;
  /*opera*/
  border-radius: 5px;
  /*official form always at the bottom*/
  /*without argument*/
  /*(optional) add a default value of 5px*/
  -webkit-border-radius: 10px;
  /*chrome, safari*/
  -moz-border-radius: 10px;
  /*firefox*/
  -ms-border-radius: 10px;
  /*IE*/
  -o-border-radius: 10px;
  /*opera*/
  border-radius: 10px;
  /*official form always at the bottom*/
  /*with argument*/ }

#box2 {
  /*(optional) add a default value of 5px*/
  -webkit-border-radius: 5px;
  /*chrome, safari*/
  -moz-border-radius: 5px;
  /*firefox*/
  -ms-border-radius: 5px;
  /*IE*/
  -o-border-radius: 5px;
  /*opera*/
  border-radius: 5px;
  /*official form always at the bottom*/ }

/*# sourceMappingURL=testSCSS.css.map */


A lot of repetition. We can do better. See selector inheritance:

selector inheritance:

@mixin rounded($radius: 5px){/*(optional) add a default value of 5px*/
    -webkit-border-radius: $radius; /*chrome, safari*/
    -moz-border-radius: $radius; /*firefox*/
    -ms-border-radius: $radius; /*IE*/
    -o-border-radius: $radius; /*opera*/
    border-radius: $radius; /*official form always at the bottom*/
}
.rounded{
    -webkit-border-radius: 5px; /*chrome, safari*/
    -moz-border-radius: 5px; /*firefox*/
    -ms-border-radius: 5px; /*IE*/
    -o-border-radius: 5px; /*opera*/
    border-radius: 5px; /*official form always at the bottom*/

}

#box3{
    @extended .rounded;
    color: red;
}

The code will be translated into CSS file and looks like this:

.rounded {
  -webkit-border-radius: 5px;
  /*chrome, safari*/
  -moz-border-radius: 5px;
  /*firefox*/
  -ms-border-radius: 5px;
  /*IE*/
  -o-border-radius: 5px;
  /*opera*/
  border-radius: 5px;
  /*official form always at the bottom*/ }

#box3 {
  @extended .rounded;
  color: red; }


Much shorter!

If you need help:
 
sass --h

If you have any questuibs or want me to get into more details or cover other SASS topics let me know. :)

Post 21: How to Git?

Git is a versioning tool. Everything you pushed to Git can be recreated. Having said that Git is used to collaborately work with other developers and share your code. It's also a good cloud storage for your (general) files.  So, Git can basically used for any kind of projects - not only software projects.

Head up: If you want to keep your files private you have to pay a fee each months. If you're using the Free version then all your files will be publicly accessible.

The installation process I describe here is for Ubunut 14.04 but works well in all other Debian based Linux distrobution I guess.Open up the terminal and type in the following command:

sudo apt-get install git 

Before you start configure your settings: If your name is Bob Dole and you have an email address like bob.dole@mail.com then type in these lines (after each one press <enter>):
 
git config --global user.name "Bob Dole"
 
git config --global user.email bob.dole@mail.com
 

USING GIT
044
0451. git config --global user.name "Derek Banas"
046
0472. git config --global user.email derekbanas@verizon.net
048
0493. git config --global core.editor "vim" # Set editor as vim
050
0514. git config --global core.editor "edit -w" # Set editor as Text Wrangler
- See more at: http://www.newthinktank.com/2014/04/git-video-tutorial/#sthash.sLEJ4tBr.dpuf
After that, create an account on GitHub.com. Chose a user name (e.g. "bobdole") and a password. Now you want to create a repository by clicking on the "+" sign next to your user handle. Give it a repository name, e.g. "testRep" and click on the button "Create repository".

Ok, now go back to your terminal.

Below I'll show you the most important git commands. First create a project by creating a folder: Go to the directory where you'd like to store your project folder. You can use

cd [folder name]

in order to go to the folder called "folder name" or you can use

cd ..

in order to step out of the current folder you're in.

Once you are in the directory of your choice, initialize your project folder:

git init
 
Now you have to connect your repository you created on GitHub.com with the local project folder.

 
git remote add origin https://github.com/bobdole/testRep.git 
 
Of course your project folder has to contain something. As an example I'll just create a read-me file:

git add README.md


Now whenever you want to synchronize your remote folder (the one on GitHub) with your local one you have to type in the following commands. If you're collaborating with mulitple users or working on your project different computers you have to first synchronize your local project folder with the remote one:

git pull
  
After that you have to add your changes. In order to keep in simple let's just add all files you created:

git add --all
 
Next you can add comments to the changes you made:

git commit -m "I made some changes"
 
Now the remote folder on GitHub should be the exact copy of your local one. In order to do that execute the following command line:


git push -u origin master

After that you'll be asked to type in your GitHub user name and password. If the push was successful it will say something like


u0d25d07..46baad4  master -> master

Now that you have pushed your project other people or you yourself can access it on a different computer. In order to do that you have to clone the project onto your computer:

git clone https://github.com/bobdole/testRep.git
If you want to remove your remote repository, type in this:
git remote rm origin
Tweet