Programming Reflection (Jun 8, 2017)

wpid-Programming-Wallpaper-3

1.  BITT Principle

Brute Force (暴力解法,低效/费空间)
Improvement (优化解法,高效/省空间)
Time and space complexity (时间/空间复杂度)
Test (测试)

2. Array is sorted and may have better performance (3Sum o(n^2) solution)

数组排序过后可能有奇效

3. Test cases are designed on purpose to test the functionality, not randomly selected.

In the example of 3sum problem,

test cases could be:

0, 1, 2 elements for input array to test shorter array than the requirement

[1, 0, 1] for no matched triplets

[-1, -1, -1, 2, 2, 2, 2] for many duplicate triplets

测试用例是用来测试具体功能的,并非任意设计。

 

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. 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:

Ruminations on C++: A Decade of Programming Insight and Experience

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

Java Data Structure Summary

c82-java-prog-logo

Data Structure in Java
ArrayList — Resizable Array Implementation
1.5x resize if necessary

GC vs ARC
runtime vs compile time
https://stackoverflow.com/questions/7874342/what-is-the-difference-between-objective-c-automatic-reference-counting-and-garb

Right shift vs Division
1. faster
2. pure integer
3. no intermediate solution overflow issue (safer, avoid stack overflow)

append operation: Amortized o(1)

seamless

Resizable Array
Random Access: o(1)

ArrayDeque — Resizable Circular Queue
2x resize if necessary (bit operation)

LinkedList
Double Linked List in Java
8 bytes to store last or next pointer
Dynamic data structure

ArrayDeque is better for implementing Stack/Queue, for consecutive space, almost o(1) for head/tail operation

Queue queue = new ArrayDeque();
Queue queue = new ArrayDeque(1000); // avoid too much resize

List queue = new ArrayList(1000);
Deque stack = new ArrayDeque(1000);

Stack (Vector) is thread safe data structure, slower for cases which doesn’t need multi-thread

Hashing
build index (map object to number/hash code, many to one, ideal status is one to one)
Default: memory address
Hashcode design 3 principles:
1. same code for repeating calling in same application
2. Equal => same hash code
3. same hash code !=> Equal, but good to have

HashTable
Search an element in an array time complexity:
unsorted array with o(n)
sorted array with o(logn)

search in almost o(1), insert in almost o(1)

Use hashcode and array length to get index of array

Mapping: hashCode => arrayIndex
arrayIndex = hashCode % length

Collision:
Linear Probing (clustering in head or tail)
Separate Chain (Linked List)

Rehashing (Load Factor = number of entries / length, if over threshold like 75% and resize)

HashMap
Default value:
size: 16
load factor: 0.75
hash % length => hash & (length – 1)

X mod 2^n (X & (2^n – 1))

Map of List is slower than List of List

HashSet (HashMap wrapper class with dummy value)

LinkedHashMap
Linked List + Hashmap
LinkedList maintains the order for insertion

LRU (Least Recently Used) Cache

LinkedHashMap – maintain visit instead of insert order, handle size

TreeMap
Red-black Tree (self balanced binary searched tree) implementation
Mid-order Iteration (calculate )
o(logn): put, containsKey, remove
sorted keys

TreeSet (TreeMap wrapper class with dummy value)

Heap
Complete Tree (Each level must have max number of nodes, bottom level could be an exception, filled from left to right on each level)
Largest/smallest in the root
Children are always smaller/larger than parent

Add/Remove (sink up/down)
Keep complete tree structure
Keep parent-children value order

Remove the root only allowed

Store as array actually (childrenIdx – 1)/2 = parentIdx, leftChildIdx = 2 * parentIdx + 1, rightChildIdx = leftChildIdx + 1

PriorityQueue in Java (offer as add)

Practice: Top K Numbers

ArrayList: 1.5x resize(most operation on one side)
ArrayDeque: 2x resize (most operation on two sides)
HashMap: 2x resize (reduce the number of rehashing)

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. 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

Programming Reflection (Jun 1, 2017)

wpid-Programming-Wallpaper-3

1. Programming, programming, programming

Keep brushing up algorithm and data structure problems

Summarize the approach and the process to figure out solution

多刷题

多总结(回顾解题思路)

2. Technical Knowledge: Breadth vs Depth

Concentrate on one in early stage, then learn about more

职业早期专精一门,之后拓展广度

3. Tech stack: Old (Mature) vs New (Unstable)

Catch up with one or two new technology

Still use C++  for server side development for billion level usage (unless Java, or Node.js)

早期跟踪一两门新技术

4. Understand is more important than memorize solution

不要背题

 

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. 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:

Clean Code: A Handbook of Agile Software Craftsmanship

Ruminations on C++: A Decade of Programming Insight and Experience

 

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

Technology Podcast notes

podcasts011

1. Fixed mind set VS growth mind set

Behavior changes brain, learn something, like playing guitar

Praise process and work, don’t always say you are smart or talented

We can always be better

2. 四小时鼓掌赢20美元
目标便宜(赢钱到赌气)
成本束缚(鼓掌一个小时不愿放弃)

布莱希特论戏剧
不要沉浸在剧情中
生活是场大戏,也是可以改变的
戏剧不仅要呈现生活,反思生活,更要激起改变生活的欲望,激情和动力

3. Vision and strategy
Get invest and revenue
Build team and put talent in right position

4. Management
Build great product
Make income more than expense

Measurability – small team
Expandable – high tech
Choose hard solution
Patent doesn’t help too much, law sue takes too long time

Small group of high quality users
Large amount of

 

5. 善借人脉 找刘备
敢想敢干 敢于拼搏 温酒斩华雄
打差异化 不喝敬酒 善于炒作
玩神秘 实力 不邀功 面沉如水
不贪恋眼前小利
远大目标 胸怀舍弃 信仰执着追求 脚踏实地

关羽的威名 曹操的打压
沧海横流 方显英雄本色

不用动机辩护结果
对大势的判断
理性(认知的局限,情绪是认知能力的缺损)

威而不怒 亲而不犯
状元的才,将军的胆,城墙厚的脸

6. Love Faith Hope
Talk Sing Read

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. 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:

Radical Candor: Be a Kick-Ass Boss Without Losing Your Humanity

The First-Time Manager (Agency/Distributed)

Manage Your Day-to-Day: Build Your Routine, Find Your Focus, and Sharpen Your Creative Mind (The 99U Book Series)

How to Improve Your Leadership and Management Skills – Effective Strategies for Business Managers

The Organized Mind: Thinking Straight in the Age of Information Overload

The Coaching Habit: Say Less, Ask More & Change the Way You Lead Forever

The Five Dysfunctions of a Team, Enhanced Edition: A Leadership Fable (J-B Lencioni Series)

Leadership Roles and Management Functions in Nursing: Theory and Application

Good to Great: Why Some Companies Make the Leap…And Others Don’t

High Output Management

Start with Why: How Great Leaders Inspire Everyone to Take Action

The ONE Thing: The Surprisingly Simple Truth Behind Extraordinary Results

The New One Minute Manager

The Power of KM: Harnessing the Extraordinary Value of Knowledge Management

Posted in IT, Uncategorized | Tagged , | Leave a comment

Java Fundamentals and Machine Learning Summary and Resources

c82-java-prog-logo

1.Inheritance can be defined as the process where one class acquires the properties (methods and fields) of another. With the use of inheritance the information is made manageable in a hierarchical order.

 

2. If a class inherits a method from its superclass, then there is a chance to override the method provided that it is not marked final.

The benefit of overriding is: ability to define a behavior that’s specific to the subclass type, which means a subclass can implement a parent class method based on its requirement.

In object-oriented terms, overriding means to override the functionality of an existing method.

 

3. Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.

 

4. An overridden method is invoked at run time, no matter what data type the reference is that was used in the source code at compile time.

 

5. Abstraction is a process of hiding the implementation details from the user, only the functionality will be provided to the user. In other words, the user will have the information on what the object does instead of how it does it.

 

6. An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception occurs the normal flow of the program is disrupted and the program/Application terminates abnormally, which is not recommended, therefore, these exceptions are to be handled.

1) Checked exceptions − A checked exception is an exception that occurs at the compile time, these are also called as compile time exceptions. These exceptions cannot simply be ignored at the time of compilation, the programmer should take care of (handle) these exceptions.

2) Unchecked exceptions − An unchecked exception is an exception that occurs at the time of execution. These are also called as Runtime Exceptions. These include programming bugs, such as logic errors or improper use of an API. Runtime exceptions are ignored at the time of compilation.

3) Errors − These are not exceptions at all, but problems that arise beyond the control of the user or the programmer. Errors are typically ignored in your code because you can rarely do anything about an error. For example, if a stack overflow occurs, an error will arise. They are also ignored at the time of compilation.

 

7. In Java, just like methods, variables of a class too can have another class as its member. Writing a class within another is allowed in Java. The class written within is called the nested class, and the class that holds the inner class is called the outer class.

Inner classes are a security mechanism in Java. We know a class cannot be associated with the access modifier private, but if we have the class as a member of other class, then the inner class can be made private. And this is also used to access the private members of a class.

1) Inner Class

2) Method-local Inner Class

3) Method-local Inner Class

 

8. Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding.

 

Benefits of Encapsulation:

The fields of a class can be made read-only or write-only.

A class can have total control over what is stored in its fields.

The users of a class do not know how the class stores its data. A class can change the data type of a field and users of the class do not need to change any of their code.

 

9. An interface is a reference type in Java. It is similar to class. It is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.

1) When a class implements an interface, you can think of the class as signing a contract, agreeing to perform the specific behaviors of the interface. If a class does not perform all the behaviors of the interface, the class must declare itself as abstract. (Interface is like the protocol in Objective C)

2) There are two basic design purposes of tagging interfaces −Creates a common parent  and Adds a data type to a class.

 

10. Packages are used in Java in order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier, etc.

1) A Package can be defined as a grouping of related types (classes, interfaces, enumerations and annotations ) providing access protection and namespace management.

 

11. A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain the following

1) Interfaces − These are abstract data types that represent collections. Interfaces allow collections to be manipulated independently of the details of their representation. In object-oriented languages, interfaces generally form a hierarchy.

2) Implementations, i.e., Classes − These are the concrete implementations of the collection interfaces. In essence, they are reusable data structures.

3) Algorithms − These are the methods that perform useful computations, such as searching and sorting, on objects that implement collection interfaces. The algorithms are said to be polymorphic: that is, the same method can be used on many different implementations of the appropriate collection interface.

 

12. Java Generic methods and generic classes enable programmers to specify, with a single method declaration, a set of related methods, or with a single class declaration, a set of related types, respectively.

 

13. Java provides a mechanism, called object serialization where an object can be represented as a sequence of bytes that includes the object’s data as well as information about the object’s type and the types of data stored in the object.

 

14. Sockets provide the communication mechanism between two computers using TCP. A client program creates a socket on its end of the communication and attempts to connect that socket to a server.

 

15. Java is a multi-threaded programming language which means we can develop multi-threaded program using Java. A multi-threaded program contains two or more parts that can run concurrently and each part can handle a different task at the same time making optimal use of the available resources specially when your computer has multiple CPUs.

1) Create a Thread by Implementing a Runnable Interface

2) Create a Thread by Extending a Thread Class

 

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. 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

Programming Reflection May 17

wpid-Programming-Wallpaper-3
1. Array is easy to index specific element with index, it’s easier to calculate the difference between different elements than linked list.
2. LeetCode Trap Rain Water problem: iterate left and right elements for each element in the input array, update left and right largest number if larger than the current ones, then get difference between current element and min (leftLargest, rightLargest) as the water in current bucket.
3. Permutation algorithm: one solution is switch each element with current depth element, another one is to remove each element temporarily and go to next depth to generate permutation recursively (recursion can scale down the problem set)
Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. 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:

Clean Code: A Handbook of Agile Software Craftsmanship

Ruminations on C++: A Decade of Programming Insight and Experience

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

Node.js Production Tips

download

1. Slug Routes:

slug-routes gives you the ability to use some unique piece of data to represent your records in URLs other than the ID.

https://github.com/felixkiss/slug-routes

 

2. Docker

Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-getting-started

https://docs.docker.com/get-started/

SWARM_sm

 

3. Canonical URL

It allows you to tell search engines that certain similar URLs are actually one and the same. Sometimes you have products or content that is accessible under multiple URLs, or even on multiple websites.

https://yoast.com/rel-canonical/

 

4. Node.js production experience, tips

From Python to Node.js, then back to Python, JS is Easy to learn, impossible to master

https://blog.geekforbrains.com/after-a-year-of-using-nodejs-in-production-78eecef1f65a

 

Paul Graham was asked about ideal programming language, he said, “I mean, we have had startups writing their code in PHP – and that worries me a little bit. But not as much as other things worry me.”

https://www.nemil.com/musings/shinyandnew.html

 

Hard won lessons five years with Node.js

https://blog.scottnonnenberg.com/hard-won-lessons-five-years-with-node-js/

 

Node.js and ES6 Instead of Java – A War Story

http://www.technology-ebay.de/the-teams/mobile-de/blog/nodejs-es6-war-story

 

Node.js single thread event loop is easy to stack tons of callback to crash the whole process, they have to manually restart the microservice after a period of time

http://blog.digg.com/post/141552444676/making-the-switch-from-nodejs-to-golang
5. Engineering Culture

Software development should be thought of as a cycle of continual learning and improvement rather a progression from start to finish, or a search for correctness.

https://medium.com/@kellan/five-years-building-a-culture-and-handing-it-off-54a38c3ab8de

 

Dogfooding culture, all employees install the latest version, test and report bugs.

https://codeascraft.com/2014/02/28/etsys-journey-to-continuous-integration-for-mobile-apps

 

“To keep the business going with a relatively small staff, we need to consistently punch above our weight.”

https://techcrunch.com/2015/04/27/etsy-cto-on-its-conservatively-crafty-tech-philosophy/

Donate $5 to me for a coffee with PayPal and read more professional and interesting technical blog articles. 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.

Resource:

A Smarter Way to Learn JavaScript. The new tech-assisted approach that requires half the effort

Secrets of the JavaScript Ninja

Node.js Design Patterns

Web Development with MongoDB and NodeJS

Node.js the Right Way: Practical, Server-Side JavaScript That Scales

Web Development with Node and Express: Leveraging the JavaScript Stack

Learn NodeJS in 1 Day: Complete Node JS Guide with Examples

Learning Node: Moving to the Server-Side

Getting MEAN with Mongo, Express, Angular, and Node

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