Sam's Chest of Drawers

Thinking about Programming and Lifestyle


  • Home

  • Categories

  • Archives

  • Tags

Mind Map of Backend

Posted on 07-05-2017 | In Mind Map

Backend tends to have a totally different topics than Web (frontend). What’s more, before putting too many items into “Mind Map of Web”, creating a new mind-map slot for backend is quite reasonable. Additionally, classical topics about algorithm are also appropriate here for the reason of an obvious different focus from frontend. So all these facts bring about a new mind map for backend.

Map

Keywords Comment & Reference
distributed system Nginx (read as “engine X”) Concepts of Distributed System
dynamic programming Comment, introduction by comic
compile compile introduction
bitwise operation is-power-of-2, find-odd-number
greatest common divider introduction by comic
max difference within array introduction by comic
circular linked list detect Given node length known introduction by comic
js dependency Comment a js project template
git merge rebase fixup autosquash feature branch see my post “Feature Branch Workflow”, cheat-sheet
slf4j logback MDC kafka Comment
CAP Eventual Consistency nosql kafka RabbitMQ MongoDB HBase Cassandra Redis Neo4j Comment
https Introduction
git mergetool kdiff3 Comment
flashcard with Anki and Studies Anki Studies
IDE vim, intellij Comment, java8-compile-idea
java nio Comment
java concurrency Comment
linux command commands
disk clean (for Mac) link
e-book site (for IT) finelybook (down since 2017.9, not sure the future), salttiger, archive.org
math support for markdown codecogs.com
unicode [unicode][#unicode]
Read more »

Sorting Performance

Posted on 05-23-2017 | In Programming

Recently, I did some study on sorting algorithms and I’m amazed to find that the sort from standard Java Runtime Environment (JRE) is NOT as efficient as I expected. According to Java-DOC’s description:

public static <T> void sort(T[] a, Comparator<? super T> c)

Sorts the specified array of objects according to the order induced by the specified comparator. All elements in the array must be mutually comparable by the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the array).

This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.
Implementation note: This implementation is a stable, adaptive, iterative mergesort that requires far fewer than n lg(n) comparisons when the input array is partially sorted, while offering the performance of a traditional mergesort when the input array is randomly ordered. If the input array is nearly sorted, the implementation requires approximately n comparisons. Temporary storage requirements vary from a small constant for nearly sorted input arrays to n/2 object references for randomly ordered input arrays.

The implementation takes equal advantage of ascending and descending order in its input array, and can take advantage of ascending and descending order in different parts of the the same input array. It is well-suited to merging two or more sorted arrays: simply concatenate the arrays and sort the resulting array.

The implementation was adapted from Tim Peters’s list sort for Python ( TimSort). It uses techniques from Peter McIlroy’s “Optimistic Sorting and Information Theoretic Complexity”, in Proceedings of the Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474, January 1993.

I have checked another sort method’s description:

Implementation note: The sorting algorithm is a Dual-Pivot Quicksort by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm offers O(n log(n)) performance on many data sets that cause other quicksorts to degrade to quadratic performance, and is typically faster than traditional (one-pivot) Quicksort implementations.

So I’m curious to know how good the built-in sort is and whether my home-made sort can defeat it. It sounds like playing with AlphaGo, but I still decide to have a go. For the completeness, I include elementary sorting methods e.g. select sort, insert sort and shell sort, which have the performance of
,
as well as more advanced sort e.g. merge sort and quick sort with the performance of
.
Here is the detailed source code.

Read more »

MVC, MVP, MVVM and Redux

Posted on 05-15-2017 | In Programming

Problem

  • View controller is getting bigger and bigger
  • View controller keeps data (or cached data)
  • View controller is NOT testable
  • View controllers tend to have complicated interaction
  • Model is dumb data structure
Read more »

Swift For Java Programmer 4

Posted on 05-10-2017 | In Programming

Let’s focus on Pattern matching, a powerful language feature in Swift. When I first saw this in blogs or articles, I felt confused and even complained about why people added this into Swift so that more often than not there are more than one way to achieve the same thing. For programmers from other world (like Java), it’s hard to accept since most of them believe in the principle that simplicity is beauty.

I find this tutorial very helpful and use an online Swift runner due to the lack of Swift compiler implementation on Windows. Note this is the only runner that supports Foundations.

Edited on [May 11, 2017]: another thorough tutorial

Read more »

Swift For Java Programmer 3

Posted on 05-09-2017 | In Programming

In the third series, let’s start the part of class. In Swift, class is reference type, which has a lot in common with this concept in other programming language like Java, c# and Javascript.

super

For a normal override method in sub-class, it’s always better to call its super method at the very beginning of the method. Otherwise, the logic in sub-class could get overwritten by the base class.

For the same reason, inside init, sub-class MUST call super.init before returning. It’s called two-phase initialization.

class SubClass: BaseClass {
  var sth: String
  init(...) {
    // phase 1 start
    self.sth = ...
    super.init(...)
    // phase 2 start
    self.foo()
  }
  foo() {...}
}

We can’t call any instance method until phase 2 because at that time the initialization has been completed.

Read more »

Swift For Java Programmer 2

Posted on 05-08-2017 | In Programming

In this second series, I want to talk about struct, which is a rather new concept for Java programmer.

Value type

First of all, remember struct is value type (in comparison with reference type as class) so that on assignment instances are COPIED. It has the following impact:

  1. The instance will be allocated in stack (instead of heap), which means it could be fast and has trouble-free for memory management.

  2. If the variable is declared as let instance = ..., then there is no way to modify the value, including its properties. The fix is to use var instance = ....

  3. The above case is for the case that we modify the struct instance by changing the property. If the change is via a method, then the method needs to be marked as mutating(so that the compiler knows it can’t be called for a constant struct instance).

  4. Other instances, which were copied from the original instance, have no impact if the original instance get changed. The same behavior as integer, boolean and string in Java. That’s also the reason that in Swift, Int, Bool and String (and other primitives) are defined as struct.

Read more »

Swift For Java Programer 1

Posted on 05-07-2017 | In Programming

External & internal parameter name

The point is using nouns as internal name for function body, while using conjunction as external name for function consumer so that from the viewpoint of client, the calling of API looks like a meaningful sentence. For example:

func daysOfMonth(_ month: Int, in year: Int) {…}
let days = daysOfMonth(2, in: 2017);
Read more »

Change Detection in Angular

Posted on 04-20-2017 | In Programming

The Timing of CD

During asynchronous events:
Events (button click…)
XHR requests
setTimeout

How CD Works

Trigger from and flow one-way down the component tree

Read more »

Reactive Form in Angular

Posted on 04-10-2017 | In Programming

FormControl’s valueChanges

It gives Observable, which takes us from plain event data into observable data flow. It’s one way for child components to have (local) communication between themselves.

switchMap vs flatMap

The former unsubscribes from the previous subscriptions as soon as the outer Observable emits new values.

Read more »

When Angular meets Redux

Posted on 03-24-2017 | In Programming

Introduction

It’s quite a long time after the last post. Although keeping learning in a systematic way in this period, I find it more difficult than expected to come up with a post with decent insight. Fortunately, I got an assignment in the workplace to build a prototype GUI with Angular technology. It’s a good opportunity to make use of the front-end knowledge from books as well as the articles from the Internet. It’s the major source to let me write down the following words of my feeling and understanding when working in an Angular project.

As usual, I’m used to getting the development environment ready before getting my hands into code. I have a bit experience of AngularJS, which reminds me of how a heavyweight framework AngularJS is, especially comparing with other frameworks (e.g. Vue) or libraries (e.g. JQuery). An obvious indication of this fact is that I need lots of boilerplate configuration and code to prepare the project before I can start coding the first line of business logic. Angular (2) improves in this area with a powerful command line tool, @angular/cli (previously known as angular-cli). So we’ll start from this tool.

Read more »
12345
Yuping Wang

Yuping Wang

85608565

43 posts
5 categories
30 tags
Github Twitter
© 2016 - 2020 Yuping Wang
Powered by Hexo
Theme - NexT.Muse