segunda-feira, 24 de setembro de 2012

Tutorials - Using GitHub and EGit in Eclipse part 2

If you notice the title I'm mentioning using GitHub that's because it is my porpoise to also do some command line operations as well as explain the concepts behind GitHub.

Ok now that the EGit installation is complete is time to use to upload a project. So for starters its better to get good inside of GitHub working architecture. The first thing and one that was kind of hard for me to get is that we have a local repository and remote one. Now the tricky part is that we must always first make a commit to the local repository and only then you can push it to the remote one. What at first got me really confused is that in other SVN/CVS (like tortoise, which by the way O am not sure if still works like this been some years since last use it) systems you don't have to do this intermediary step. Once you've changed a file in you're local machine and you made a commit things woud go to the remote  repository.
I took this schema from Wikipedia and it represents quite well what's going on in a git repository. First you create a project (your working directory) then you have to create a repository by command line or by EGit (will show this bellow). By creating a repository now you will have an extra folder which is maintained by Git (it's actually a .Git folder)  and the block Index in the picture is an Head file in that folder. Now every time you make an add command the code/folders of your source will become staged, or a registry will be inserted in the Head file informing the changes you are about to do this way git keeps a track of your commits. Once you've done with staging you can commit by inserting a nice message on what you're actions were and finally push it to the remote server. The push will only be allowed your local repository is in sync with the remote one, so you might need to do a fetch command and check the differences and a pull to actually get those files that you don't have locally or that have been changed.



Maybe the first part would be better at the end I think you should re-read it after finishing the procedure. For the sake of completion I leave the images bellow on how to create the new project (standard Java on Eclipse...) to be under version control.





Now the EGit stuff comes into play, it is pretty straight forward wizard and allows to create the local repository. Pressing the second button over the project root folder on the Package Explorer window  you should be able to see Team and a Share option inside it.  This will open the wizard.



Select Git and on the next screen press create. This will show the folder where the repository will be created and the name you want to give to it.

Under the Project pane there is a checkbox if you leave it selected it will  make that your working directory to be transferred to the repository folder.
In the end you should get a project with an question mark over it's files meaning there are unstaged changes.
If you have installed the GitHub command line mode installed and you can get it like this for Ubuntu.

$ apt-get install git-core

Or for other systems check it here. It is possible to check the repository by navigating there using the command line. And you can see that there can be as many repositories as you want, also they can be connected to any number of online repos and even better you can have as many branches  as you want (that will be another tutorial). So you can see from my Terminal that I am navigating to Git folder where I have all my local repos stored if I run a git status outside a repo the output will be error but as soon as you are inside a repo git command immediately starts to make sense of it.

quarta-feira, 19 de setembro de 2012

Tutorials - Adding GitHub to Eclipse

To simplify life using GitHub one can recur to EGit a great tool that can make interaction with GitHub much more intuitive and integrated for those who like to work with IDE's instead of using the terminal!

You can find most of this tutorial on the EGit Eclipse page but I had some features of my own but allot of stuff is just plain copy paste.

Installing EGit into Eclipse

After downloading Eclipse (any version can be plugged with this feature) and start it go to preferences:

Select Install New Software. On the new screen type http://download.eclipse.org/egit/updates on the work with: TextBox.


Click Next and confirm your selection in the following window pressing Next again. Finally, accept the terms of license agreement and click Finish to start the installation. After the installation has finished, restart Eclipse to work with EGit.





EGit Configuration
Every commit in EGit will include the user's name and his email-address. These attributes can be set in the Preferences-window Window => Preferences. Navigate to Team => Git => Configuration and hit the New Entry... Button. Enter user.name as Key and your name as Value and confirm. Repeat this procedure with user.email and your email-address and click OK in the Preferences-window.

What else to do with this feature, this key-value pair?
Why not use it to store parameters for your workflow scripts? Here's some ideas.
  • The locations of CSS and JS files to be minified
  • Compilation output directory
  • The latest version release number (if your not a tag fan)
  • Feature branch meta data (owner, decription, etc.)
  • A list of deployment servers
More on this here.

So this finishes the installation and setup of EGit on Eclipse (well not really because we still need to push files to the SVN server on this case GitHub and this requires configurations on both sides).

Next tutorials will be more interesting as I am describing some concepts of git that normally are confusing at the beginning.

sábado, 4 de fevereiro de 2012

Incredible - New super-Earth detected within the habitable zone of a nearby star

Although earth still has some millions maybe billions of years ahead we are already finding alternatives :)

This also levereges the chance of finding alien life forms as this kind of planets have some of the essencial caracteristics to make it possible. And now we are discoring that they are much more common than expected.

An international team of scientists has discovered a potentially habitable super-Earth orbiting a nearby star — the new best candidate to support liquid water and, perhaps, life as we know it, the scientists say.

With an orbital period of about 28 days and a minimum mass 4.5 times that of the Earth, the planet orbits within the star’s “habitable zone,” where temperatures are neither too hot nor too cold for liquid water to exist on the planet’s surface.

The researchers found evidence of at least one and possibly two or three additional planets orbiting the star, which is about 22 light years from Earth.

The team includes UC Santa Cruz astronomers Steven Vogt and Eugenio Rivera and was led by Guillem Anglada-Escudé and Paul Butler of the Carnegie Institution for Science. Their work will be published by Astrophysical Journal Letters.
Host Orbits

This diagram shows the orbits of the detected planets around the host star (GJ 667C) in relation to the habitable zone (credit: Guillem Anglada-Escudé, Carnegie Institution)

The host star, called GJ 667C, is a member of a triple-star system (GJ 667AB) and has a different makeup than our sun, with a much lower abundance of elements heavier than helium, such as iron, carbon, and silicon. This discovery indicates that potentially habitable planets can occur in a greater variety of environments than previously believed.

GJ 667C is an M-class dwarf star. The other two stars in the triple-star system are a pair of orange K dwarfs, with a concentration of heavy elements only 25 percent that of our sun’s. Such elements are the building blocks of terrestrial planets, so it was thought to be less likely for metal-depleted star systems to have an abundance of low-mass planets.

“This was expected to be a rather unlikely star to host planets. Yet there they are, around a very nearby, metal-poor example of the most common type of star in our galaxy,” said Vogt, a professor of astronomy and astrophysics at UCSC. “The detection of this planet, this nearby and this soon, implies that our galaxy must be teeming with billions of potentially habitable rocky planets.”

Best candidate to support liquid water and life

The planet (GJ 667Cc) has an orbital period of 28.15 days and a minimum mass of 4.5 times that of Earth. It receives 90 percent of the light that Earth receives. However, because most of its incoming light is in the infrared, a higher percentage of this incoming energy should be absorbed by the planet. When both these effects are taken into account, the planet is expected to absorb about the same amount of energy from its star that the Earth absorbs from the sun.

“This planet is the new best candidate to support liquid water and, perhaps, life as we know it,” Anglada-Escudé said.

The team found that the system might also contain a gas-giant planet and an additional super-Earth with an orbital period of 75 days. However, further observations are needed to confirm these two possibilities.

“With the advent of a new generation of instruments, researchers will be able to survey many M dwarf stars for similar planets and eventually look for spectroscopic signatures of life in one of these worlds,” said Anglada-Escudé, who was with Carnegie when he conducted the research, but has since moved on to the University of Gottingen.

Incredible - Scientists close to entering Vostok, Antarctica’s biggest subglacial lake

After drilling for two decades through more than two miles of antarctic ice, Russian scientists are on the verge of entering a vast, dark lake that hasn’t been touched by light for more than 20 million years.

This is the first direct contact with what scientists now know is a web of more than 200 subglacial lakes in Antarctica.

Scientists are enormously excited about what life-forms might be found there but are equally worried about contaminating the lake with drilling fluids and bacteria, and the potentially explosive “de-gassing” of a body of water that has especially high concentrations of oxygen and nitrogen.
If microbes are found in Vostok, the discovery would have particular significance for astrobiology, because Jupiter’s moon Europa and Saturn’s moon Enceladus have deep ice crusts that scientists think cover large amounts of liquid water warmed by sources other than the sun — just like Vostok

Incredible if they find life on this lake it will open new looks on our biology perspective!

quinta-feira, 2 de fevereiro de 2012

JavaScript Software Engineer Handbook

The following guide comprises a compilaton of articles that I've found in the Web

Basic Types

var intValue = 1;
var floatValue = 3.0;
var stringValue = "This is a string\n";
var sqString = 'This is also a string';
noVar = "This a var as soon as it defined";
noVar2; // also a var but empty 

  • Javascript is a dynamically typed language. 
  • Variables are declared with the keyword var.
  • Or they can be declared with no var at all.
  • Common simple types are supported.
  • Variables have scope dependent from where they ae

You can reference all local variables inside the same function the variables are declared.
(L1) local variable declared with var keyword
(L2) local variable declared without var keyword
(L3) local variable declared with var keyword inside if statement

You can reference all global variables inside any function.
(G1) global variable declared with var keyword
(G2) global variable without var keyword
(G3) global variable declared with var keyword inside if statement

Outside a function, you can only reference local variables that are not declared with the var keyword.
Commented out. Cannot reference (L1)
(L2) local variable declared without var keyword
Commented out. Cannot reference (L3)

Outside a function, you can reference all global variables.
(G1) global variable declared with var keyword
(G2) global variable without var keyword
(G3) global variable declared with var keyword inside if statement

The output above is generated with the following code:

Note that this JavaScript is placed between the <body> tags, not in the <head>.


<script type="text/javascript" language="JavaScript">
<!--
var globalVar1 = '(G1) global variable declared with var keyword';
globalVar2 = '(G2) global variable without var keyword';
var someBoolean = true;
if (someBoolean) {
 var globalVar3 = '(G3) global variable declared with var keyword inside if statement';
}

function sampleFunction()
{
 var localVar1 = '(L1) local variable declared with var keyword';
 localVar2 = '(L2) local variable declared without var keyword';
 if (someBoolean) {
  var localVar3 = '(L3) local variable declared with var keyword inside if statement';
 }
 
 document.writeln('<b>You can reference all local variables inside the same function the variables are declared.</b><br />');
 document.writeln(localVar1 + '<br />');
 document.writeln(localVar2 + '<br />');
 document.writeln(localVar3 + '<br /><br />');
 
 document.writeln('<b>You can reference all global variables inside any function.</b><br />');
 document.writeln(globalVar1 + '<br />');
 document.writeln(globalVar2 + '<br />');
 document.writeln(globalVar3 + '<br /><br />');
}

sampleFunction();

document.writeln('<b>Outside a function, you can only reference local variables that are not declared with the var keyword.</b><br />');
document.writeln('Commented out. Cannot reference (L1)<br />'); //document.writeln(localVar1 + '<br />');
document.writeln(localVar2 + '<br />');
document.writeln('Commented out. Cannot reference (L3)<br /><br />'); //document.writeln(localVar3 + '<br />');

document.writeln('<b>Outside a function, you can reference all global variables.</b><br />');
document.writeln(globalVar1 + '<br />');
document.writeln(globalVar2 + '<br />');
document.writeln(globalVar3);
//-->
</script> 



Operators 

Given that x=5, the table below explains the comparison operators:

==is equal tox==8 is false
x==5 is true
===is exactly equal to (value and type)x===5 is true
x==="5" is false
!=is not equalx!=8 is true
>is greater thanx>8 is false
<is less thanx<8 is true
>=is greater than or equal tox>=8 is false
<=is less than or equal tox<=8 is true

Arrays

var emptyList = [];
var homogenousList = [1, 2, 3];
var heterogenousList = ["one", 2, 3.0];
Javascript has built-in collection objects. The Array object is a dynamically typed sequence of Javascript values. They are created with the bracket notation [] or with the new operator on the Array object (e.g. new Array(5)).

Property Maps

var emptyMap = {};
var homogenousMap = {"one": 1, "two": 2, "three": 3};
var heterogenousMap = {"one": 1,
                       "two": "two",
                       "three": 3.0};
Along with Arrays are the Object objects. They act as property maps with strings serving as keys to dynamically typed data.

Access

// Dot notation property access
window.alert("Homogenous map property \"one\" "
             + homogenousMap.one);
// Subscript notation property access
window.alert("Homogenous map property \"two\" "
             + homogenousMap["two"]);

Assignment

homogenousMap["one"] = 10;
homogenousMap.two = 20;

Removal

delete homogenousMap["one"];
delete homogenousMap.two;

Iteration

for (var key in heterogenousMap) {
    window.alert("Heterogenous map property \""
                 + key
                 + "\" = "
                 + heterogenousMap[key]);
}

Functions

var callable = function (message) { // <-- notice assignment
    window.alert("Callable called with message = "
                 + message);
}


function createClosure(initial) {
    var res = function () {
        initial = initial + 1;
        window.alert("Closure with modified state "
                     + initial);
    }
    return res;
}

function callCallable(f, x) {
    f(x);
}

function composeCallables(f, g, x) {
    f(g(x));
}

Functions are first-class objects. That means that they can be created dynamically, stored, passed and returned just like any other value.

Objects

function MyObject(name, value) {
    this.name = name;
    this.value = value;
}
Javascript supports prototype based object orientation. Not a class type but an object constructor is created for new objects with particular properties. In the example above the this keyword used to reference the ''current instance'' of the object. The this object is essentially a property map with members accessed (and initialized) in this example with the dot notation.
The object constructor, MyObject, is an object constructor not in how it's defined, which looks like any other Javascript function, but in how it's ''invoked''.
var my = new MyObject("foo", 5);
The new operator before the function invokes the function with a newly construced object as this and returns that the initialized object.

Object Prototype

Part of what makes a language object oriented is that data not only has properties but also ''behaviors''. Also known as: member functions; methods; and object messages. To implement a member function in Javascript one would be tempted to write something like what's below based on the member initialization exampled above.

function BadObject(data) {
    this.data = data
    this.memberFunction = function () {
        // ...functions on data...
    }
}
While the code above will work without error, it does create a new closure for each member function for each new instance of the object. What's really required is a class level function that works on instance data. But remember, Javascript objects aren't class based but prototype based. So how do we implement "class" level member functions? (Skip to Implementation) Better yet, how do we implement "class" level members functions in general?
Enter the prototype member.
The internal object member, prototype, has language defined significance in that it is used for resolving property names if the property isn't found in the current property map. It's considered internal because, while the instance'sprototype member is ''inherited'' from the ''constructor's'' prototype member, it cannot be accessed directly from the object instance itself. The defined prototype member is a property map itself which holds members for property name resolution. Consider the example below:
var parentPropertyMap = {"bar": "I'm the bar"};

 // Define the constructor with inheritable properties
 function ChildObject(foo) {
     this.foo = foo;
 }
 ChildObject.prototype = parentPropertyMap;

 childPropertyMap1 = new ChildObject("I'm the foo1");
 childPropertyMap2 = new ChildObject("I'm the foo2");

 // Prints "childPropertyMap1.foo = I'm the foo1"
 window.alert("childPropertyMap1.foo = " + childPropertyMap1.foo);

 // Prints "childPropertyMap2.foo = I'm the foo2"
 window.alert("childPropertyMap2.foo = " + childPropertyMap2.foo);

 // Prints "childPropertyMap1.bar = I'm the bar"
 window.alert("childPropertyMap1.bar = " + childPropertyMap1.bar);

 // Prints "childPropertyMap2.bar = I'm the bar"
 window.alert("childPropertyMap2.bar = " + childPropertyMap2.bar);
The member foo is an instance member added to the instance's property map during construction:
function ChildObject(foo) {
     this.foo = foo;
 }
while bar is in the constructor's prototype:
var parentPropertyMap = {"bar": "I'm the bar"};
 ...
 ChildObject.prototype = parentPropertyMap;
which is ''inherited'' during the new operation:
childPropertyMap1 = new ChildObject("I'm the foo1");
 childPropertyMap2 = new ChildObject("I'm the foo2");
In other words, the member, bar, is shared across all instances of ChildObject.
Therefore, by implementing the prototype member of the constructor function, we can think of the constructor function itself as the "class" object. Complete with static class functions:
function ClassObject() {}
 ClassObject.staticClassFunction = function(x) {
     return x * 2;
 }
static class variables:
function ClassObject() {}
 ClassObject.staticClassVariable = 5;
shared member variables:
function ClassObject() {}
 ClassObject.prototype.sharedMember = 5;
and of course, shared member functions:
function ClassObject(x) {
     this.x = x;
 }
 ClassObject.prototype.memberFunction = function(x) {
     return x * this.x;
 }

Member Function Implementation

function Message(message) {
    this.message = message;
}

Message.prototype.show = function() {
    window.alert("Message.show() with message = "
                 + this.message);
}