Part 1: Understand git and github

Git: Git is a free and distrubuted opensource version control, it helps in maintaining your sourcecode.

Github: It is a remote repository, available as free/premium singups based on your requirement.

Setup:

  1. Download and Install git version control for Windows – https://git-scm.com/

Basic Command:

  1. $ git init  => intializes local giit repository, creates .git folder as well
  2. $ git add <File> => Adds <files> to index or staging folder.                                                        OR   $ git add *  => Adds files recursively
  3. $ git status => Check status of working tree. Shows difference between working tree and staging area
  4. $ git commit => Commit changes from index/staging area to the local repo.
  5. $ git remote
  6. $ git push => Push from Local to Remote repo. Asks password.
  7. $ git pull => Pull the latest from remote repo.
  8. $ git clone => Clones repo into new repo

Push it to Github

  1. Create repository on the Github to which you would like to push it.
  2. git remote add origin your repo name that you created in step1
  3. git push -u origin master ..or push it the existing repository.

References:

Crash Course on Git

Advertisements

JavaScript References

JavaScript Objects:

http://blog.pluralsight.com/understanding-javascript-objects-2

https://www.nczonline.net/blog/2012/10/16/does-javascript-need-classes/

JavaScript Prototypes explained :

http://blog.pluralsight.com/understanding-javascript-prototypes

http://sporto.github.io/blog/2013/02/22/a-plain-english-guide-to-javascript-prototypes/

https://javascriptweblog.wordpress.com/2010/06/07/understanding-javascript-prototypes/

http://yehudakatz.com/2011/08/12/understanding-prototypes-in-javascript/

Referencing Outer Query Tables in Inner Query

WRONG:

SELECT * FROM Table t1 INNER JOIN  ( SELECT TOP 1 t1.PrimaryKeyId Table t2 ON where t2.CustomerId = t1.CustomerId ORDER BY CreatedDate DESC)

When you run the above query, you would get an error – “Multi-Part Identifier Could Not Be Found”.

CORRECT:

SELECT * FROM Table t1 where t1.PrimaryKeyId = (SELECT TOP 1 PrimaryKeyId FROM  Table t2 WHERE t2.CustomerId = t1.CustomerId ORDER BY CreatedDate DESC)

This sub query runs for each of the PrimaryKeyIds from the Outer Query and get the TOP 1 row from the set of rows with same CustomerIDs.

Confusion with NULL values in SQL

Today I was working on a SQL query, and it took me a while before I figured out an issue.

A query goes something like this –  SELECT * FROM Table t1 where t1.UserId NOT IN ( SELECT UserId FROM Table t2 WHERE t2.Status = 1) WHERE Status = 2

Lets assume Status 1 = Active and Status 2 = Terminated and UserId can be NULL. There are few records in Table with UserIds Null for Status = 1. When i ran the query I was expecting few records to output but for some reason there are 0 records. After looking at the query carefully, i noticed that the inner query was returning NULL values and that ends being as below. It return NULL

SELECT * FROM Table t1 where t1.UserId NOT IN ( 1, 2, NULL) — Return 0 records although there are matching records with 1, 2

NULL can be dangerous enough to mess up the whole query and result set. So better handle NULL values properly.

 

Quotes –

“Often the answer is baked into the question you ask, so, if you don’t question the questions you’re asking you’re not going to come up with really innovative solutions.”