/images/art2.png

DFS & BFS

DFS & BFS are two basic algorithms to traverse a graph(or a tree). DFS is Deep-first search and BFS is Breath-first search.

Basic idea

The idea behind two algorithms are identical but use different auxiliary data structure. DFS use stack and BFS use Queue.

First, Every node have a mark to identify is already be visited or not(it could be a list or an attribute in node).

Second, Push the start point into the auxiliary data structure and loop until structure is empty.

Miller Rabin Algorithm

What is millerRabin algorithm

The Miller–Rabin primality test or Rabin–Miller primality test is a primality test: an algorithm which determines whether a given number is prime, similar to the Fermat primality test and the Solovay–Strassen primality test. It was first discovered by Russian mathematician M. M. Artjuhov in 1967.[1] Gary L. Miller rediscovered it in 1976; Miller’s version of the test is deterministic, but its correctness relies on the unproven extended Riemann hypothesis.[2] Michael O. Rabin modified it to obtain an unconditional probabilistic algorithm in 1980.[3]

Makefile overview

What is makefile. How to write a makefile.

Ref: https://opensource.com/article/18/8/what-how-makefile

What is makefile

A makefile is a file containing a set of directives used by a make build automation tool to generate a target/goal.

You may have used make to compile a program from source code.

How to write makefile

To summarize, below is the syntax of a typical rule:

target: prerequisites
<TAB> recipe

As an example, a target might be a binary file that depends on prerequisites (source files). On the other hand, a prerequisite can also be a target that depends on other dependencies:

Safari Shortcut

Some keyboards shortcuts when using safari

Use arrow keys to go up and down.

Use Option+up/down or Shift+Space / Space to scroll quickly.

Use Command+up/down goto the top & button.

Open Pages in Tabs

Use Command+T to open a new Tab.

Use Shift+Command+Left/right arrow or Control+Tab / Control+Shift+Tab to move from tab to tab.

Use Command+W to close current tab.

Use Command+Z to reopen a closed tab.

Use Command+Option+W to close all tabs expect current tab.

My Zsh setting

Zsh & Bash

Since MacOs 10.15(Catalina). The default shell switch from bash to zsh. It is hard to say which one is better however Zsh has been used more widely than bash especially from Linux user.

Zsh

The Z shell (also known as zsh) is a Unix shell that is built on top of bash (the default shell for macOS (Before MacOs Catalina)) with additional features. It’s recommended to use zsh over bash. It’s also highly recommended to install a framework with zsh as it makes dealing with configuration, plugins and themes a lot nicer.

Erlang overview

Basic

Documentation: https://erlang.org/doc/search/

Functional language

Erlang is a functional language. Code need compile and running line by line.

Every line need finish by a .. like: A = 1..

Module

Every erlang file will consider as a module. You console will compile all module you want.

You have to add -module(<filename>). into first line. Module should be same with filename without suffix.

In erl console, run c(<filename>). to compile it. Run a function is like: <moduleName>: <functionName>(...<argument>)

Z-shell overview

Reference

Very useful blog:

http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/#username-and-hostname

http://zsh.sourceforge.net/Intro/intro_12.html#SEC12

Variable

nameusage
%mHostname
%nUsername
%dDirectory from /
%~Directory from ~
%ttime (12)
%Ttime (24)

%d and %~ can add a number to specify how many previous path will show. Like %1~

Guide to zsh

Here is the link to A User’s Guide to the Z-Shell

single quotes & double quotes

RPROMPT="$(command)"  # this will run command, then set RPROMPT to the result
RPROMPT='$(command)'  # this will set RPROMPT to run command each time it is printed

Date

man Date

What is "this" in javascript

Author: Dmitri Pavlutin

Reference: https://dmitripavlutin.com/gentle-explanation-of-this-in-javascript/

Concept

  • Invocation of a function is executing the code that makes the body of a function, or simply calling the function. For example parseInt function invocation is parseInt('15').
  • Context of an invocation is the value of this within function body. For example the invocation of map.set('key', 'value') has the context map.
  • Scope of a function is the set of variables, objects, functions accessible within a function body.

Invocations

  • function invocation: alert(‘Hello World!’)
  • method invocation: console.log(‘Hello World!’)
  • constructor invocation: new RegExp(’\d')
  • indirect invocation: alert.call(undefined, ‘Hello World!’)

this in different invocations

this is base on the context of calling this function

How to have a dynamic class name

In same case, you may want to have a different style depend on your state or a variable. Now we can have two ways to achieve that.

classNames

This is a javascript for conditionally joining classNames.

Here is: Github

Basically, you can combine any number of classNames.

const classNames = require('classNames');
classNames('foo', { bar: true, duck: false }, 'baz', { quux: true }); // => 'foo bar baz quux'

ES6 template literals

You can just use template literals.