Excellent Javascript/jQuery resources

Lexical scoping/closure
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures

Understanding Scope and Context in JavaScript

this

Demystifying JavaScript Variable Scope and Hoisting

Event Capturing and Bubbling in JavaScript
Bubbling and capturing
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events

How JavaScript Event Delegation Works

JavaScript Prototype in Plain Language

JavaScript Promises for Dummies

Eric Elliott’s “Master the JavaScript Interview” Series

Anjana Vakil: Learning Functional Programming with JavaScript – JSUnconf 2016

How JavaScript Event Delegation Works

Event order

Closures in loops – Javascript Gotchas

Your JS is a Mess. Javascript Namespacing

Notes on Data Structures

Excellent memory refreshers on the basics of data structures:
http://algosaur.us/data-structures-basics/#n00b (With very cute illustrations!)
http://www.geeksforgeeks.org/data-structures/

Memory refresher on time complexity:

Such complex, very wow – A guide to Algorithmic Complexity

Queue

Stack

Heap
– max-heap – all children are smaller than parent
– min-heap – all children are greater than parent
– Time complexity for insertion is O(logN)
– Heapsort => O(NlogN)

Binary Tree
– always of height logN

Sorting
insertion sort => O(N2)
– Good when array size is small or almost sorted
– bubble sort
– Mergesort => O(NlogN)
– Quicksort => O(NlogN)
– Key concept: Picks an element as pivot and partitions the given array around the picked pivot
– Best case O(NlogN), average case O(NlogN), worst case O(N2)

Hash table
O(1)

Count inversions

Sticky vs Non-Sticky sessions

A good explanation on sticky vs. non-sticky sessions:

When your website is served by only 1 web server, for each pair, a session object is created and remains in the memory of the web server. All the requests from the client go to this web server and update this session object. If some data needs to be stored in the session object over the period of interaction, it is stored in this session object and stays there as long as the session exists.

However, if your website is served by multiple web servers which sit behind a load balancer, the load balancer decides which actual (physical) web-server should each request go to. For example, if there are 3 webservers A, B and C behind the load balancer, it is possible that www.mywebsite.com/index.jsp is served from server A, www.mywebsite.com/login.jsp is served from server B and www.mywebsite.com/accoutdetails.php are served from server C.

Now, if the requests are being served from (physically) 3 different servers, each server has created a session object for you and because these session objects sit on 3 independent boxes, there’s no direct way of one knowing what is there in the session object of the other. In order to synchronize between these server sessions, you may have to write/read the session data into a layer which is common to all – like a DB. Now writing and reading data to/from a db for this use-case may not be a good idea. Now, here comes the role of sticky-session. If the load balancer is instructed to use sticky sessions, all of your interactions will happen with the same physical server, even though other servers are present. Thus, your session object will be the same throughout your entire interaction with this website.

To summarize, In case of Sticky Sessions, all your requests will be directed to the same physical web server while in case of a non-sticky loadbalancer may choose any webserver to serve your requests.

From https://stackoverflow.com/questions/10494431/sticky-and-non-sticky-sessions

Javascript’s Reduce method

The Reduce method reduces an array into a single value by applying a callback function to each element in the array, starting with the leftmost to the rightmost element.

As a simple example, we could use reduce() to find the sum of all the numbers in an array.

const numbers = [3, 2, 5, 7, 8, 10];
const sum = numbers.reduce(function (total, item) {
  return total + item;
});
// Returns 35

In ES6 syntax,

const numbers = [3, 2, 5, 7, 8, 10];
const sum = numbers.reduce((total, item) => total + item);
// Returns 35

More great examples of the Reduce method:
https://medium.freecodecamp.org/reduce-f47a7da511a9

Full documentation:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce

Git cheatsheet

See all local branches

git branch

See all remote branches

git branch -r

See all branches

git branch -a

Clone a git repo

git clone [url]

Create a local branch from remote and switch to it

git checkout -b <branch> <remote>/<branch>

List the current configured remote repository for your fork.

git remote -v

List recent commits

git log

Add a new remote upstream repository

git remote add upstream [url]

See what files are changed

git status

See only changes that have already been added to the Staging Area

git diff --staged

Show unstaged changes

git diff

Push to remote

git push <remote> <branch>

Check out pull requests locally

In .git/config add this under the [remote “upstream”] section

fetch = +refs/pull/*/head:refs/remotes/origin/pr/*:

To check out a particular pull request:

git checkout pr/999

Excellent Git resources
https://services.github.com/on-demand/downloads/github-git-cheat-sheet/
https://www.git-tower.com/learn/git/ebook/en/command-line/introduction#start

Installing Maven plugins

To download plugins and the required dependencies, run this command:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.6:get -Dartifact=groupId:artifactId:version

For example, to download versions-maven-plugin:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.6:get -Dartifact=org.codehaus.mojo:versions-maven-plugin:2.3 -DrepoUrl=https://github.com/mojohaus/versions-maven-plugin

If the plugins need to be installed manually, refer to this documentation on the Apache Maven project site.

Installing Apache Maven on El Capitan

  • Add the following line to ~/.profile or ~/.bash_profile:
export JAVA_HOME=$(/usr/libexec/java_home)

To verify the JAVA_HOME environment variable has been set correctly, type:

echo $JAVA_HOME

which should return something like this:

/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home
  • Verify that JDK 7+ is installed.  Type the following in a terminal window:
java -version

It should give you something like this:


java version "1.8.0_102"

Java(TM) SE Runtime Environment (build 1.8.0_102-b14)

Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

(At the time this was written, the version was 3.3.9)

  • Extract the Maven Archive
  • Type the following lines in terminal:

sudo su

mv [apache-maven-directory]/apache-maven-3.3.9 ~/opt

exit

 

where [apache-maven-directory] is the path of the directory where you extract the maven archive in.

  • Add Maven binaries to user path.  Add the following line in ~/.bash_profile

export PATH=/opt/apache-maven-3.3.9/bin:$PATH

save and quit the file, then execute .bash_profile again.

  • Verify Maven installation by typing:
mvn -version

which should return something like this:


Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T08:41:47-08:00)

Maven home: /opt/apache-maven-3.3.9

Java version: 1.8.0_102, vendor: Oracle Corporation

Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/jre

Default locale: en_US, platform encoding: UTF-8

OS name: "mac os x", version: "10.11.6", arch: "x86_64", family: "mac"

Installing Apache Maven on Mac

While the installation guide on Apache is helpful, I decided to document the exact steps (some are not covered on the Apache site) I took to get Apache Maven installed in my machine.

  1. Add JAVA_HOME environment variable to .bash_profile

    export JAVA_HOME=$(/usr/libexec/java_home)
  2. Reload .bash_profile by running:

    . ~/.bash_profile
  3. Download the Apache Maven distribution archive from here.
  4. Add the bin directory to the PATH environment variable.
    In, .bashrc, add:

    export PATH=/path/to/apache/maven-3.3.9/bin:$PATH
  5. Reload .bashrc by running:

    . ~/bashrc
  6. Type the following the confirm Maven has been installed successfully:

    mvn -v