This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Point; | |
public class Vehicle{ | |
private Point location = new Point(); | |
private String name; | |
public Vehicle(Point location, String name){ | |
this.location = new Point(location); //Since Point object is mutable, it should be copied. | |
vehicleName = name; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A custom toString method that returns a meaningful string representation of an ArrayList object | |
public String toString() { | |
String strOutput = "MyArrayListObject ["; //Prints constructor name + left bracket | |
for(int i = 0; i < myArr.size(); i++){ //myArr = ArrayList instance variable | |
strOutput += myArr.get(i) + ", "; | |
} | |
strOutput = strOutput + "]"; | |
return strOutput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//converting a Java ArrayList to an int[] array | |
int[] arr = new int[myArrList.size()]; | |
for (int i=0; i < arr.length; i++){ | |
arr[i] = myArrList.get(i).intValue(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git branch -m old_branch new_branch # Rename branch locally | |
git push origin :old_branch # Delete the old branch | |
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git branch -m old_branch new_branch # Rename branch locally | |
git push origin --delete :old_branch # Delete the old branch | |
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Person(firstName, lastName){ | |
this.firstName = firstName; | |
this.lastName = lastName; | |
}; | |
Person.prototype.getFullName = function(){ | |
return this.firstName + " " + this.lastName; | |
}; | |
function Employee(firstName, lastName, position){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The Factory Pattern | |
var createPerson = function(firstName, lastName) { | |
return { | |
firstName : firstName, | |
lastName : lastName, | |
greet : function(){ | |
return "Hey there " + firstName + " " + lastName; | |
} | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The constructor pattern | |
function Robot(name, model, job){ | |
this.name = name; | |
this.model = model; | |
this.job = job; | |
this.sayMyName = function() { | |
alert(this.name); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Example 1 | |
var createPerson = function(firstName, lastName){ | |
var person = {}; | |
//Descriptor object - define single property | |
//2 types - Data & Accessor descriptors | |
Object.defineProperty(person, "firstName", { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Selecting all the external links of a page | |
$('a[href^="http://"]') | |
//Selecting all the internal links of a page | |
$('a:not(a[href^="http://"])') |
OlderNewer