JavaScript's this Principle

1. Origin of the problem One sign of understanding the JavaScript language is to understand the following two ways of writing, which may have different results. 1 2 3 4 5 6 7 8 9 10 11 12 var obj = { foo: function () {} }; var foo = obj.foo; // Writing Method I obj.foo() // Writing Method 2 foo() In the above code, although obj.foo and foo point to the same function, the execution result may be different.

Interaction Between Pages - window.postMessage and BroadcastChannel Api

In multi-page web applications, you will encounter scenarios of inter-page interaction, such as: passing data from navigation pages to iFrame pages, notifying events between tab pages, and so on. This article introduces two common interfaces for inter-page interaction - window.postMessage and BroadcastChannel API - and compares the differences between them. Messaging Direction window.postMessage An example of a window.postMessage call is as follows. 1 2 3 // A Page const B = window.

Why I Migrated From Redux to Mobx

Redux is a data management layer that is widely used to manage data for complex applications. But in practice, Redux is poorly used, and arguably not well used. And at the same time, a number of data management solutions have emerged in the community, Mobx being one of them. Problems with Redux Predictable state container for JavaScript apps This is the position Redux has given itself, but there are many problems with it.

Common Ways to Implement Animations in React

Nowadays, users’ requirements for front-end pages are no longer satisfied with achieving functionality, but also with value and fun. In addition to the overall UI aesthetics, adding the right animation effect in the right place is often more expressive and natural than static pages. For example, a simple loading animation or page switching effect can not only relieve the user’s waiting emotion, but even silently achieve the effect of brand

Simple Usage of Colly

colly is a powerful crawler framework written in Go language . It provides a simple API, has strong performance, can automatically handle cookies & sessions, and provides a flexible extension mechanism. First, we introduce the basic concept of colly. Then we introduce the usage and features of colly with a few examples: pulling GitHub Treading, pulling Baidu novel hotlist, downloading images from Unsplash . Quick Use Create the directory and

Manual for structopt library

The standard library provides std::env::args() to get command line arguments, the first value is the name of the program, similar to the way arguments are obtained in other languages: 1 2 3 4 5 let args: Vec<String> = env::args().collect(); let query = &args[1]; let filename = &args[2]; println!("Searching for {}", query); println!("In file {}", filename); But in the process of product development, we need more program parameters, and need certain rules and checks, this time we need to use some other libraries to parse these parameters, such as the structopt library.

Browser Database IndexedDB Getting Started Tutorial

1. Overview With the increasing functionality of browsers, more and more websites are considering storing large amounts of data on the client side so that they can get less data from the server and get it directly from the local area. The existing browser data storage solutions are not suitable for storing large amounts of data: Cookie size is no more than 4KB and each request is sent back to

Automating Docker Publishing With GitHub Action

Recently, I’ve been using GitHub Actions for my company’s internal project release process, and it’s been a great experience. The main goal of this article is to help newcomers to GitHub Actions to quickly build automated tests and package and push Docker images. Create project This article focuses on Go as an example, but of course other languages are similar and have little to do with the language itself. Here we start by creating a project on GitHub and writing a few simple pieces of code main.

Redis6 Client Side Caching Features and Practices

Redis 6.0 has been released more than a year ago. The new features in Redis 6.0 have been identified through step-by-step discussions and optimizations. Many of these features have already been introduced in previous releases such as RC. However, there are some new changes in the official GA release: SSL ACL: better, command support RESP3 Client side caching: redesigned Threaded I/O Diskless replication on replicas Cluster support in Redis-benchmark and improved redis-cli cluster support Disque in beta as a module of Redis: starting to invade the message queue space Redis Cluster Proxy Support for immediate deletion when the RDB is no longer in use, for scenarios where the disk is not dropped PSYNC2: Optimized replication protocol More friendly timeout setting support Faster RDB loading, 20% ~ 30% improvement STRALGO, new string command, currently only one implementation of LCS (longest common subsequence) @antirez mentioned that it was only the largest version update in Redis history, so it was prudent to recommend more testing and evaluation of the product in the application, and promised to release version 6.

Data Reading in Golang

The standard library of Go provides several methods to read data from io.Reader (io, ioutil), and this article demonstrates the application scenarios by reading data from net. Accessing a website using a TCP connection, using the HTTP 1.0 protocol, keeping the TCP connection short and closing it after reading the response, thus simulating the io.EOF error. 1 2 3 4 5 6 conn, err := net.Dial("tcp", "rpcx.site:80") if err != nil { fmt.

The Type System of Javascript

Overview The type judgment of JavaScript is a necessary part of the front-end engineers’ code every day, and every day they must write a if (a === 'xxx') or if (typeof a === 'object') similar type judgment statement, so mastering the type judgment of JavaScript is also a necessary skill for the front-end, the following will be from the type of JavaScript, type judgment and some internal implementation to give

Android Surfaceview Source Code Analysis and Use

SurfaceView is a special kind of view in Android. The biggest difference between it and TextView and Button is that it is not on the same view layer as its view container, and its UI display can be done in a separate thread, so the drawing of SurfaceView does not affect the main thread. surfaceView does not affect the main thread. Combining these features, SurfaceView is generally used to implement dynamic or complex images and animations.

Web Worker Tutorial

1. Overview The JavaScript language uses a single-threaded model, which means that all tasks can only be done on one thread, one thing at a time. If the previous task is not done, the later task has to wait. With the increase in computing power of computers, especially with the advent of multi-core CPUs, single-threading poses a great inconvenience and cannot fully utilize the computing power of computers. The role of the Web Worker is to create a multi-threaded environment for JavaScript, allowing the main thread to create Worker threads and assign some tasks to the latter to run.

Build an Etcd Cluster With Etcdadm

1. Introduction In the process of building a Kubernetes cluster, the first thing to do is to fix the Etcd cluster. Although the kubeadm tool already provides an automatic way to build the Etcd cluster that is bound to the master node by default, I personally always manually build the Etcd cluster on the host; because this thing is so important, it is no exaggeration to say that It is

MySQL Crash Safe

The MySQL master-slave architecture has been widely used, and the stability of the master-slave replication relationship is a constant concern. MySQL 5.6 provides a new feature for master-slave replication stability: slave support crash-safe. This feature can solve the problem of relay_log.info bit inaccuracy caused by abnormal power failure in previous versions. In this article, we will introduce this feature in terms of principle, parameters, and new issues. Translated with www.DeepL.com/Translator (free version)

Kubernetes Switching to Containerd

1. Environmental preparation Ubuntu 20.04 x5 Etcd 3.4.16 Kubernetes 1.21.1 Containerd 1.3.3 1.1. Handling IPVS Since the new version of Kubernetes Service implementation switches to IPVS, you need to make sure the kernel has IPVS modules loaded; the following command will set the system to automatically load IPVS related modules at boot, and you need to reboot after execution. 1 2 3 4 5 6 7 8 9 10 11

Npx Tutorial

The npx command has been added to npm since version 5.2. It has many uses, and this article introduces the main usage scenarios of the command. Node comes with an npm module, so you can use the npx command directly. In case it doesn’t work, you’ll have to install it manually. 1 $ npm install -g npx Calling the project’s installed modules The main problem that npx is trying to solve is calling modules that are installed inside the project.

Implementing Lock Free Queues With Go

A queue is a very common data structure that allows only outgoing (dequeue) operations at the front end of a table (head) and incoming (enqueue) operations at the back end of a table (tail). Like the stack data structure, a queue is a linear table with restricted operations. The end that performs the insert operation is called the tail and the end that performs the delete operation is called the header.

Spring Cloud Gateway Custom Exception Handling

When we usually use SpringMVC, as long as the request is processed by DispatcherServlet, you can customize the handling logic of different types of exceptions through @ControllerAdvice and @ExceptionHandler, you can refer to ResponseEntityExceptionHandler and DefaultHandlerExceptionResolver, the underlying principle is very simple, that is, when an exception occurs, search for the exception handler that already exists in the container and match the corresponding exception type, after a successful match, use

Spring Cloud Gateway-ServerWebExchange Core Methods and Request or Response Content Modification

Prerequisites This article was written using Spring Cloud Gateway version Greenwich.SR1. When we use Spring Cloud Gateway, we notice that the filters (including GatewayFilter, GlobalFilter and the filter chain GatewayFilterChain), all depend on the ServerWebExchange. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 public interface GlobalFilter { Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain); } public interface GatewayFilter extends ShortcutConfigurable { Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain);