Web Basics

447567-the-best-web-hosting-services-for-2014
1. authentication: who you are
authorization: what you can do

cookie: more physical

session: context (teaching – learning, lecturing)
session cookie (bank login)
persistent cookie (remember me option)
token – certificate
2. multi-thread

context thread
thread pool
blocking I/O
single thread
non-blocking I/O (then go to end of queue)

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles about web and mobile development. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.

Follow me @Yaoli0615 at Twitter to get latest tech updates.

Advertisements
Posted in CS Research&Application, IT, Uncategorized | Tagged , | Leave a comment

How the Web Works

447567-the-best-web-hosting-services-for-2014How the Web Works: A Primer for Newcomers to Web Development (or anyone, really)

https://medium.freecodecamp.org/how-the-web-works-a-primer-for-newcomers-to-web-development-or-anyone-really-b4584e63585c

How the Web Works Part II: Client-Server Model & the Structure of a Web Application

https://medium.freecodecamp.org/how-the-web-works-part-ii-client-server-model-the-structure-of-a-web-application-735b4b6d76e3

How the Web Works Part III: HTTP & REST

https://medium.freecodecamp.org/how-the-web-works-part-iii-http-rest-e61bc50fa0a

 

A Beginner-Friendly Introduction to Containers, VMs and Docker

https://medium.freecodecamp.org/a-beginner-friendly-introduction-to-containers-vms-and-docker-79a9e3e119b

Linux namespace and control group.

 

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles about web and mobile development. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.

Follow me @Yaoli0615 at Twitter to get latest tech updates.

Posted in CS Research&Application, Uncategorized | Tagged , , , | Leave a comment

Advanced Algorithm Research Notes

daie-algorithms

1. KMP

Problem: find a substring in a string

brute force: start from every position in str1 and compare with str2, time is O(n*m).

optimization idea: position 1 and position 2 comparison is independent.

prefix without last one and prefix without first one in str2.

application: check tree T1 in T2, serialize and find substring.

2. Manacher

problem:longest palindrome substring (最长回文子串)in O(n)

idea:最右回文覆盖(边界),回文中心,过程绑定在某些不回退的变量

explanation:

“abc121def” => “#a#b#c#1#2#1#d#e#f”

3. 完美洗牌算法

4. 矩阵快速幂

1) 严格固定(状态转移方程)

2) F(k) = F(1) * |k * k| ^ (n -k)

application: Fibonacci Series

idea: brute force solution => optimized solution (Recursion => Memorized Search => DP

1) 试法(recursion)

2)确定维数(参数个数)process(array, index, aim) => dp[index][aim]

3)初始状态(不依赖任何其他位置)

4)结果位置

5)任意点的依赖位置

5. 蓄水池算法

6. BFPRT

Problem: find nth smallest element in an array.

Solution idea: not randomly pick the initial value.

 

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles about web and mobile development. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.

 

Resources:

Core Java Volume I–Fundamentals (10th Edition) (Core Series)

Core Java, Volume II–Advanced Features (10th Edition) (Core Series)

Test-Driven Java Development

Java Concurrency in Practice

Java: An Introduction to Problem Solving and Programming (7th Edition)

Java 9 for Programmers (Deitel Developer Series)

Java SE8 for the Really Impatient: A Short Course on the Basics (Java Series)

Core Java for the Impatient

Java: The Beginners Guide for every non-programmer which will attend you trough your learning process

Java Deep Learning Essentials

Machine Learning in Java

Learning Reactive Programming With Java 8

Java 9 Programming By Example

Thinking in Java (4th Edition)

The Java EE Architect’s Handbook, Second Edition: How to be a successful application architect for Java EE applications

Java Artificial Intelligence: Made Easy, w/ Java Programming

Posted in CS Research&Application, Uncategorized | Tagged | Leave a comment

Javascript Learning Notes

asyncawait

1. Javascript Engine is synchronous

2. Browser and NodeJS are asynchronous, main thread in NodeJS is a single thread.

3. AngularJS: two way data binding

4. Callback
Execute and obey after master/boss give an order (Callback functions define the order that different actions occur, callback provides a level of control so you can determine the custom order)

5. Promise
Resolve “callback hell”, make it more clear and understandable.
(A promises holds the place of a value that does not exist yet, but will certainly exist in future)
Promises are a great way of giving clarity to consecutive asynchronous functions and clarifying inputs and outputs)

The key to promises is the concept of unfilled, filled or rejected. Once you create a sequence of these promises, you have a clear flow of inputs and outputs, and clear code for others to read. You can use 3 different states to track the progress of the entire chain of promises. The style is synchronous (sequential), even though the actual execution is asynchronous.

6. Promise All vs Race

Promise.all leads to a success when all conditions are met, or results in failure when one of the conditions fails (without waiting for the others).

Promise.race sets the program pending the outcome of the first condition tested in a list. Depending on whether the result is a success or a failure, promise.race is a success or a failure, without awaiting the result of other conditions.

7. Javascript uses dictionary-like structure for property insert and access, it takes O(n) time.

Nodejs is built on Chrome V8 engine. (use the code)
8. IO
File Read/Write
Database
Network
9. Git
https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud

merge: keep 2 branches, merge changes in feature branch to master branch, no message overridden
rebase: keep a linear structure, based on master branch, have a clean commit history but override commit message

Reference:
https://medium.freecodecamp.org/javascript-callbacks-explained-using-minions-da272f4d9bcd

https://medium.freecodecamp.org/javascript-promises-explained-by-gambling-at-a-casino-28ad4c5b2573

https://www.xul.fr/javascript/promise-all-race.php

https://blog.thoughtram.io/angular/2016/10/13/two-way-data-binding-in-angular-2.html

Learn How To Debug JavaScript with Chrome DevTools

How to get the most out of the JavaScript console

JavaScript ES6+: var, let, or const?

https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/

 

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles about web and mobile development. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.

Follow me @Yaoli0615 at Twitter to get latest tech updates.

Posted in CS Research&Application, Uncategorized | Tagged , , , | Leave a comment

Install common libs in Ubuntu

ruiiq

I host a Ubuntu (14.04) image in MacOS VirtualBox and there are some tips to install commonly used libraries:

1. open Chrome in ubuntu hosted in mac VirtualBox
Error: NSS_VersionCheck(“3.26”) failed.
Solution:
(sudo apt-get --only-upgrade install libnss3)

Tips: download chrome from google chrome home page

2. Install NodeJS

sudo apt-get update

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash –

sudo apt-get install -y nodejs

3. Install Nodemon

sudo npm install -g nodemon

4. Install git

sudo apt-get install git

5. Install angular/cli

sudo npm install -g @angular/cli

6. Install Redis

wget http://download.redis.io/releases/redis-3.2.6.tar.gz

tar xzf redis-3.2.6.tar.gz

cd redis-3.2.6

make

sudo make install

cd utils

sudo ./install_server.sh

7. Install pip

(sudo apt-get update)

sudo apt install python-pip

sudo pip install Flask

8 . Install Docker

curl -fsSL https://get.docker.com/ | sh

Setup docker permission:

sudo usermod -aG docker $(whoami)

(you need to logout and login again after set permission)

To start docker when the system boots: sudo systemctl enable docker

sudo systemctl enable docker

https://askubuntu.com/questions/304860/what-is-the-systemctl-equivalent

sudo update-rc.d docker defaults

9. Install Nginx

sudo apt-get update

sudo apt-get install nginx
verify nginx installed

(For ubuntu 16.04)

Add following two lines into /etc/apt/sources.list

deb http://nginx.org/packages/ubuntu/ xenial nginx

deb-src http://nginx.org/packages/ubuntu/ xenial nginx

Then run:

sudo apt-get update

sudo apt-get install nginx

Error:
GPG error: http://nginx.org xenial InRelease: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY XXXXXXXXXXXX2
Refer:
Solution:
sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys [PUBLIC_KEY]
10. Visual Studio Code
11. Speed up Ubuntu in VirtualBox
12. Angular/cli
ng serve
(ctrl + shift + c to exit)

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles about web and mobile development. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.
Posted in CS Research&Application, Uncategorized | Tagged , | Leave a comment

NoSQL Learning Notes

nosql

What

NoSQL (originally referring to “non SQL” or “non relational”)[1] database provides a mechanism for storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases. (Not only SQL, support SQL query)

Why

Simplicity of design, simpler “horizontal” scaling to clusters of machines (which is a problem for relational databases), and finer control over availability. The data structures used by NoSQL databases (e.g. key-value, wide column, graph, or document) are different from those used by default in relational databases, making some operations faster in NoSQL. The particular suitability of a given NoSQL database depends on the problem it must solve. Sometimes the data structures used by NoSQL databases are also viewed as “more flexible” than relational database tables.

How

Many NoSQL stores compromise consistency (in the sense of the CAP theorem) in favor of availability, partition tolerance, and speed. Barriers to the greater adoption of NoSQL stores include the use of low-level query languages (instead of SQL, for instance the lack of ability to perform ad-hoc joins across tables), lack of standardized interfaces, and huge previous investments in existing relational databases. Most NoSQL stores lack true ACID transactions, although a few databases, such as MarkLogicAerospike, FairCom c-treeACE, Google Spanner (though technically a NewSQL database), Symas LMDB, and OrientDB have made them central to their designs. (See ACID and join support.)

Instead, most NoSQL databases offer a concept of “eventual consistency” in which database changes are propagated to all nodes “eventually” (typically within milliseconds) so queries for data might not return updated data immediately or might result in reading data that is not accurate, a problem known as stale reads. Additionally, some NoSQL systems may exhibit lost writes and other forms of data loss. Fortunately, some NoSQL systems provide concepts such as write-ahead logging to avoid data loss. For distributed transaction processing across multiple databases, data consistency is an even bigger challenge that is difficult for both NoSQL and relational databases. Even current relational databases “do not allow referential integrity constraints to span databases.” There are few systems that maintain both ACID transactions and X/Open XA standards for distributed transaction processing.

1401269083847

Database Decision Tree

if Running a cluster

if Need SQL query

NewSQL

else

if Relationships are very important

Graph based Database (Neo4J …)

else

if Key-based access only

Key-Value based Database (Redis, Riak, …)

else

if Need Ad-hoc query

Document based Database (MongoDB, CouchDB, …)

else

Column based Database (Cassandra, HBase, …)

else

if Need SQL query

Relational Database Management System (MySQL, Oracle)

else

if Relationships are very important

Graph based Database (similar like above)

 

Reference:

NoSQL Databases: An Overview

SQL/NoSQL How to choose ?

 

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles about web and mobile development. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.
Posted in CS Research&Application, Uncategorized | Tagged , , | Leave a comment

Consistent Hashing Learning Notes

cache

Why?

In most traditional hash tables, a change in the number of array slots causes nearly all keys to be remapped because the mapping between the keys and the slots is defined by a modular operation. (less keys to update when add or remove nodes, easier to scale up/down)

What?

Consistent hashing is a special kind of hashing such that when a hash table is resized, only K/n keys need to be remapped on average, where K is the number of keys, and n is the number of slots.

How?

Consistent hashing is based on mapping each object to a point on the edge of a circle (or equivalently, mapping each object to a real angle). The system maps each available machine (or other storage bucket) to many pseudo-randomly distributed points on the edge of the same circle.

To find where an object should be placed, the system finds the location of that object’s key on the edge of the circle; then walks around the circle until falling into the first bucket it encounters (or equivalently, the first available bucket with a higher angle). The result is that each bucket contains all the resources located between each one of its points and the previous points that belong to other buckets.

If a bucket becomes unavailable (for example because the computer it resides on is not reachable), then the points it maps to will be removed. Requests for resources that would have mapped to each of those points now map to the next highest points. Since each bucket is associated with many pseudo-randomly distributed points, the resources that were held by that bucket will now map to many different buckets. The items that mapped to the lost bucket must be redistributed among the remaining ones, but values mapping to other buckets will still do so and do not need to be moved.

A similar process occurs when a bucket is added. By adding new bucket points, we make any resources between those and the points corresponding to the next smaller angles map to the new bucket. These resources will no longer be associated with the previous buckets, and any value previously stored there will not be found by the selection method described above.

 

Reference:

Wikipedia: Consistent Hashing

Consistent hashing

The Simple Magic of Consistent Hashing

Improving load balancing with a new consistent-hashing algorithm

Consistent Hashing in Cassandra

Why do people use virtual nodes to get a load balance in consistent hashing implementation?

 

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles about web and mobile development. Feel free to visit my web app, WhizWallet, to apply for credit, store or gift cards, DealsPlus to browse daily deals and store coupons to save money.
Follow me @Yaoli0615 at Twitter to get latest tech updates.
Posted in CS Research&Application, Uncategorized | Tagged , , | Leave a comment