> 2021年07月27日信息消化 ### Zero downtime API in Golang origin: [Zero downtime API in Golang](https://wutch.medium.com/zero-downtime-api-in-golang-d5b6a52cc0ed) > Recently I have encountered a task, where I needed to develop an API, that has maximum uptime **during upgrading binaries**. I found two usable solutions, that I would like to share with you. I will try to sum up everything so it can serve as some basepoint for everyone interested in this topic. Writing a blog post about this problem also helps me so I can come back later and quickly read what I have discovered to prevent researching everything from scratch. [github/wutchzone/zero-downtime-application](https://github.com/wutchzone/zero-downtime-application) 1. We can take an advantage of socket options namely [**SO_REUSEPORT**](https://lwn.net/Articles/542629/). In Golang we can set options to our listener (as can be seen in the following code example), with these options we can start multiple web servers that use the same port. 2. When we start a new process in Golang, you can specify file descriptors that can be inherited. We can share our opened socket with our child so our child can start where we left off. ```go lc := net.ListenConfig{ Control: control, } ... func control(network, address string, c syscall.RawConn) error { var err error c.Control(func(fd uintptr) { err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1) if err != nil { return } err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1) if err != nil { return } }) return err } ``` We apply both **SO_REUSEADDR** and **SO_REUSEPORT**, the difference between these two is nicely described in [this](https://stackoverflow.com/a/14388707/7594900) Stackoverflow answer. Normally you cannot listen on a port that is already used by another application. But when we specify these socket options we can. When we have multiple applications listening on the same port, our kernel will then “randomly” load balance incoming requests between these applications. Everything can be seen in the code [here](https://github.com/wutchzone/zero-downtime-application/blob/master/socket-option-version/main.go). The second variant is rather more complex but can be used in multiple scenarios, not only with sockets. It can be used with any kind of file descriptors like pipes, files, etc. In Golang we have many options on how to spawn another process (Do not mix terms like process and thread, the process can be simply explained as another running application. Furthermore processes do not share RAM like threads.). In particular, let’s take a look at **StartProcess** func in the [os package](https://pkg.go.dev/os#StartProcess). This func has an option of [ProcAttr](https://pkg.go.dev/os#ProcAttr) where we can provide opened file descriptors for our child process. This means that our child process will not create a new listener, it will just take it from it’s parent. Everything can be seen in the code [here](https://github.com/wutchzone/zero-downtime-application/blob/master/inherit-version/main.go). 我们同时应用**SO_REUSEADDR**和**SO_REUSEPORT**,这两者的区别在[this](https://stackoverflow.com/a/14388707/7594900)Stackoverflow答案中得到很好的描述。通常情况下,你不能监听一个已经被其他应用程序使用的端口。但当我们指定这些套接字选项时,我们可以。当我们有多个应用程序在同一个端口上监听时,我们的内核将在这些应用程序之间 "随机 "地平衡进入的请求。一切都可以在代码中看到[这里](https://github.com/wutchzone/zero-downtime-application/blob/master/socket-option-version/main.go)。 第二种变体相当复杂,但可以用于多种情况,不仅仅是用于套接字。它可以用于任何类型的文件描述符,如管道、文件等。在Golang中,我们有很多关于如何生成另一个进程的选项(不要把进程和线程这样的术语混在一起,进程可以简单地解释为另一个正在运行的应用程序。此外,进程不像线程那样共享内存)。) 特别是,让我们看看[os包](https://pkg.go.dev/os#StartProcess)中的**StartProcess**函数。这个函数有一个[ProcAttr](https://pkg.go.dev/os#ProcAttr)的选项,我们可以为我们的子进程提供打开的文件描述符。这意味着我们的子进程不会创建一个新的监听器,它只是从它的父进程中获取它。一切都可以在代码中看到[这里](https://github.com/wutchzone/zero-downtime-application/blob/master/inherit-version/main.go)。 ### Understanding Recursion in Programming origin: [Understanding Recursion in Programming](https://www.freecodecamp.org/news/understanding-recursion-in-programming/) Here are all the topics covered in this course: - What is Recursion? - recursion is nothing more than a method that calls itself and to be more precise, it's usually a method that maybe returns a value, maybe it doesn't. - Why & Why Not Recursion - Pros - Bridges the gap between elegance and complexity - Reduces the need for complex loops and auxiliary data structures. - Can reduce time complexity easily with memorization - Works readlly well with recursive structures like trees and graphs - Cons - Slowness due to CPU overhead - Can lead to out of memory erros/stack overflow exceptions - Can be unnecessarily complex if poorly constructed - Call Stack Analogy - Recursion With Strings Introduction - String Reversal Explanation - String Reversal Call Stack Animation - Palindrome Explanation - palindromes are these unique words, where we can basically spell the same word forward and backward. - [Check whether the given string is Palindrome using Stack](https://www.geeksforgeeks.org/check-whether-the-given-string-is-palindrome-using-stack/) - Find the length of the string say **len**. Now, find the mid as **mid = len / 2**. - Push all the elements till mid into the stack i.e. **str[0…mid-1]**. - If the length of the string is odd then neglect the middle character. - Till the end of the string, keep popping elements from the stack and compare them with the current character i.e. **string[i]**. - If there is a mismatch then the string is not a palindrome. If all the elements match then the string is a palindrome. - ```python # Python3 implementation of the approach stack = [] top = -1 # push function def push(ele: str): global top top += 1 stack[top] = ele # pop function def pop(): global top ele = stack[top] top -= 1 return ele # Function that returns 1 # if str is a palindrome def isPalindrome(string: str) -> bool: global stack length = len(string) # Allocating the memory for the stack stack = ['0'] * (length + 1) # Finding the mid mid = length // 2 i = 0 while i < mid: push(string[i]) i += 1 # Checking if the length of the string # is odd, if odd then neglect the # middle character if length % 2 != 0: i += 1 # While not the end of the string while i < length: ele = pop() # If the characters differ then the # given string is not a palindrome if ele != string[i]: return False i += 1 return True # Driver Code if __name__ == "__main__": string = "madam" if isPalindrome(string): print("Yes") else: print("No") ``` - Recursion With Numbers - Binary Search - ```python def binarySearch(array, x, low, high): # Repeat until the pointers low and high meet each other while low <= high: mid = low + (high - low)//2 if array[mid] == x: return mid elif array[mid] < x: low = mid + 1 else: high = mid - 1 return -1 ``` - Fibonacci Explanation - F0=0, F1=1 - Fn = Fn-1 + Fn-2 (n>1) - 0,1,1,2,3,5,8,13,21,34,55,89,144 - ![img](https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/FibonacciSpiral.svg/220px-FibonacciSpiral.svg.png) - [Merge Sort](https://www.geeksforgeeks.org/merge-sort/) - ``` MergeSort(arr[], l, r) If r > l 1. Find the middle point to divide the array into two halves: middle m = l+ (r-l)/2 2. Call mergeSort for first half: Call mergeSort(arr, l, m) 3. Call mergeSort for second half: Call mergeSort(arr, m+1, r) 4. Merge the two halves sorted in step 2 and 3: Call merge(arr, l, m, r) ``` - [Linked List](https://www.geeksforgeeks.org/linked-list-set-1-introduction/) - ```python # Node class class Node: # Function to initialize the node object def __init__(self, data): self.data = data # Assign data self.next = None # Initialize # next as null # Linked List class class LinkedList: # Function to initialize the Linked # List object def __init__(self): self.head = None ``` - Graphs - [Depth-First Search](https://www.geeksforgeeks.org/depth-first-search-or-dfs-for-a-graph/) - Depth First Traversal (or Search) for a graph is similar to Depth First Traversal of a tree. The only catch here is, unlike trees, graphs may contain cycles, a node may be visited twice. To avoid processing a node more than once, use a boolean visited array. - ```python # Python3 program to print DFS traversal # from a given given graph from collections import defaultdict # This class represents a directed graph using # adjacency list representation class Graph: # Constructor def __init__(self): # default dictionary to store graph self.graph = defaultdict(list) # function to add an edge to graph def addEdge(self, u, v): self.graph[u].append(v) # A function used by DFS def DFSUtil(self, v, visited): # Mark the current node as visited # and print it visited.add(v) print(v, end=' ') # Recur for all the vertices # adjacent to this vertex for neighbour in self.graph[v]: if neighbour not in visited: self.DFSUtil(neighbour, visited) # The function to do DFS traversal. It uses # recursive DFSUtil() def DFS(self, v): # Create a set to store visited vertices visited = set() # Call the recursive helper function # to print DFS traversal self.DFSUtil(v, visited) # Driver code # Create a graph given # in the above diagram g = Graph() g.addEdge(0, 1) g.addEdge(0, 2) g.addEdge(1, 2) g.addEdge(2, 0) g.addEdge(2, 3) g.addEdge(3, 3) print("Following is DFS from (starting from vertex 2)") g.DFS(2) ``` - [Tail-Call Recursion](https://www.geeksforgeeks.org/tail-call-elimination/) - Tail Recursion: A recursive function is tail recursive when a recursive call is the last thing executed by the function. For example the following C++ function print() is tail recursive. - We also discussed that a tail-recursive is better than a non-tail recursive as tail-recursion can be optimized by modern compilers. Modern compiler basically does tail call elimination to optimize the tail-recursive code. If we take a closer look at the above function, we can remove the last call with goto. Below are examples of tail call elimination. - It is possible for the function to execute in constant memory space because, in tail recursive function, there are no statements after call statement so preserving state and frame of parent function is not required. Child function is called and finishes immediately, it doesn’t have to return control back to the parent function. As no computation is performed on the returned value and no statements are left for execution, the current frame can be modified as per the requirements of the current function call. So there is no need to preserve stack frames of previous function calls and function executes in constant memory space. This makes tail recursion faster and memory-friendly. ### Anxiety Is in Your Body, Not Your Mind > Why you might want to stop talking about your anxiety and try this instead origin: [Anxiety Is in Your Body, Not Your Mind](https://elemental.medium.com/anxiety-is-in-your-body-not-your-mind-93031abd14eb) ##### Your survival brain vs. your thinking brain In her work, Stanley makes the distinction between the *thinking* brain, our neocortex, responsible for decision-making, reasoning, ethics, conscious memory, learning, and the *survival* brain — the limbic system, brain stem, and cerebellum — which handles our basic survival, emotions, implicit memory, and stress arousal. One of the survival brain’s most important functions, according to Stanley, is *neuroception*, an unconscious process of rapidly scanning the internal and external environment for safety and danger. When danger is spotted, your survival brain sends an instantaneous stress arousal message to your body by turning on the sympathetic nervous system, resulting in the release of specific hormones that lead to certain physical sensations related to our heart, breathing, and digestion. “Whatever’s happening in the survival brain has these tremendous ripple effects through our body,” Stanley says. As Stephen Porges, PhD, a psychologist and the creator of the Polyvagal Theory, explains in [an interview](https://www.youtube.com/watch?v=ec3AUMDjtKQ) with *PsychAlive*, “These responses are not voluntary. **Our nervous system is picking up information in the environment, not on a cognitive level, but on a neurobiological level.**” ##### A bottom-up solution for anxiety While talk therapy and medication are still the mainstream solutions offered for chronic anxiety, other modalities exist that offer a body-first approach. And while these modalities are still considered “alternative,” [an increased interest](https://www.psychologytoday.com/us/blog/talking-apes/201702/is-neuroscience-the-future-or-the-end-psychology) in “brain science” and neurobiology along with continued [research](https://www.researchgate.net/profile/Jeffery-Dusek/publication/10798548_The_Evaluation_of_a_MindBody_Intervention_to_Reduce_Psychological_Distress_and_Perceived_Stress_in_College_Students/links/56fa972008aef6d10d9049d9/The-Evaluation-of-a-Mind-Body-Intervention-to-Reduce-Psychological-Distress-and-Perceived-Stress-in-College-Students.pdf) on [mindfulness](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3772979/) and [mind-body](https://www.gastrojournal.org/article/S0016-5085(12)01493-X/fulltext?referrer=https%3A%2F%2Fpubmed.ncbi.nlm.nih.gov%2F) [connections](https://pubmed.ncbi.nlm.nih.gov/19344891/) are shifting our psychological understanding from focusing only on the mind to seeing the brain and body as a cohesive unit. When your body is having a stress response, the first thing is to become aware of objects that help the survival brain feel safe, like what you can see and hear. “One of the best ways to help the survival brain feel grounded is to bring attention to where our body is in contact with our environment,” Stanley says. She suggests focusing on the contact between your feet with the floor, or your body in your chair. As soon as the survival brain perceives groundedness and safety, it automatically starts the recovery process. Obviously, when you’re caught in a moment of severe anxiety, trying to breathe deeply or be mindful can feel almost impossible. In those situations, what you need is to get the adrenaline and cortisol out of your system. Stanley suggests jumping rope or running up and down stairs. After 10 minutes, try a mindfulness exercise again. Is there any role for talk therapy, or trying to think logically about your anxiety? Absolutely. But only once your body is regulated, Stanley says: “After we have helped our survival brain feel safe and stable, then we can work on our thoughts. Otherwise, our cognitive response continues to be biased by our stress and emotions.” ### 4 Things Really Successful People Say ‘No’ To origin: [4 Things Really Successful People Say ‘No’ To](https://alan-12169.medium.com/4-things-really-successful-people-say-no-to-2e66a83406f) > All failures are unique, but all successes look similar In the office, he simply… reads. Financial statements, news, journals, business reports, books — everything that might lead him to better investment decisions. He estimates that about 80% of his work time is spent reading. “**I just sit in my office and read all day**,” he once said. He has also famously said that > *Successful people say ‘no’ to almost everything.* What is he referring to? Some things — like sleeping in or spending all your money on luxury purchases — are obvious. Here are four less-obvious things really successful people give up in order to reach and maintain their success. ##### They say ‘no’ to feeling sorry for themselves. uccessful people view each failure as a stepping stone towards finding the thing that actually works. Thomas Edison, the inventor of the light bulb, has famously said that > *I have not failed. I’ve just found 10,000 ways that won’t work, — Thomas Edison* Despite getting a $180 million pay check after selling his PayPal shares, Elon Musk [went broke](https://www.ccn.com/elon-musk-broke-save-tesla-in-2008-now-worth-21-billion/#:~:text=From Broke to Billionaire&text=Despite the %24180 million payday,up in Tesla and SpaceX.) to save Tesla. Here’s how the legendary founder sees failure: > “If things are not **failing**, you are not innovating enough.” ##### They say ‘no’ to useless networking. I personally know people who take great pride in the people they hang out with. They’ll boast big names on their contacts list and present the achievements of their ‘network’ as partly their own. These are usually the people who prioritize handing out business cards over making actual human connections. Successful people prioritize the quality of their relationships over the quantity. For example, Bob Iger, Disney’s legendary CEO, [often recalls](https://www.youtube.com/watch?v=OS4y0giPVaE&list=PLSoBJ5yHS0liajhZSNNl90_rme8qa2JCv&index=2) how Steve Jobs would show him Apple products pre-launch or called him up on Saturday mornings just to chat. Eventually, that relationship was the only thing that enabled the purchase of Pixar, a business move that gave Disney a re-start it needed. > “The currency of real networking is not greed but generosity.” — Keith Ferrazzi, author and entrepreneur ##### They say ‘no’ to most opportunities — business or otherwise. As soon as you start seeing some success in your life, opportunities start coming at you left and right. Your friends are offering you business partnerships. Old friends start inviting you to come over for the weekend or participate in a charity event. Before you know it, you spread yourself so thin you don’t even know who you are anymore. Successful people are masters at saying ‘no.’ According to Warren Buffet, who makes ridiculously few investments, > In your lifetime you should swing at only a couple dozen pitches, and you should do careful homework so that the few swings you do take are hits. ##### They say ‘no’ to people who drain their energy. All people have 24 hours in a day, and all people have roughly the same amounts of energy. There’s a reason why people like Elon Musk are able to maintain 100-hour work weeks for years on: they limit their social circle to people who energize them. One of my favorite entrepreneurs is Alex Lieberman, the founder of the Morning Brew newsletter. He’s been working 6 days a week, publishing a daily newsletter and speaking in local campuses since he was around 22. He’s also been suffering from anxiety and OCD for as long as he can remember. Yet, he built a $13 million newsletter in just 4 years. Here’s [how he sees his social circle](https://www.youtube.com/watch?v=r-RDhYWMgAs&t=2755s): > “I feel most satisfied when I get to meet really smart people. I spend a lot of time getting coffee with really smart people. To me, that is when I feel most satisfied in general.” ##### Success is mostly about eliminating things that keep you stuck Becoming successful is a lot like writing a good article. It’s usually not about how many things you can add, but how many things you can take away. Successful people are masters at prioritizing and ruthlessly eliminating activities and people that do not coincide with their goals. In some ways, lives of successful entrepreneurs are the most boring — because they spend 90% of their time on the few activities that generate the 90% of the value in their lives. Most of us subconsciously know which activities we should give up to become more successful. The difference between those who win and those who fail is that the former actually go ahead and do it. As my favorite quote from *Avatar* goes, > You cannot fill a cup that is already full. ### 13 Fascinating Numbers Around Us — When Beauty Meets Math origin: [13 Fascinating Numbers Around Us — When Beauty Meets Math](https://www.cantorsparadise.com/13-fascinating-numbers-around-us-when-beauty-meets-math-3fa7d3a22126) ##### 13. Aleph Null ℵ0 > wikipedia > > In mathematics, and in particular set theory, the aleph numbers are a sequence of numbers used to represent the cardinality of infinite sets that can be well-ordered. They are named after the symbol used to denote them, the Hebrew letter aleph. > > 在数学中,特别是集合理论中,阿勒夫数是一连串的数字,用来表示可以有秩序的无限集合的cardinality。它们是以用来表示它们的符号--希伯来字母阿勒夫命名的。 Aleph Null is a beautiful concept. It is the smallest infinite number. I know what you’re thinking, infinity should be just one concept, not many infinite numbers. After all, *if there is an infinity larger than the other infinity, the first one is definitely not an infinity*. Let’s suppose that we have a basic idea on what infinity is (discussed below, 12 in the list). **Aleph null is how many natural numbers there are** (0, 1, 2, 3, etc.). This concept or number is huge in size and well, infinite. 假设我们对什么是无限有一个基本的概念(下面讨论,列表中的12)。**Aleph null是指有多少个自然数**(0,1,2,3,等等)。这个概念或数字的大小是巨大的,嗯,是无限的。 What if we count all of the natural numbers two or three times? After finishing the first set, we’ll have numbers that extend beyond the natural numbers in **order**. So, we will need the order of numbers, otherwise known as ordinality. The next number after Aleph Null is omega (ω), then comes ω + 1. These two last numbers are not **cardinal** numbers but **ordinal**, i.e. *they represent their position compared to a horizontal axis*. The below graph is a simplistic representation. Each set can represent the set of natural numbers in existence, and each set has the cardinality ℵ0. Adding one after the first set does not change the cardinality (You can just change the order and you’ll still be left with Aleph Null cardinality). 如果我们把所有的自然数都数两遍或三遍呢?在完成第一组后,我们会有超出自然数的数字,按顺序扩展。所以,我们将需要数字的顺序,也就是所谓的序数。Aleph Null之后的下一个数字是omega(ω),然后是ω+1。这两个最后的数字不是心数,而是序数,也就是说,它们代表了与横轴相比的位置。下图是一个简单的表示。每个集合都可以代表存在的自然数的集合,每个集合的心数都是ℵ0。在第一个集合之后增加一个,并不改变cardinality(你可以只是改变顺序,你仍然会留下Aleph Null的cardinality)。 ![img](https://raw.githubusercontent.com/Phalacrocorax/memo-image-host/master/uPic/0*zrrlf7GWpw_L7TCq.png) - **Infinity and Aleph Null are two different things. The former is simply an extreme limit idea lying on the number axis while the latter is simply the size of the set (cardinality).**无限和Aleph Null是两件不同的事情。前者只是一个位于数轴上的极端极限概念,而后者只是集合的大小(cardinality)。 - **Cardinality is the size of a set and cardinal numbers represent quantity (1, 2, 459, 1002, etc.) while Ordinality is the order of a set and ordinal numbers represent order (1st, 2nd, 66th, etc.).** cardinals是一个集合的大小,心数代表数量(1,2,459,1002,等等),而ordinals是一个集合的顺序,序数代表次序(1,2,66,等等)。 - **Just as there are infinite cardinals, there are infinite ordinals as well and the first infinite (uncountable) ordinal number is the one we have discussed above, omega ω.** 正如有无限的cardinals,也有无限的ordinals,第一个无限的(不可数的)序数就是我们上面讨论的欧米伽ω。 - **Following this logic, Aleph one is the cardinality of omega ω. **按照这个逻辑,Aleph one是omega ω的cardinals。 ##### 12. Infinity ∞ Conclusive table for operations on infinity: **∞ + ∞ = ∞ -∞ + -∞ = -∞ ∞ × ∞ = ∞ -∞ × -∞ = ∞ -∞ × ∞ = -∞** ##### 11. i The letter i refers to an imaginary number. The definition of an imaginary number is that when we square it, it gives us a negative result. ##### 10. Googol A googol equals 10 followed by 100 zeros, therefore, to put things into perspective, think the following number: **10,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000** It is approximately 70! (Factorial). which is 70 x 69 x 68 x 67 x 66 x 65 x 64 x 63 x 62 x 61 x 60 x 59 …. x 1 It is interesting to note that the company Google is a misspelling of the Googol name. It is indeed a smart way to name your search engine. The number is mostly used with astronomical studies such as the big freeze of the universe. ##### 9. The number 9 (Coincidentally ranked 9) - The circle. It has 360 degrees (3 + 6 + 0 = **9**) - The circle cut in half. Each half is 180 degrees (1 + 8 + 0 = **9**) - The circle cut in quarters. Each quarter is 90 degrees (9 + 0 = **9**) - The circle cut in 8 pieces. Each part is 45 degrees (4 + 5 + 0 = **9**) - The circle cut in 16 pieces. Each part is 22.5 degrees (2 + 2 + 5 = **9**) - The circle cut in 32 pieces. Each part is 11.25 degrees (1 + 1 + 2 +5 = **9**) - A regular polygon inside a circle. Each angle is 60 x 3 (180 = 1 + 8 = **9**) - A square. Each angle is 90 x 4 (360 = 3 + 6 + 0 = **9**) ##### 8. The number 73 If you’re a fan of The big bang Theory, then you must’ve heard Dr. Sheldon Cooper stating why **73** is the perfect number, here’s the quote: “***The best number is 73. Why? 73 is the 21st prime number. Its mirror, 37, is the 12th and its mirror, 21, is the product of multiplying 7 and 3\****.*”’” “***In binary 73 is a palindrome, 1001001, which backwards is 1001001\****.*”’ 如果你是《生活大爆炸》的粉丝,那么你一定听过谢尔顿-库珀博士说过为什么***73是完美的数字,以下是这句话。 "***最好的数字是73。73是第21个质数。它的镜像,37,是第12个,它的镜像,21,是7和3的乘积/****。*'" "***在二进制中,73是一个回文数,1001001,倒过来就是1001001\****.*" ##### 7. Euler’s number Named after Leonhard Euler, **e** is an irrational number and the base of the natural logarithms. Interestingly, euler’s number is known to around 1 trillion digits of accuracy [source: mathisfun.com]. It is found following this formula: As n approaches infinity, we get a clearer vision of the value of **e**. When n = 100,000, **e** = 2.71827. An interesting property that **e** has, is that its **slope is its value**. It is also used in finance to calculate compound interest. I believe those of you who have already taken the CFA test are familiar with this information. ##### 6. The Fibonacci sequence Fn = Fn-1 + Fn-2 This gives us the following sequence that goes to infinity: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …. The beauty of this sequence is that it is related to nature. For example, it appears the flowering of the artichoke, some flower petals such as Daisies, honeybees, etc.. Does it even occur in the galaxy spirals? There is even a very interesting observation based on facts that suggests that the dimensions of the Earth and Moon are in Phi relationship, forming a Triangle based on 1.618, by Gary Meisner. **But what is Phi, and what is this 1.618?** If we take any two successive numbers in the sequence, their ratio (Xn / Xn-1) gets closer to 1.618 which is what we call the golden ratio: 3 / 2 = **1**.5 13 / 8 = **1.6**66 55 / 34 = **1.61**764 233 / 144 = **1.6180**5 ##### 5. The number 23 Many among us have seen the movie: the number **23** which features Jim Carrey portraying the persona of Walter Sparrow as someone who becomes obssessed with the number **23** after reading about it in a book. The belief here is that this number mysteriously coincides with many events all around the world and **while that can be a perfect example of Apophenia,** it is still interesting to list some events that have **23** embedded in them: - Humans have **23** pairs of chromosomes. - **23** is the lowest prime that consists of consecutive digits. 23是由连续数字组成的最低素数 - On average, the human blood circulates through the whole body every **23** seconds. 平均而言,人类的血液每23秒在全身循环一次。 ##### 4. Pi (π) & Tau (τ) - We all know the 22/7 approximation for Pie. *But no ratio can give out the exact value of pie because it’s an irrational number*. Why did I include Tau? Some mathematicians have been debating the usefulness of **π** and propose Tau instead which is simply **τ = 2π**. Many mathematicians argue that Tau is more suited for calculating circles. Their intuition is correct when we want to dig into the details, but who doesn’t love **Pi(e)**? ##### 3. Euler’s identity This is why I have included the word “beauty” in the title. Combining some of the most beautiful concepts in maths can give us such simple results. Let’s recap first what concepts are we talking about and how are we going to combine them: - Euler’s number **e** - The unit imaginary number **i** - Pi **π** ##### It’s fascinating to see these three together form an equation such as the below to give us the simple result of -1. $$ e^{i\pi}=-1 $$ How did we get -1 from the three musketeers? As we have already seen together, i raised to the power of 2 = -1. Leonhard Euler applied the Taylor series with i giving him the following equation (omitting the details as they are beyond the scope of this article): $$ e^{ix}=cosx+isinx $$ Putting the above Euler’s formula on a complex plane (with real numbers and imaginary ones) gives us a circle. By including a radius of r, we can turn the points into another form such as **re** raised to the power of **ix**. If we assume x = **π**, then we will have the following: $$ e^{i\pi}=cos\pi+isin\pi $$ Knowing that cos **π** = -1 and sin **π** = 0, then the i on the right will disappear: $$ e^{i\pi}=-1+(ix0) $$ $$ e^{i\pi} =-1 $$ So, we can also rearrange this equation to make it more beautiful and add another simple number: $$ e^{i\pi}+1=0 $$ ##### 2. The number 6174 Also known as Kaprekar’s constant, this number has a special feature if you follow the below steps (Taken from various sources, but let’s just say Wikipedia): 这个数字也被称为卡普雷卡常数,如果你按照下面的步骤,这个数字有一个特殊的功能。 - Take any four-digit number (at least two digits should be different). 取任何四位数的数字(至少有两个数字是不同的)。 - **Arrange the digits in descending and ascending order** to get two new four-digit numbers. 将这些数字按降序和升序排列,得到两个新的四位数。 - Now, subtract the smaller number from the bigger number. 现在,用大的数字减去小的数字。 - Redo step 2. 重做第2步。 Let’s take an example of 2714: - 7421 -1247 = **6174** Another example of 3687: - 8763 -3678 = 5085; - 8550 -0558 = 7992; - 9972 -2799 = 7173; - 7731 -1377 = 6354; - 6543 -3456 = 3087; - 8730 -0378 = 8352; - 8532 -2358 = **6174** Now, if we have **6174**, we will always stay at **6174** because 7641 -1467 = **6174**. It is also a Harshad number, meaning it is divisible by the sum of its constituents: **6174** / (6 + 1 + 7 + 4) = 6174 / 18 = 343. So, that adds to its coolness. ##### 1. The golden ratio We have already discussed this ratio, but it is probably the most important ratio in the world (It was named by the Greeks). Here’s a list of its characteristics: - The reciprocal of **0.618** is simply 1 + **0.618**. Hence, 1 / ϕ ≈ 1 + ϕ - It appears in **Nature** (as previously mentioned). Some tree branches are an example. The main trunk will grow until it produces a branch thus creating two new starting points. One of the starting points will grow two others while the other will not. The pattern is similar to the Fibonacci pattern. - It is believed to represent **Beauty** and even though this belief is not proven, it remains interesting to know how our minds define beauty. For example, the face. Now, the following is probably not the most accurate research made but Dr. Schmid has a 10 scale ratio with 10 as the highest (most beautiful person) with most people scoring between 4 and 6. The beauty metric is first measured by the length and the width of the face then divides by the width. The optimal result is 1.618. Meaning a beautiful person’s face is 1.618 longer than it’s width. Later on, other ratios are calculated such as the bottom of the nose to the bottom of the chin. Finally, symmetry tests are performed to check out more beauty metrics. Dr. Schmid says that the length of the ear should be equal to the length of the nose on a perfect face, among other characteristics. 人们认为它代表着美,尽管这种信念没有得到证实,但知道我们的头脑如何定义美仍然很有趣。例如,脸部。现在,以下可能不是所做的最准确的研究,但施密德博士有一个10级比例,10为最高(最美的人),大多数人的得分在4到6之间。美丽的尺度首先是由脸部的长度和宽度来衡量,然后除以宽度。最佳结果是1.618。这意味着一个美丽的人的脸比它的宽度长1.618。后来,其他比例也被计算出来,如鼻子的底部到下巴的底部。最后,进行对称性测试,以检查出更多的美丽指标。施密特博士说,在一张完美的脸上,耳朵的长度应该与鼻子的长度相等,还有其他特征。 - It is believed that the ratio of our arm to our forehand is equal to **ϕ**. - It is present in **Geometry.** Many buildings and artworks have the Golden Ratio in them, An example would be the **Parthenon** in Greece. - The pantagram has the golden ratio embedded inside of it. #### 7 Awesome CSS Tools for All Web Developers origin: [7 Awesome CSS Tools for All Web Developers](https://javascript.plainenglish.io/7-awesome-css-tools-for-all-web-developers-390ceced6f83) - [Get Waves](https://getwaves.io/) - [PurgeCSS](https://purgecss.com/) | remove unused code in your CSS - [CSS Scan](https://getcssscan.com/) | allows you to get the entire CSS code of any element you hover over on a web page. - [CSS Grid Generator](https://cssgrid-generator.netlify.app/) - [CSS clip-path maker](https://bennettfeely.com/clippy/) - [Animista](https://animista.net/) | a collection of pre-made CSS animations - [Smooth shadow](https://shadows.brumm.af/) ### 一点收获 - 7 Toxic Habits That Will Hold You Back - A love of the safe road. - > “Man cannot discover new oceans unless he has the courage to **lose sight** of the **shore**.” — Andre Gide - Worrying about your reputation. - Being shrunk by your limitations. - Pizza, Beer and Netflix. - Your preoccupation with sex. - Running someone else’s race. - Trying too hard to be original. - [3 Foods That Are Incredible for Your Brain, Backed by Science](https://medium.com/alyssas-healthy-tidbits/3-foods-that-are-incredible-for-your-brain-backed-by-science-ee1f33af6e95) - Tomato - Walnuts - Turmeric - About Socket - 套接字是:IP+端口+自我的特定标识 | [Comment](https://blog.csdn.net/qq_36098284/article/details/81841975) - In fact, your brain predictions’ anticipate sensory inputs such as vision or taste even before they happen. Then real sensory inputs either affirm the mind’s predictions as correct or wrong — if wrong, then the brain learns updates new predictions. -- [The Coolest Discovery In Neuroscience This Decade](https://medium.com/artificial-intelligence-and-cognition/what-makes-emotions-feel-good-or-bad-9bdcd0a81afc)