<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Welcome to Seven's page</title>
    <description>My personal git page about Java, JavaScript and Python.
</description>
    <link>https://seven.github.io/</link>
    <atom:link href="https://seven.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Sun, 05 Nov 2017 03:36:06 +0000</pubDate>
    <lastBuildDate>Sun, 05 Nov 2017 03:36:06 +0000</lastBuildDate>
    <generator>Jekyll v3.6.2</generator>
    
      <item>
        <title>hash table and algorithm</title>
        <description>&lt;h1 id=&quot;hashing-function&quot;&gt;hashing function&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;collision resistance
    &lt;ul&gt;
      &lt;li&gt;attach SHA1/MD5
less than 2^(N/2), N bits of hash output.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;uniform distribution&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;collision-resolution&quot;&gt;collision resolution&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;chaining with list/RBT/…
    &lt;ul&gt;
      &lt;li&gt;linkedlist vs RBT&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;open address
(hash(key)+ di) mod m, ith times to collision
    &lt;ul&gt;
      &lt;li&gt;how to avoid &lt;strong&gt;cluster&lt;/strong&gt;?&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;hash-open-address-application-in-java-api&quot;&gt;hash open address application in java api&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;ThreadLocalMap
 ```java&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;private Entry getEntry(ThreadLocal&amp;lt;?&amp;gt; key) {
    int i = key.threadLocalHashCode &amp;amp; (table.length - 1);
    Entry e = table[i];
    if (e != null &amp;amp;&amp;amp; e.get() == key)
        return e;
    else
        return getEntryAfterMiss(key, i, e); //
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  
# hash chaining application in java api 
    * LinkedHashMap
      - double-linked list
      - access order by move access node to last
      - default by insert order
    * Hashtable
      - chaining with single linked list
      - indexing
          - hashtable: int index = (hash &amp;amp; 0x7FFFFFFF) % tab.length;
          - hashmap:   int index = (hash ^ (hash&amp;gt;&amp;gt;&amp;gt;16)) % (tab.length-1);
    * HashMap
      - if binCount &amp;lt;6, untrieefy to list 
      - if binCount &amp;gt;8, (if table.length &amp;gt;64, trieefy to RBT; else resize())
      - if map.size &amp;gt; (threshold=capacity*loadfactor), resize()

```java

     /**
       * The maximum capacity, used if a higher value is implicitly specified
       * by either of the constructors with arguments.
       * MUST be a power of two &amp;lt;= 1&amp;lt;&amp;lt;30.
       */
      static final int MAXIMUM_CAPACITY = 1 &amp;lt;&amp;lt; 30;

      /**
       * The load factor used when none specified in constructor.
       */
      static final float DEFAULT_LOAD_FACTOR = 0.75f;

      /**
       * The bin count threshold for using a tree rather than list for a
       * bin.  Bins are converted to trees when adding an element to a
       * bin with at least this many nodes. The value must be greater
       * than 2 and should be at least 8 to mesh with assumptions in
       * tree removal about conversion back to plain bins upon
       * shrinkage.
       */
      static final int TREEIFY_THRESHOLD = 8;

      /**
       * The bin count threshold for untreeifying a (split) bin during a
       * resize operation. Should be less than TREEIFY_THRESHOLD, and at
       * most 6 to mesh with shrinkage detection under removal.
       */
      static final int UNTREEIFY_THRESHOLD = 6;

      /**
       * The smallest table capacity for which bins may be treeified.
       * (Otherwise the table is resized if too many nodes in a bin.)
       * Should be at least 4 * TREEIFY_THRESHOLD to avoid conflicts
       * between resizing and treeification thresholds.
       */
      static final int MIN_TREEIFY_CAPACITY = 64;
      /**
       * The table, initialized on first use, and resized as
       * necessary. When allocated, length is always a power of two.
       * (We also tolerate length zero in some operations to allow
       * bootstrapping mechanics that are currently not needed.)
       * RBT Or LinkedList
       */
      transient Node&amp;lt;K,V&amp;gt;[] table;

      /**
       * The number of key-value mappings contained in this map.
       */
      transient int size;

      /**
       * The number of times this HashMap has been structurally modified
       * Structural modifications are those that change the number of mappings in
       * the HashMap or otherwise modify its internal structure (e.g.,
       * rehash).  This field is used to make iterators on Collection-views of
       * the HashMap fail-fast.  (See ConcurrentModificationException).
       */
      transient int modCount;

      /**
       * The next size value at which to resize (capacity * load factor).
       *
       * @serial
       */
      int threshold;

      /**
       * The load factor for the hash table.
       *
       * @serial
       */
      final float loadFactor;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;java-author-joshua-j-bloch&quot;&gt;Java author Joshua J. Bloch&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;the Java Collections Framework&lt;/li&gt;
  &lt;li&gt;http://www.javaworld.com/article/2073877/core-java/joshua-bloch–a-conversation-about-design.html&lt;/li&gt;
  &lt;li&gt;http://www.oracle.com/technetwork/articles/javase/bloch-effective-08-qa-140880.html&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;distributed-hashtable&quot;&gt;Distributed HashTable&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;DHT need to handle:
    &lt;ul&gt;
      &lt;li&gt;autonomy and decentralization&lt;/li&gt;
      &lt;li&gt;fault tolerance&lt;/li&gt;
      &lt;li&gt;scalability&lt;/li&gt;
      &lt;li&gt;load balance&lt;/li&gt;
      &lt;li&gt;data integrity&lt;/li&gt;
      &lt;li&gt;performance (routing/storage/retrieval)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Keyspace partitioning
Task: removal or addition of one node changes only the set of keys owned by the nodes with adjacent IDs, and leaves all other nodes unaffected.
    &lt;ul&gt;
      &lt;li&gt;Consistent hashing
hashing ring + tags&lt;/li&gt;
      &lt;li&gt;Rendezvous hashing
client side: highest random weight hashing, selected = max((h(s,key) for s in serverlist)&lt;/li&gt;
      &lt;li&gt;Locality-preserving hashing
efficient range query by ensure that similar keys are assigned to similar objects.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;bloomfilter&quot;&gt;Bloomfilter&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;used to test whether an element is a member of a set.&lt;/li&gt;
  &lt;li&gt;False positive matches are possible, but false negatives are not&lt;/li&gt;
  &lt;li&gt;– in other words, a query returns either “possibly in set” or “definitely not in set”.&lt;/li&gt;
  &lt;li&gt;Elements can be added to the set, but not removed (though this can be addressed with a “counting” removed_filter, but add removed items back is not supported.);&lt;/li&gt;
  &lt;li&gt;the more elements that are added to the set, the larger the probability of false positives.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;state&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashIterations&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;hashIterations&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;indexes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hash&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashIterations&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bits&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;hash&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;byte&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iterations&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hash1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LongHashFunction&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;xx_r39&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;hashBytes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hash2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LongHashFunction&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;farmUo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;hashBytes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;indexes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;iterations&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;];&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hash&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hash1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;iterations&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;indexes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hash&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Long&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;MAX_VALUE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;hash&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hash2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;hash&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hash1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;indexes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;reference&quot;&gt;Reference&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;https://en.wikipedia.org/wiki/Poisson_distribution&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Wed, 05 Apr 2017 00:00:00 +0000</pubDate>
        <link>https://seven.github.io/java/2017/04/05/hash_table.html</link>
        <guid isPermaLink="true">https://seven.github.io/java/2017/04/05/hash_table.html</guid>
        
        
        <category>java</category>
        
      </item>
    
      <item>
        <title>famous authors in Java</title>
        <description>&lt;h1 id=&quot;james-arthur-gosling&quot;&gt;James Arthur Gosling&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;Java VM father&lt;/li&gt;
  &lt;li&gt;Scala advisor&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;douglas-s-lee&quot;&gt;Douglas S. Lee&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;concurrent data structures&lt;/li&gt;
  &lt;li&gt;http://gee.cs.oswego.edu/dl/index.html&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;joshua-j-bloch&quot;&gt;Joshua J. Bloch&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;the Java Collections Framework&lt;/li&gt;
  &lt;li&gt;the java.math package&lt;/li&gt;
  &lt;li&gt;the assert mechanism&lt;/li&gt;
  &lt;li&gt;http://www.javaworld.com/article/2073877/core-java/joshua-bloch–a-conversation-about-design.html&lt;/li&gt;
  &lt;li&gt;http://www.oracle.com/technetwork/articles/javase/bloch-effective-08-qa-140880.html&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;todo&quot;&gt;TODO&lt;/h1&gt;
</description>
        <pubDate>Wed, 05 Apr 2017 00:00:00 +0000</pubDate>
        <link>https://seven.github.io/java/2017/04/05/famous_java_author.html</link>
        <guid isPermaLink="true">https://seven.github.io/java/2017/04/05/famous_java_author.html</guid>
        
        
        <category>java</category>
        
      </item>
    
      <item>
        <title>LCS algorithm</title>
        <description>&lt;h1 id=&quot;lcs-large-common-subsequence&quot;&gt;LCS large common subsequence&lt;/h1&gt;

&lt;p&gt;In general, LCS algorithms can be solved in O(m∗n)O(m∗n) time and space using basic dynamic programming. 
Hirschberg’s algorithm reduces the space requirement to O(min(m,n))O(min(m,n)), thus making it feasible for very large substrings (time is usually cheaper than memory)&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* DP
input: x[m], y[n]
optimal substructure: f[m-1][n-1]= f[m-2][n-2]+1 if x[m-1]==y[n-1] else max(f[m-1][n-2],f[m-2][n-1])
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# A Naive recursive Python implementation of LCS problem&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;lcs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]:&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lcs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
       &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lcs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lcs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;lcs2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# find the length of the strings&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
 
    &lt;span class=&quot;c&quot;&gt;# declaring the array for storing the dp values&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
 
    &lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;Following steps build L[m+1][n+1] in bottom up fashion
    Note: L[i][j] contains length of LCS of X[0..i-1]
    and Y[0..j-1]&quot;&quot;&quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
 
    &lt;span class=&quot;c&quot;&gt;# L[m][n] contains the length of LCS of X[0..n-1] &amp;amp; Y[0..m-1]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;L&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#end of function lcs&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;lcs-large-common-substring&quot;&gt;&lt;strong&gt;LCs&lt;/strong&gt; large common substring&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;DP
O(nm)&lt;/li&gt;
  &lt;li&gt;suffix tree 
time: O(n+m)&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;application&quot;&gt;application&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;diff&lt;/li&gt;
  &lt;li&gt;git merge&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;reference&quot;&gt;Reference&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;https://en.wikipedia.org/wiki/Hirschberg%27s_algorithm&lt;/li&gt;
  &lt;li&gt;LUCS https://leetcode.com/problems/longest-uncommon-subsequence-ii/#/description&lt;/li&gt;
  &lt;li&gt;Reverse Index&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Wed, 05 Apr 2017 00:00:00 +0000</pubDate>
        <link>https://seven.github.io/algorithm/2017/04/05/LCS_algorithm.html</link>
        <guid isPermaLink="true">https://seven.github.io/algorithm/2017/04/05/LCS_algorithm.html</guid>
        
        
        <category>algorithm</category>
        
      </item>
    
      <item>
        <title>count distinct problem</title>
        <description>&lt;h2 id=&quot;streaming-algorithm&quot;&gt;streaming algorithm&lt;/h2&gt;

&lt;h1 id=&quot;hyperloglog&quot;&gt;HyperLogLog&lt;/h1&gt;

&lt;h2 id=&quot;online-algorithm&quot;&gt;online algorithm&lt;/h2&gt;

&lt;h1 id=&quot;ref&quot;&gt;Ref&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://web.archive.org/web/20150323055945/http://research.neustar.biz/2012/10/25/sketch-of-the-day-hyperloglog-cornerstone-of-a-big-data-infrastructure/&quot;&gt;HyperLogLog&lt;/a&gt;&lt;/p&gt;
</description>
        <pubDate>Thu, 23 Mar 2017 00:47:14 +0000</pubDate>
        <link>https://seven.github.io/algorithm/2017/03/23/count_distinct_problem.html</link>
        <guid isPermaLink="true">https://seven.github.io/algorithm/2017/03/23/count_distinct_problem.html</guid>
        
        
        <category>algorithm</category>
        
      </item>
    
      <item>
        <title>markdown mode in emacs</title>
        <description>&lt;h1 id=&quot;h1-markdown-mode-in-emacs&quot;&gt;h1: markdown mode in emacs&lt;/h1&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# h1: markdown mode in emacs #
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;h2-styles&quot;&gt;h2 styles&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;## h2 styles ##
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;bold&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;**bold**
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;list items&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;a&lt;/li&gt;
  &lt;li&gt;b
    &lt;ul&gt;
      &lt;li&gt;a&lt;/li&gt;
      &lt;li&gt;b&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* a
* b
  * a
  * b
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;quotes&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;line1…&lt;br /&gt;
line1&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;line2&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt;line1...&amp;lt;br&amp;gt;
line1

&amp;gt;line2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;links&lt;br /&gt;
&lt;a href=&quot;http://google.com&quot;&gt;google&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[google](http://google.com)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;h2-code-block&quot;&gt;h2 code block&lt;/h2&gt;

&lt;p&gt;inline code &lt;code class=&quot;highlighter-rouge&quot;&gt;alert(s)&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;inline code `alert(s)`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;python code&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;```python
def say:
    yield 1
    pass
```
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;say&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;yield&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Sun, 19 Mar 2017 07:47:56 +0000</pubDate>
        <link>https://seven.github.io/admin/2017/03/19/markdown-mode-in-emacs.html</link>
        <guid isPermaLink="true">https://seven.github.io/admin/2017/03/19/markdown-mode-in-emacs.html</guid>
        
        
        <category>admin</category>
        
      </item>
    
      <item>
        <title>redis study notes</title>
        <description>&lt;p&gt;redis key notes&lt;/p&gt;

&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#redis-data-types&quot; id=&quot;markdown-toc-redis-data-types&quot;&gt;redis data types&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#cluster-design&quot; id=&quot;markdown-toc-cluster-design&quot;&gt;cluster design&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#write-safety&quot; id=&quot;markdown-toc-write-safety&quot;&gt;write safety&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#redis-cluster-protocol&quot; id=&quot;markdown-toc-redis-cluster-protocol&quot;&gt;Redis cluster protocol&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#nodes-handshake-on-discovering&quot; id=&quot;markdown-toc-nodes-handshake-on-discovering&quot;&gt;nodes handshake on discovering&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#fault-tolerance&quot; id=&quot;markdown-toc-fault-tolerance&quot;&gt;fault tolerance&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#slave-election--promotion&quot; id=&quot;markdown-toc-slave-election--promotion&quot;&gt;slave election / promotion&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#sentinel&quot; id=&quot;markdown-toc-sentinel&quot;&gt;Sentinel&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#quorum&quot; id=&quot;markdown-toc-quorum&quot;&gt;quorum&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#tilt-mode&quot; id=&quot;markdown-toc-tilt-mode&quot;&gt;TILT mode&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#keys-distribution-model&quot; id=&quot;markdown-toc-keys-distribution-model&quot;&gt;keys distribution model&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#hash-slothash-tag&quot; id=&quot;markdown-toc-hash-slothash-tag&quot;&gt;hash slot/hash tag&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#hash-algorithm&quot; id=&quot;markdown-toc-hash-algorithm&quot;&gt;hash algorithm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#consistent-hash&quot; id=&quot;markdown-toc-consistent-hash&quot;&gt;consistent hash&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#redlock&quot; id=&quot;markdown-toc-redlock&quot;&gt;RedLock&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#algorithm&quot; id=&quot;markdown-toc-algorithm&quot;&gt;algorithm&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#raft&quot; id=&quot;markdown-toc-raft&quot;&gt;Raft&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#roles&quot; id=&quot;markdown-toc-roles&quot;&gt;roles&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#how-to-elect-leader&quot; id=&quot;markdown-toc-how-to-elect-leader&quot;&gt;how to elect leader?&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#how-to-replicate-log-entries&quot; id=&quot;markdown-toc-how-to-replicate-log-entries&quot;&gt;how to replicate log entries?&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#visualization-raftscope&quot; id=&quot;markdown-toc-visualization-raftscope&quot;&gt;visualization (RaftScope)&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#redisson&quot; id=&quot;markdown-toc-redisson&quot;&gt;Redisson&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#lock-implementation&quot; id=&quot;markdown-toc-lock-implementation&quot;&gt;lock implementation&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#unlock-implementation&quot; id=&quot;markdown-toc-unlock-implementation&quot;&gt;unlock implementation&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#questions&quot; id=&quot;markdown-toc-questions&quot;&gt;Questions:&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#reference&quot; id=&quot;markdown-toc-reference&quot;&gt;Reference:&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;redis-data-types&quot;&gt;redis data types&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;how to select redis key?
    &lt;ul&gt;
      &lt;li&gt;binary safe&lt;/li&gt;
      &lt;li&gt;schema, e.g. “comment:123:reply-to”&lt;/li&gt;
      &lt;li&gt;max key size = 512MB&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;string/list/capped list/set/range/bitmap&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;cluster-design&quot;&gt;cluster design&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;performance
    &lt;ul&gt;
      &lt;li&gt;async replication&lt;/li&gt;
      &lt;li&gt;avoid key-value version conflicts or merge&lt;/li&gt;
      &lt;li&gt;scaling readonly reads using slave nodes&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;scalability
    &lt;ul&gt;
      &lt;li&gt;add/remove nodes&lt;/li&gt;
      &lt;li&gt;redirection &amp;amp; resharding&lt;/li&gt;
      &lt;li&gt;key-node mapping&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;avaliability
    &lt;ul&gt;
      &lt;li&gt;failover&lt;/li&gt;
      &lt;li&gt;partition&lt;/li&gt;
      &lt;li&gt;persistent
        &lt;ul&gt;
          &lt;li&gt;AOF vs RDB Snapshot&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;replicate migration&lt;/strong&gt; for orphaned masters&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;write-safety&quot;&gt;write safety&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;failure cases
    &lt;ul&gt;
      &lt;li&gt;master die without write reaching slaves before slave promoted&lt;/li&gt;
      &lt;li&gt;out-of-date routing table in client side &lt;corner case=&quot;&quot;&gt;&lt;/corner&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;redis-cluster-protocol&quot;&gt;Redis cluster protocol&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;discover new nodes&lt;/li&gt;
  &lt;li&gt;promote slave to master&lt;/li&gt;
  &lt;li&gt;propagate Pub/Sub msg&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;nodes-handshake-on-discovering&quot;&gt;nodes handshake on discovering&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;admin command &lt;code class=&quot;highlighter-rouge&quot;&gt;CLUSTER MEET ip port&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;auto-discover into fully connnected graph&lt;/p&gt;

    &lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt; if A know B and B know C, then B send gossip msg to A about C&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;fault-tolerance&quot;&gt;fault tolerance&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;heartbeat &amp;amp; gossip msg
&lt;code class=&quot;highlighter-rouge&quot;&gt;ping/pong&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;failure detection
&lt;code class=&quot;highlighter-rouge&quot;&gt;PFAIL/FAIL flag&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;slave-election--promotion&quot;&gt;slave election / promotion&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;epoch - term in Raft&lt;/li&gt;
  &lt;li&gt;winer slave gain majority votes from masters&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;sentinel&quot;&gt;Sentinel&lt;/h2&gt;

&lt;h1 id=&quot;quorum&quot;&gt;quorum&lt;/h1&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* quorum - number of sentinels agree about master failure
* start failover only when, e.g. quorum=2, total=5
    * 2 agree about one master failure
    * 3+/majority sentinels reachable (=== no failover in minority partition)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;tilt-mode&quot;&gt;TILT mode&lt;/h1&gt;

&lt;p&gt;stop acting/response failure request until computer time resolved.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;if the time difference is negative or unexpectedly big (2 seconds or more) the TILT mode is entered (or if it was already entered the exit from the TILT mode postponed)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;keys-distribution-model&quot;&gt;keys distribution model&lt;/h2&gt;

&lt;h1 id=&quot;hash-slothash-tag&quot;&gt;hash slot/hash tag&lt;/h1&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;//HASH_SLOT = CRC16(key) mod 16384
def HASH_SLOT(key)
    s = key.index &quot;{&quot;
    if s
        e = key.index &quot;}&quot;,s+1
        if e &amp;amp;&amp;amp; e != s+1
            key = key[s+1..e-1]
        end
    end
    crc16(key) % 16384
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;hash-algorithm&quot;&gt;hash algorithm&lt;/h1&gt;

&lt;ul&gt;
  &lt;li&gt;how to select a hash function?
    &lt;ol&gt;
      &lt;li&gt;input data&lt;/li&gt;
      &lt;li&gt;probability distribution&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;consistent-hash&quot;&gt;consistent hash&lt;/h1&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* 1-n mapping: node-vnode
hashlist = hash(nodename+vnode[i]) for i in range(n)
rbt.add(hashlist)

* hit cache
h1 = hash(request)
cache = rbt.findCacheNode(h1)
response = cache.handle(request)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;redlock&quot;&gt;RedLock&lt;/h2&gt;

&lt;h1 id=&quot;algorithm&quot;&gt;algorithm&lt;/h1&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;if (cluster.acquireCount(key,val) &amp;gt; N/2+1) and elapsed_time &amp;lt; lock_validity_time:
    return true
else:
    cluster.unlockAll(key,val) 
    return false
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;raft&quot;&gt;Raft&lt;/h2&gt;

&lt;h1 id=&quot;roles&quot;&gt;roles&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;follower&lt;/li&gt;
  &lt;li&gt;candidate&lt;/li&gt;
  &lt;li&gt;leader&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;how-to-elect-leader&quot;&gt;how to elect leader?&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;terms&lt;/li&gt;
  &lt;li&gt;avoid split vote by randomized selection timeout&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;how-to-replicate-log-entries&quot;&gt;how to replicate log entries?&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;commit once log entry has replicated it on a majority of servers&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;visualization-raftscope&quot;&gt;visualization (RaftScope)&lt;/h1&gt;
&lt;p&gt;Here’s a Raft cluster running in your browser. You can interact with it to see Raft in action. Five servers are shown on the left, and their logs are shown on the right. We hope to create a screencast soon to explain what’s going on.&lt;/p&gt;
&lt;iframe src=&quot;https://raft.github.io/raftscope/index.html&quot; style=&quot;border: 0; width: 800px; height: 580px; margin-bottom: 20px&quot;&gt;&lt;/iframe&gt;

&lt;h2 id=&quot;redisson&quot;&gt;Redisson&lt;/h2&gt;

&lt;h2 id=&quot;lock-implementation&quot;&gt;lock implementation&lt;/h2&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RFuture&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;tryLockInnerAsync&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;leaseTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TimeUnit&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;long&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;threadId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RedisStrictCommand&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;internalLockLeaseTime&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;toMillis&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaseTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;commandExecutor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;evalWriteAsync&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LongCodec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;INSTANCE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
                  &lt;span class=&quot;s&quot;&gt;&quot;if (redis.call('exists', KEYS[1]) == 0) then &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                      &lt;span class=&quot;s&quot;&gt;&quot;redis.call('hset', KEYS[1], ARGV[2], 1); &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                      &lt;span class=&quot;s&quot;&gt;&quot;redis.call('pexpire', KEYS[1], ARGV[1]); &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                      &lt;span class=&quot;s&quot;&gt;&quot;return nil; &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                  &lt;span class=&quot;s&quot;&gt;&quot;end; &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                  &lt;span class=&quot;s&quot;&gt;&quot;if (redis.call('hexists', KEYS[1], ARGV[2]) == 1) then &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                      &lt;span class=&quot;s&quot;&gt;&quot;redis.call('hincrby', KEYS[1], ARGV[2], 1); &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                      &lt;span class=&quot;s&quot;&gt;&quot;redis.call('pexpire', KEYS[1], ARGV[1]); &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                      &lt;span class=&quot;s&quot;&gt;&quot;return nil; &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                  &lt;span class=&quot;s&quot;&gt;&quot;end; &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                  &lt;span class=&quot;s&quot;&gt;&quot;return redis.call('pttl', KEYS[1]);&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;Collections&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;singletonList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;internalLockLeaseTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getLockName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;threadId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;unlock-implementation&quot;&gt;unlock implementation&lt;/h2&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;unlock&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Boolean&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;opStatus&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;commandExecutor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;evalWrite&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LongCodec&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;INSTANCE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RedisCommands&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;EVAL_BOOLEAN&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;s&quot;&gt;&quot;if (redis.call('exists', KEYS[1]) == 0) then &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                            &lt;span class=&quot;s&quot;&gt;&quot;redis.call('publish', KEYS[2], ARGV[1]); &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                            &lt;span class=&quot;s&quot;&gt;&quot;return 1; &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                        &lt;span class=&quot;s&quot;&gt;&quot;end;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                        &lt;span class=&quot;s&quot;&gt;&quot;if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                            &lt;span class=&quot;s&quot;&gt;&quot;return nil;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                        &lt;span class=&quot;s&quot;&gt;&quot;end; &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                        &lt;span class=&quot;s&quot;&gt;&quot;local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                        &lt;span class=&quot;s&quot;&gt;&quot;if (counter &amp;gt; 0) then &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                            &lt;span class=&quot;s&quot;&gt;&quot;redis.call('pexpire', KEYS[1], ARGV[2]); &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                            &lt;span class=&quot;s&quot;&gt;&quot;return 0; &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                        &lt;span class=&quot;s&quot;&gt;&quot;else &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                            &lt;span class=&quot;s&quot;&gt;&quot;redis.call('del', KEYS[1]); &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                            &lt;span class=&quot;s&quot;&gt;&quot;redis.call('publish', KEYS[2], ARGV[1]); &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                            &lt;span class=&quot;s&quot;&gt;&quot;return 1; &quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                        &lt;span class=&quot;s&quot;&gt;&quot;end; &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                        &lt;span class=&quot;s&quot;&gt;&quot;return nil;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;Arrays&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;asList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getChannelName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LockPubSub&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;unlockMessage&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;internalLockLeaseTime&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getLockName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Thread&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;currentThread&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getId&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()));&lt;/span&gt;
                    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;questions&quot;&gt;Questions:&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1. How does redis provide high avaliability and reliability?
   - Redis Sentinel
   - Redis Cluster
     - scale/add node/add replica slave
     - slave replicas
       - replicas auto-migration
       - async-replicate --&amp;gt; weak consistency
     - data sharding/partition
       - hashing(hash slot) vs consistent hashing(hashring+vnode)
   - Raft algorithm

2. How to persistent and recovery data in Redis?
   - AOF
   - RDB

4. why redis is fast? 
   - memory
   - network 
     - no blocking i/o api (epoll/kqueue, edge trigger &amp;gt; level trigger) 
   - scaling reading(more read-only salves)/writing(sharding by more master)

5. user stories
   - DB vs cache
   - message broker
   - RedLock
   - Bloomfilter
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;reference&quot;&gt;Reference:&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://redis.io/topics/cluster-spec&quot;&gt;cluster spec&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://raft.github.io/&quot;&gt;Raft&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Paxos_(computer_science)&quot;&gt;Paxos&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://making.pusher.com/redis-pubsub-under-the-hood/&quot;&gt;Pub/Sub&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</description>
        <pubDate>Fri, 17 Mar 2017 07:47:56 +0000</pubDate>
        <link>https://seven.github.io/redis/2017/03/17/redis_notes.html</link>
        <guid isPermaLink="true">https://seven.github.io/redis/2017/03/17/redis_notes.html</guid>
        
        
        <category>redis</category>
        
      </item>
    
      <item>
        <title>emacs</title>
        <description>&lt;h1 id=&quot;emacs-configuration&quot;&gt;emacs configuration&lt;/h1&gt;

&lt;h2 id=&quot;use-vi-mode-as-default&quot;&gt;use vi-mode as default&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;
(require 'package)
(add-to-list 'package-archives '(&quot;melpa&quot; . &quot;http://melpa.org/packages/&quot;))
(package-initialize)
(require 'evil)
(evil-mode 1)
&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;install-package&quot;&gt;install package&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1. install org-mode
`M-x package-install RET org-mode RET`

2. install markdown
`M-x package-install RET markdown-mode RET`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;others&quot;&gt;Others&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1. input &quot;shell&quot; output
   e.g. C-u M-! date
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Fri, 17 Mar 2017 07:46:26 +0000</pubDate>
        <link>https://seven.github.io/admin/2017/03/17/17-emacs.html</link>
        <guid isPermaLink="true">https://seven.github.io/admin/2017/03/17/17-emacs.html</guid>
        
        
        <category>admin</category>
        
      </item>
    
      <item>
        <title>Java Technical Notes</title>
        <description>&lt;h1 id=&quot;java-technical-notes&quot;&gt;Java Technical Notes&lt;/h1&gt;

&lt;h1 id=&quot;kafka&quot;&gt;kafka&lt;/h1&gt;

&lt;p&gt;used for building real-time data pipelines and streaming apps.
scalable/fault-tolerant/fast&lt;/p&gt;

&lt;p&gt;ref: &lt;a href=&quot;https://kafka.apache.org&quot;&gt;kafka&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&quot;redis&quot;&gt;Redis&lt;/h1&gt;

&lt;h1 id=&quot;active-mqkafka&quot;&gt;Active MQ/Kafka&lt;/h1&gt;

&lt;h1 id=&quot;lucence-solr&quot;&gt;Lucence/ Solr&lt;/h1&gt;

&lt;h1 id=&quot;fastdfs&quot;&gt;FastDFS&lt;/h1&gt;

&lt;h1 id=&quot;mybatis--hibernate&quot;&gt;MyBatis / Hibernate&lt;/h1&gt;

&lt;h1 id=&quot;hashmap-history&quot;&gt;HashMap history&lt;/h1&gt;
&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1. linkedlist -&amp;gt; RBT
2. enhance hash algorithm in string
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;json&quot;&gt;json&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;how to parse json faster?
    &lt;ul&gt;
      &lt;li&gt;small memory footprint&lt;/li&gt;
      &lt;li&gt;stream API?&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Sat, 11 Mar 2017 03:24:55 +0000</pubDate>
        <link>https://seven.github.io/java/2017/03/10/java-technical-notes.html</link>
        <guid isPermaLink="true">https://seven.github.io/java/2017/03/10/java-technical-notes.html</guid>
        
        
        <category>Java</category>
        
      </item>
    
      <item>
        <title>front end study notes</title>
        <description>&lt;div id=&quot;table-of-contents&quot;&gt;
&lt;h2&gt;Table of Contents&lt;/h2&gt;
&lt;div id=&quot;text-table-of-contents&quot;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1&quot;&gt;1. javascript&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-1&quot;&gt;1.1. keywords&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-1-1&quot;&gt;1.1.1. closure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-1-2&quot;&gt;1.1.2. &quot;use strict&quot;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-1-3&quot;&gt;1.1.3. - &quot;prototype&quot;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-1-4&quot;&gt;1.1.4. - constructor&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-1-5&quot;&gt;1.1.5. - LexicalEnvironment | closure | block&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-1-6&quot;&gt;1.1.6. - ECMAScript ES3/ES5/ES6&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-1-7&quot;&gt;1.1.7. - typeof | instanceof | null | undefined&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-1-8&quot;&gt;1.1.8. - compare&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-1-9&quot;&gt;1.1.9. - this&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-2&quot;&gt;1.2. Built-in obj&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-3&quot;&gt;1.3. DOM document object model&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-4&quot;&gt;1.4. BOM browser object model&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-5&quot;&gt;1.5. FOP&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-5-1&quot;&gt;1.5.1. Arrow Functions =&amp;gt; (ES6 only, non IE support!)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-5-2&quot;&gt;1.5.2. forEach/for in/for of&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-5-3&quot;&gt;1.5.3. every/some&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-5-4&quot;&gt;1.5.4. reverse/sort&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-5-5&quot;&gt;1.5.5. map/reduce/filter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-5-6&quot;&gt;1.5.6. generator/yield/*yield&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-5-7&quot;&gt;1.5.7. Promise&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-6&quot;&gt;1.6. OOP patterns&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-6-1&quot;&gt;1.6.1. pseudo-class&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-7&quot;&gt;1.7. Event&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-7-1&quot;&gt;1.7.1. Asynchronous Event Queue&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-7-2&quot;&gt;1.7.2. Synchronous Event&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-8&quot;&gt;1.8. other source code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-1-9&quot;&gt;1.9. Ref&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-2&quot;&gt;2. CSS&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#sec-2-1&quot;&gt;2.1. CSS3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-2-2&quot;&gt;2.2. SASS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sec-2-3&quot;&gt;2.3. Compass&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;h1 id=&quot;javascript&quot;&gt;javascript&lt;a id=&quot;sec-1&quot; name=&quot;sec-1&quot;&gt;&lt;/a&gt;&lt;/h1&gt;

&lt;h2 id=&quot;keywords&quot;&gt;keywords&lt;a id=&quot;sec-1-1&quot; name=&quot;sec-1-1&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;h3 id=&quot;closure&quot;&gt;closure&lt;a id=&quot;sec-1-1-1&quot; name=&quot;sec-1-1-1&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;hide sth/ enable private method&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;use lexicalEnv as memoizer&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;use-strict&quot;&gt;“use strict”&lt;a id=&quot;sec-1-1-2&quot; name=&quot;sec-1-1-2&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h3 id=&quot;--prototype&quot;&gt;- “prototype”&lt;a id=&quot;sec-1-1-3&quot; name=&quot;sec-1-1-3&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;obj._&lt;sub&gt;proto&lt;/sub&gt;__&lt;/td&gt;
          &lt;td&gt;function.prototype/function._&lt;sub&gt;proto&lt;/sub&gt;__&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;ul&gt;
      &lt;li&gt;Object.create(proto, propertiesObject)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;obj = new Function;&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;obj._&lt;sub&gt;proto&lt;/sub&gt;__ = Function.prototype&lt;/li&gt;
      &lt;li&gt;obj.constructor = Function = Function.prototype.constructor&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;--constructor&quot;&gt;- constructor&lt;a id=&quot;sec-1-1-4&quot; name=&quot;sec-1-1-4&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;obj.constructor | Object.prototype.constructor
alert( rabbit.hasOwnProperty(‘constructor’) ) &lt;em&gt;/ false
alert( Rabbit.prototype.hasOwnProperty(‘constructor’) ) /&lt;/em&gt; true&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;--lexicalenvironment--closure--block&quot;&gt;- LexicalEnvironment | closure | block&lt;a id=&quot;sec-1-1-5&quot; name=&quot;sec-1-1-5&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h3 id=&quot;--ecmascript-es3es5es6&quot;&gt;- ECMAScript ES3/ES5/ES6&lt;a id=&quot;sec-1-1-6&quot; name=&quot;sec-1-1-6&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h3 id=&quot;--typeof--instanceof--null--undefined&quot;&gt;- typeof | instanceof | null | undefined&lt;a id=&quot;sec-1-1-7&quot; name=&quot;sec-1-1-7&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h3 id=&quot;--compare&quot;&gt;- compare&lt;a id=&quot;sec-1-1-8&quot; name=&quot;sec-1-1-8&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;stric equal &lt;code class=&quot;highlighter-rouge&quot;&gt;=&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;abstract equal ==&lt;/li&gt;
  &lt;li&gt;Object.is(val1,val2)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;--this&quot;&gt;- this&lt;a id=&quot;sec-1-1-9&quot; name=&quot;sec-1-1-9&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;called as obj.method&lt;/li&gt;
  &lt;li&gt;called as function
    &lt;ul&gt;
      &lt;li&gt;Window/Global/undefined (“use strict”)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;called in new&lt;/li&gt;
  &lt;li&gt;explicit this
func.call(context, args…)
func.apply(context, [arg]|args…)
func.bind(context, args…)()&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;built-in-obj&quot;&gt;Built-in obj&lt;a id=&quot;sec-1-2&quot; name=&quot;sec-1-2&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Function
    &lt;ol&gt;
      &lt;li&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;arguments&lt;/td&gt;
              &lt;td&gt;arguments.callee&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/li&gt;
      &lt;li&gt;static fields: arguments.callee.count&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;dom-document-object-model&quot;&gt;DOM document object model&lt;a id=&quot;sec-1-3&quot; name=&quot;sec-1-3&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;h2 id=&quot;bom-browser-object-model&quot;&gt;BOM browser object model&lt;a id=&quot;sec-1-4&quot; name=&quot;sec-1-4&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;alert/confirm/prompt&lt;/li&gt;
  &lt;li&gt;url&lt;/li&gt;
  &lt;li&gt;frame&lt;/li&gt;
  &lt;li&gt;XMLHttpRequest&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;fop&quot;&gt;FOP&lt;a id=&quot;sec-1-5&quot; name=&quot;sec-1-5&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;h3 id=&quot;arrow-functions--es6-only-non-ie-support&quot;&gt;Arrow Functions =&amp;gt; (ES6 only, non IE support!)&lt;a id=&quot;sec-1-5-1&quot; name=&quot;sec-1-5-1&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;definition&lt;/p&gt;

    &lt;p&gt;An arrow function expression has a shorter syntax than a function expression and does not bind its own this, arguments, super, or new.target. 
These function expressions are best suited for non-method functions, and they cannot be used as constructors.&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;(param1, param2, …, paramN) =&amp;gt; { statements }
(param1, param2, …, paramN) =&amp;gt; expression
// equivalent to: (param1, param2, …, paramN) =&amp;gt; { return expression; }
    
// Parentheses are optional when there's only one parameter:
(singleParam) =&amp;gt; { statements }
singleParam =&amp;gt; { statements }
    
// A function with no parameters requires parentheses:
() =&amp;gt; { statements }
() =&amp;gt; expression // equivalent to: () =&amp;gt; { return expression; }
    
// Parenthesize the body to return an object literal expression:
params =&amp;gt; ({foo: bar})
    
// Rest parameters and default parameters are supported
(param1, param2, ...rest) =&amp;gt; { statements }
(param1 = defaultValue1, param2, …, paramN = defaultValueN) =&amp;gt; { statements }
    
// Destructuring within the parameter list is also supported
var f = ([a, b] = [1, 2], {x: c} = {x: a + b}) =&amp;gt; a + b + c;
f();  // 6
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;not bind its own this, arguments, super, or new.target; not as constructor&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;'use strict';
var obj = {
  i: 10,
  b: () =&amp;gt; console.log(this.i, this),
  c: function() {
    console.log(this.i, this);
  }
}
obj.b(); // prints undefined, undefined
obj.c(); // prints 10, Object {...}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;foreachfor-infor-of&quot;&gt;forEach/for in/for of&lt;a id=&quot;sec-1-5-2&quot; name=&quot;sec-1-5-2&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var s = 'a𝓌a';
for(var c of s) console.log(c);

for(var c in s) console.log(s[c]);
Array.prototype.forEach.call(s, c =&amp;gt; console.log(c));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;everysome&quot;&gt;every/some&lt;a id=&quot;sec-1-5-3&quot; name=&quot;sec-1-5-3&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h3 id=&quot;reversesort&quot;&gt;reverse/sort&lt;a id=&quot;sec-1-5-4&quot; name=&quot;sec-1-5-4&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h3 id=&quot;mapreducefilter&quot;&gt;map/reduce/filter&lt;a id=&quot;sec-1-5-5&quot; name=&quot;sec-1-5-5&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var materials = ['Hydrogen', 'Helium', 'Lithium', 'Beryllium'];
var result = materials.map(material =&amp;gt; material.length).filter(n=&amp;gt;n&amp;gt;7).reduce((a,b)=&amp;gt;a+b);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;reduce&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[0, 1, 2, 3, 4].reduce( (accumulator, currentValue, currentIndex, array) =&amp;gt; accumulator + currentValue,
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;100
);&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;generatoryieldyield&quot;&gt;generator/yield/*yield&lt;a id=&quot;sec-1-5-6&quot; name=&quot;sec-1-5-6&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h3 id=&quot;promise&quot;&gt;Promise&lt;a id=&quot;sec-1-5-7&quot; name=&quot;sec-1-5-7&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h2 id=&quot;oop-patterns&quot;&gt;OOP patterns&lt;a id=&quot;sec-1-6&quot; name=&quot;sec-1-6&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;h3 id=&quot;pseudo-class&quot;&gt;pseudo-class&lt;a id=&quot;sec-1-6-1&quot; name=&quot;sec-1-6-1&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;function Hamster() { 
  this.food = []
}
Hamster.prototype = {
  found: function(something) {
    this.food.push(something)
  }
}

speedy = new Hamster()
lazy = new Hamster()

speedy.found(&quot;apple&quot;)
speedy.found(&quot;orange&quot;)

alert(speedy.food.length) // 2
alert(lazy.food.length) // 0(!)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;event&quot;&gt;Event&lt;a id=&quot;sec-1-7&quot; name=&quot;sec-1-7&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;h3 id=&quot;asynchronous-event-queue&quot;&gt;Asynchronous Event Queue&lt;a id=&quot;sec-1-7-1&quot; name=&quot;sec-1-7-1&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h3 id=&quot;synchronous-event&quot;&gt;Synchronous Event&lt;a id=&quot;sec-1-7-2&quot; name=&quot;sec-1-7-2&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;h2 id=&quot;other-source-code&quot;&gt;other source code&lt;a id=&quot;sec-1-8&quot; name=&quot;sec-1-8&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 1. Function declarations are initialized before the code is executed.
// window = { f: function }

// 2. Variables are added as window properties.
// window = { f: function, a: undefined, g: undefined }

var a = 5   // &amp;lt;-- var

function f(arg) { alert('f:'+arg) }

var g = function(arg) { alert('g:'+arg) } // &amp;lt;-- var

//read vs set
function f() {
  x = 5 // writing x puts it into outmost LexicalEnvironment
  console.log(typeof y); //undefined
  console.log(abc); //error
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;ref&quot;&gt;Ref&lt;a id=&quot;sec-1-9&quot; name=&quot;sec-1-9&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;javascript.info
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;http://javascript.info/tutorial/inheritance#inheritance-the-proto&quot;&gt;http://javascript.info/tutorial/inheritance#inheritance-the-proto&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;google: RegExp mdc/ regexp msdn jscript&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;css&quot;&gt;CSS&lt;a id=&quot;sec-2&quot; name=&quot;sec-2&quot;&gt;&lt;/a&gt;&lt;/h1&gt;

&lt;h2 id=&quot;css3&quot;&gt;CSS3&lt;a id=&quot;sec-2-1&quot; name=&quot;sec-2-1&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;h2 id=&quot;sass&quot;&gt;SASS&lt;a id=&quot;sec-2-2&quot; name=&quot;sec-2-2&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;Sass is an extension of CSS3 which adds nested rules, variables, mixins, selector inheritance, and more. 
Sass generates well formatted CSS and makes your stylesheets easier to organize and maintain.&lt;/p&gt;

&lt;h2 id=&quot;compass&quot;&gt;Compass&lt;a id=&quot;sec-2-3&quot; name=&quot;sec-2-3&quot;&gt;&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;Compass is an open-source CSS authoring framework which uses the Sass stylesheet language to make writing stylesheets powerful and easy.&lt;/p&gt;
</description>
        <pubDate>Thu, 02 Mar 2017 03:24:55 +0000</pubDate>
        <link>https://seven.github.io/front_end/2017/03/01/front-end-notes.html</link>
        <guid isPermaLink="true">https://seven.github.io/front_end/2017/03/01/front-end-notes.html</guid>
        
        
        <category>front_end</category>
        
      </item>
    
      <item>
        <title>Welcome to personal page powered by Jekyll!</title>
        <description>&lt;h1 id=&quot;jekyll&quot;&gt;Jekyll&lt;/h1&gt;

&lt;p&gt;This is my first post with Jekyll.
Check out the &lt;a href=&quot;http://jekyllrb.com/docs/home&quot;&gt;Jekyll docs&lt;/a&gt; for more info on how to get the most out of Jekyll. File all bugs/feature requests at &lt;a href=&quot;https://github.com/jekyll/jekyll&quot;&gt;Jekyll’s GitHub repo&lt;/a&gt;. If you have questions, you can ask them on &lt;a href=&quot;https://talk.jekyllrb.com/&quot;&gt;Jekyll Talk&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;emacs-integration&quot;&gt;emacs integration&lt;/h1&gt;

&lt;h2 id=&quot;for-org-mode-user&quot;&gt;for org-mode user:&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1. write a org file in emacs org-mode
2. export to markdown
3. jekyll build
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;for-markdown-mode-user&quot;&gt;for markdown-mode user:&lt;/h2&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1. write a md file in emacs markdown-mode
2. jekyll build
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Tue, 28 Feb 2017 03:24:55 +0000</pubDate>
        <link>https://seven.github.io/admin/2017/02/27/welcome-to-jekyll.html</link>
        <guid isPermaLink="true">https://seven.github.io/admin/2017/02/27/welcome-to-jekyll.html</guid>
        
        
        <category>admin</category>
        
      </item>
    
  </channel>
</rss>
