Committing projects up to Github

ref –
ref –

Create the repo

Make sure you have created a repository on Github via
Enter a repository name, then check the box where it creates a readme file.
Click ok.


Then fork it locally, directions below are taken from the url here:


On GitHub, navigate to your fork of your repository.
Clone URL buttonIn the right sidebar of your fork’s repository page, click
to copy the clone URL for your fork.

Open Terminal (for Mac users) or the command prompt (for Windows and Linux users).

Type git clone, and then paste the URL you copied in Step 2. It will look like this, with your GitHub username instead of YOUR-USERNAME:

Press Enter. Your local clone will be created and the output from your terminal will be something like this:

Rickys-MacBook-Pro:Desktop rickytsao$ git clone
Cloning into ‘face-recognizer’…
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
Checking connectivity… done

Clone a single branch

git clone –branch dev

Clone with username

List branches of the the repository

(double dash next to “heads”)
git ls-remote –heads

Change working branch :

Create the branch on your local machine and switch in this branch :

$ git checkout -b [name_of_your_new_branch]
Change working branch :

$ git checkout [name_of_your_new_branch]
Push the branch on github :

$ git push origin [name_of_your_new_branch]

Uploading Project

Then, you’ll see the project folder on your desktop. Copy your source files into the folder. And to upload it to Github you do:

note – The project url can be found on the repo page on the righthand side bar. It should have a little paste icon next to it. Its the HTTPS clone URL…you should be able to just copy and paste to the terminal window

If the system tell you that origin already exists, keep going with the instructions.

Make sure you are in the directory of the folder that Git created on your computer. Then within the folder (which should have a git file) you go:

Rickys-MacBook-Pro:holistic-element rickytsao$ git push -f origin master

It will then ask you for your username and password:

Username for ‘’: redmacdev1988
Password for ‘’:


Counting objects: 651, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (645/645), done.
Writing objects: 100% (650/650), 130.74 MiB | 1.45 MiB/s, done.
Total 650 (delta 19), reused 0 (delta 0)
0ddae45..a74a112 master -> master

If you want to remove files, delete the files in your directory.
Then in the same directory, go:

git commit -a -m “removed fluff”
git push origin master

Pulling (cloning) the project onto your machine

git clone

src refspec does not match any ERROR

If you try pushing to a certain branch and it gives you a src refspec error, it means you are not on that branch. You need to switch to that branch first, THEN, push to it.

git checkout -b Ricky_Tsao
Switched to a new branch Ricky_Tsao

git commit -a -m “cleaned up stuff”
git push origin Ricky_Tsao

Cloning Single Branch

git clone learned –single-branch option to limit cloning to a single branch;
tags that do not point into the history of the branch are not fetched.

git clone -b branch_name –single-branch (double dash in front of “single”)

Merge current local branch with remote

$ git stash
$ git pull origin release/1.0.1
// fix conflicts
// git add, git commit
$ git stash pop

// git add, git commit, git push

See the list of files that have changes between your local and remote

$ git status
On branch dev
Your branch is up-to-date with ‘origin/dev’.
Changes to be committed:
(use “git reset HEAD …” to unstage)

modified: Src/Project/Website/Code/global/css/product.css
modified: Src/Project/Website/Code/global/standalonesim.html


$ git stash save “—–”
$ git stash list
$ git stash apply stash@{0}

Delete local branch

$ git branch -d feature/login

Pushing new files onto your branch

$ git add .
$ git reset build/config (or whatever path to folder you want to exclude)
$ git commit -m “Add existing file”
$ git push -f origin Your_Branch

Javascript copy by reference

With a = {}; b = a, you get

quoted from stackoverflow:

No, JS doesn’t have pointers.

Objects are passed around by passing a copy of a reference. The programmer cannot access any C-like “value” representing the address of the object.

Within a function one may change the contents of an passed object via that reference, but you cannot modify the reference that the caller had, because your reference is only a copy:





pointers (C) vs references (Java)

ref –

References might be implemented by storing the address. Usually Java references will be implemented as pointers, but that’s not required by the specification. They may be using an additional layer of indirection to enable easier garbage collection. But in the end it will (almost always) boil down to (C-style) pointers being involved in the implementation of (Java-style) references.

You can’t do pointer arithmetic with references. The most important difference between a pointer in C and a reference in Java is that you can’t actually get to (and manipulate) the underlying value of a reference in Java. In other words: you can’t do pointer arithmetic.

In C you can add something to a pointer (i.e. the address) or substract something to point to things that are “nearby” or point to places that are at any place.

In Java, a reference points to one thing and that thing only. You can make a variable hold a different reference, but you can’t just ask it to point to “the thing after the original thing”.

References are strongly typed. Another difference is that the type of a reference is much more strictly controlled in Java than the type of a pointer is in C. In C you can have an int* and cast it to a char* and just re-interpret the memory at that location. That re-interpretation doesn’t work in Java: you can only interpret the object at the other end of the reference as something that it already is (i.e. you can cast a Object reference to String reference only if the object pointed to is actually a String).

Those differences make C pointers more powerful, but also more dangerous. Both of those possibilities (pointer arithmetic and re-interpreting the values being pointed to) add flexibility to C and are the source of some of the power of the language. But they are also big sources of problems, because if used incorrectly they can easily break assumptions that your code is built around. And it’s pretty easy to use them incorrectly.


Basic Usage

1st param – what index of the array to start
2nd param – how many elements to remove

in firebug console, we first see what test is. Which gives us the result of the full array. Then we do test.splice(1,2), which means at index 1, we remove 2 elements. This returns us “two” and “three”, meaning we removed “two” and “three.

Then we see the results of test again to ensure that “two” and “three” are removed from the original array.

> test
Array [ “one”, “two”, “three”, “four”, “five”, “six” ]
> test.splice(1,2)
Array [ “two”, “three” ]
> test
Array [ “one”, “four”, “five”, “six” ]

in firebug console, we start at index 2, which would be “ten”.
We remove 2 elements, which would be the “ten”, and “six”. The removed elements are returned.
We then add the word “nine”.

> test
Array [ “one”, “four”, “ten”, “six” ]
> test.splice(2,2,”nine”)
Array [ “ten”, “six” ]
> test
Array [ “one”, “four”, “nine” ]

Using splice in List implmentation

We first make a List class default constructor. we initialize member variables. Then we assign function definitions append, remove, length, insert, clear, and toString.

delete the array of elements. then reassign to empty array.

We loop through all the elements of our dataStore array, and if the elements match, we simply return the index.

We first get the index of where we want to remove the element.
Then when we have the index, we use the index as parameter for the splice index to know where to start. The 1 at the 2nd parameter of the splice, means to remove 1 element at that index.

We insert at given position pos, removing 0 elements, and insert the element to be inserted.

Angular/Server layout

from the backend (Server)

starts up and loads

  • express
  • path
  • bordy-parser
  • morgan
  • mongoose
  • config file

We have our express and app variables and initializes them using other modules.
Then we use mongoose to connect to database and make sure it checks.

Then it loads up our routes by using api.js. We require the function that’s in /app/routes/api.js, and throw in our app and express variables. Thus, we get our apiRoutes, and then init the api root path at /api.

This is where our backend router takes care of HTTP verbs GET/POST/PUT/DELETE…etc by implementing function definitions such as:


Once the router is initialized in api.js, we say we want send the browser the index.html like for a root url access:

The start of this html file will load up this router in api.js among other angular js files such as controllers, services, etc.

from the front end – index.html loads up js scripts

When the server starts, this index.html gets loaded up. Angular loads up its controllers, services, etc via js script files at the beginning of this index.html file.

Front End Routing templates to Controller

In the app.routes.js file, we create our routerRoutes module using Angular module ngRoute. We use .config and assign templateUrl, controller, and controllerAs for each individual html page. We will be using this module in another module shortly.

Notice the angular.module, what this means is that we it to group our defined modules together and have angular run and use all of these modules via injection dependencies.

Just like how the main function wire everything together, module is Angular’s way of bootstrapping all of our functionality.

Boostrap is a technique of loading a program into a computer by means of a few initial instructions that enable the introduction of the rest of the program from an input device.


Then we also have the app.js. What this app.js means for this particular example is that it is the Angular app. It contains the controllers, which uses services via dependency injections.

First, notice that it uses our routerRoutes. It injects the routerRoutes module by passing it into the parameter array.


What this means is that we define a module called routerApp, which uses routerRoutes defined in app.routes.js for its routing mechanism. In our routing mechanism, we have .when(‘url’, {..}), which routes templates to controllers. Hence, we define these controllers by declaring our .controller in our app.js.

Services used by Controllers

Also notice the authService in the parameter array. authService is a service defined in authService.js.


so we declare a module called authService, and we use .factory to create this service:

First, we can use either factory, or service. In factory, we return a object, which can be injected into a controller.
Here’s an example:

Notice the creation of authFactory, its usage and declaration of properties, and then the return of that object.

Where as in service, you see that we attach attributes and behavior to this:

When inside a service we are dealing with the object using this and not returning anything.
Both are singletons.

Angular services are:

Lazily instantiated – Angular only instantiates a service when an application component depends on it. So when another component uses it by calling it in its dependency array parameter, Angular will instantiate that one singleton Service and then pass it via reference to the component in need.

Singletons – Each component dependent on a service gets a reference to the single instance generated by the service factory.

From the knowledge above, we can see that we declared an AuthFactory for getToken setToken. Then we use the AuthFactory, inject it into Auth, which we use to see if the current browser has a token, then uses the http to call createSampleUser in our backend API.

Angular service or factory

What is an AngularJS service or factory?


Yes! That one word is enough to define AngularJS services. The purpose of AngularJS service / factory function is to generate a single object or function that represents the service to rest of the application.

An AngularJS service can be created or registered or created in four different ways,

Using the service() method
Using the factory() method
Using the provider() method
Using the value() method
Using the constant() method

For example, here we are saying, we want to create a module called CalculatorService, which uses no other modules, hence the empty array parameter. This module has a service called Calculator, which has a function to square a number a. The result square will be a property for this singleton.

That object or function is passed as a parameter to any other factory function which specifies a dependency on this service.


Notice the name Calculator declared in module CalculatorService, and used here as a parameter to inject dependency from the controller to the service.

On the view we are using the controller to do the data binding as shown below,