Hip Driven Freestyle

Hip drive is suitable for long distances and is relatively more energy-efficient compared to shoulder drive. Catch (Hold Water) Relax the shoulders, and form a resistance surface for pushing water with the inner side (the side not touched by the sun) of the entire arm. The push water resistance surface includes the inner upper arm, inner forearm, and inner palm. Keep elbows appropriately bent at about 100 degrees. Relax shoulders and armpits, but keep core (abdomen) tight, and maintain a straight body line. ...

March 12, 2022 · 2 min

Docker

1. Docker The client operates images and containers through the docker daemon running on the host, and the registry provides image publishing and downloading (similar to npm and pip). A Docker image is a special read-only file system that provides programs, libraries, resources, configuration files, and other files required for container runtime. It also contains some configuration parameters prepared for runtime (such as anonymous volumes, environment variables, users, etc.). The image does not contain any dynamic data, and its content will not change after being built. ...

March 8, 2022 · 39 min

Unit Testing, Test Driven Development

1. Introduction The diagram below comes from Learning Curves (for different programming languages). Although the article is primarily humorous, it shows the author’s attitude towards unit testing. For Python programmers, as experience grows, after mastering unit testing, personal productivity gets a sudden boost (as for mastering decorators, one might feel inflated, but the efficiency improvement is not obvious). Many years ago, just out of school, in the C++ era. A Java expert from former Nortel evangelized to the development team, recommending cpp-unit, saying unit testing “can significantly improve individual combat capability.” Time passes, through many battles, I’ve lost contact with Eddie from Nortel, but his evangelism was clearly successful. I’ve practiced unit testing in different projects: ...

March 6, 2022 · 4 min

A Simple API Proxy

1. Background When configuring Directus to use DingTalk QR code login, I found that DingTalk’s password-free login (OAuth 2) is not consistent with the RFC specification. Protocol conversion is needed before it can communicate with Directus normally. This is a relatively niche requirement, and there was no existing software available, so I had to build it myself. 2. Main Functions Can act as a middleware for API communication, forwarding communication between clients and API servers, recording LOGs for convenient protocol analysis; As a middleware, it can modify request content and response content; it can do protocol adaptation and conversion. APIPROXY is a RESTFUL API proxy, monitor and adaptor. ...

March 5, 2022 · 2 min

Modules in TypeScript

Unlike Python, TypeScript/JavaScript has a wide variety of module import and export methods. Currently, ES6 has been standardized, so using import/export is recommended. Due to historical legacy and the huge number of npm libraries, require/exports will continue to coexist for a long time. 1. ES6 Module Import and Export 1.1. Syntax Three export methods, two import methods export import export var; import {var} from module export {var}; import {var} from module export default var import var from module You can also use: ...

March 4, 2022 · 2 min

Typescript

TypeScript learning notes. From zero to hero. 1. Array, Tuple, Union, Enum // Basic Types let id: number = 5 //Add type after variable, separated by colon let company: string = 'Traversy Media' let isPublished: boolean = true let x: any = 'Hello' //any type variable can hold any type of data let ids: number[] = [1, 2, 3, 4, 5] //Variable-length array; different from traditional static language int a[4]; let arr: any[] = [1, true, 'Hello'] //any array, can mix various values // Tuple let person: [number, string, boolean] = [1, 'Brad', true] //Tuple: array with known number of elements and types; element types need not be the same. // Tuple Array let employees: [number, string][] //Array where each element is a tuple employee = [ [1, 'Brad'], [2, 'John'], [3, 'Jill'], ] // Union let pid: string | number //Union /* Below is C language union - a variable that can store several different types of data union data{ int n; char ch; double f; }; */ pid = '22' // Enum enum Direction1 { Up = 1, Down, Left, Right, } enum Direction2 { Up = 'Up', Down = 'Down', Left = 'Left', Right = 'Right', } 2. Map // Definition type MapType = { [id: string]: string; } // Instantiation const map: MapType = {}; map['a'] = 'b'; map['c'] = 'd'; // Deletion delete map['c']; // Enumeration for (let i in map) { console.log(map[i]); } // Get array containing all keys console.log(Object.keys(map)); // Another implementation using Record const map: Record<string, string> = {}; map['a'] = 'b'; map['c'] = 'd'; 3. Object // Objects type User = { id: number name: string } const user: User = { id: 1, name: 'John', } // Type Assertion - type casting let cid: any = 1 // let customerId = <number>cid Casting from any to number let customerId = cid as number 4. Function // Functions function addNum(x: number, y: number): number { return x + y } // Void function log(message: string | number): void { console.log(message) } 5. Interface, Class // Interfaces interface UserInterface { readonly id: number name: string age?: number } const user1: UserInterface = { id: 1, name: 'John', } interface MathFunc { (x: number, y: number): number } const add: MathFunc = (x: number, y: number): number => x + y const sub: MathFunc = (x: number, y: number): number => x - y interface PersonInterface { id: number name: string register(): string } // Classes class Person implements PersonInterface { id: number name: string constructor(id: number, name: string) { this.id = id this.name = name } register() { return `${this.name} is now registered` } } const brad = new Person(1, 'Brad Traversy') const mike = new Person(2, 'Mike Jordan') // Subclasses class Employee extends Person { position: string constructor(id: number, name: string, position: string) { super(id, name) this.position = position } } const emp = new Employee(3, 'Shawn', 'Developer') 6. Generics // Generics => Similar to C++ templates function getArray<T>(items: T[]): T[] { return new Array().concat(items) } let numArray = getArray<number>([1, 2, 3, 4]) let strArray = getArray<string>(['brad', 'John', 'Jill']) strArray.push(1) // Throws error 7. FAQ 7.1. type alias or interface https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#differences-between-type-aliases-and-interfaces ...

March 4, 2022 · 3 min

What is Basis Point (bps)?

What is bps? BP (or bps) stands for Basis Point. In Chinese, it’s translated to “基点” (jī diǎn). It’s a ratio, meaning one ten-thousandth, which is one hundredth of one percent. Why Do We Need This Concept? Why not just say “one ten-thousandth” and introduce a new term instead? Basis points are convenient and steady. Basis points are less ambiguous than percentages as they represent an absolute, set figure instead of a ratio. ...

March 3, 2022 · 1 min

Designing High-Performance and Scalable API Services

Directus itself is a NodeJS-based API server. The TPS it can support depends on multiple factors such as the database system and API query design. This article provides some architectural considerations to enable Directus applications to scale with business growth by adding hardware, thereby improving system processing capacity and achieving good scalability in performance. 1. How to Plan a Scalable Directus Application Directus focuses on two aspects for handling high load scenarios: ...

March 2, 2022 · 2 min

OAuth2 Application Practice: Attempting to Integrate DingTalk Login with Directus

1. Project Overview The expected outcome of this small project is to allow Directus to support logging in with DingTalk accounts. After understanding the OAuth2 protocol (see the previous blog post, reference 1), we have enough knowledge to implement this. Directus natively supports GitHub login, so the approach is to start with GitHub. Follow these steps: Configure Directus to use GitHub account login to get familiar with Directus’s standard OAuth support Configure Directus to use DingTalk account login; since DingTalk’s protocol implementation differs from RFC6749/GitHub, we may need to handle issues as they arise Deploy Directus to the server environment and verify on both DingTalk PC and mobile versions 2. Environment Configuration Use ngrok locally to expose a service to receive OAuth server redirects. ...

February 27, 2022 · 11 min

OAuth2 Protocol Analysis: GitHub and DingTalk Examples

1. Principle Suppose there’s an APP that wants me to use GitHub for authorized login. In this login scenario: I, as the data owner, tell the system (GitHub) that I agree to authorize a third-party application (App) to enter the system and obtain certain data (my ID, avatar, etc.). The system then generates a short-term access token to replace the password for the third-party application (APP) to access the data. ...

February 26, 2022 · 14 min