Starting with Sequence Sequence is a Lazy List implementation provided by Kotlin. For example, the following Fibonacci list is implemented using Sequence. 1 2 3 4 5 6 7 8 9 10 val fibonacci = sequence { var terms = Pair(0L, 1L) while (true) { 🏹 yield(terms.first) terms = Pair( terms.second, terms.first + terms.second ) } } The terminal operator We use an infinite loop in the Sequence builder block
Kotlin Coroutine and Retrofit
Retrofit 2.6.0 supports defining interfaces with Kotlin suspend functions. This article describes how to create the most comfortable coroutine experience by customizing the Retrofit Call Adapter and Converter. Call Adapter: custom request execution logic, including thread switching, etc. Converter: Customize the deserialization logic, how to convert the bytes obtained from the request into objects. Spoiler for the final result. 1 2 3 4 5 6 7 8 9 10 11
Marshal serialization of numeric types such as int64 safely in Go
Javascript’s base type (POD) and JSON actually have only one numeric type: Number. Number is usually represented by the 64-bit floating-point standard in IEEE-754 in mainstream browser implementations (i.e., double-precision floating-point), which represents valid numbers in the range \(-(2^{53} - 1)\) ~ \(2^{53} - 1\) . While 64-bit data types are often used in Go language, e.g., int64/uint64, such values are not safe to use in Javascript.
If you look at the JSON specification document, there is no limit to the number of bits, and any large value can be placed in JSON.
Run the sshd service inside the container
I want to share data with different friends, but I don’t really want to create new users on my system. Because in most Linux distributions, the default umask is 022, which means that other users can access my home directory and read files at will, which means no privacy and no security. If my friend’s account/password is accidentally leaked, it will also endanger all the data in my system, I
A little research on the connection reuse problem caused by unread http.Response.Body
In the source code of Golang’s HTTP library, the description of http.Response.Body is as follows. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 // Body represents the response body. // // The response body is streamed on demand as the Body field // is read. If the network connection fails or the server // terminates the response, Body.Read
Simply defer file.Close() is probably a misuse
The use of defer statements in Go can be considered as a language style or habit. But while convenience is convenient, being able to use the defer statement to delay closing/cleaning files without errors is not so easy to guarantee. Writing files and closing them For example, in the code related to Go language file operations, you can see code like the following everywhere. 1 2 3 4 5 6
The impact of CURL caching on downloading streaming data
When accessing a gRPC streaming interface (converted to HTTP) with cURL before, a very strange phenomenon occurred.
when directly cuRL, always the full content is displayed and the connection does not break, because it is a streaming interface, which is exactly the expected behavior. And when cURL | ... or cURL > file, the full content is never available, and it doesn’t work no matter how long you wait. Why is this?
Some minor issues with LIKE fuzzy lookups in MySQL
Today, a colleague found a bug in MySQL regarding fuzzy lookups, which is quite embarrassing to say the least. When I saw the problem, I didn’t even know what I had written wrong.
The problem was that I meant to find rows in the database starting with abc_, but I ended up with a statement that looked like the following
1 SELECT * FROM users_tab WHERE name LIKE 'abc_%'; Can you find the desired results this way?
A problem with time and time zone resolution in Go
Almost all examples of time resolution in Go take the full time including the date, and the official example is no exception. But few people have used the following code as an example to explain the behavior until the day the user makes a mistake.
Background of the problem Trying to get the user to enter a readable time as input from the terminal, but I find that I am parsing the input incorrectly.
Using the Tokyo Cabinet Key/Value Database in Golang
Tokyo Cabinet is an early KV database developed in C. It also supports a wide range of data structures, mainly for its fast read and write performance at certain levels of data volume.
Tokyo Cabinet data structure.
Here is a simple read/write comparison with goleveldb and boltdb, using Tokyo Cabinet’s Hash data structure.
10 data tests 1 2 3 4 5 6 7 8 9 10 11 12 13 % go test -bench "Benchmark*" -benchmem -benchtime 10s kvLst len 20 db size 7847B 0MB goos: darwin goarch: amd64 pkg: tk cpu: Intel(R) Core(TM) i7-4870HQ CPU @ 2.
Docker install mysql
MySQL is the world’s most popular open source database. With its reliability, ease of use and performance, MySQL has become the database of choice for web applications. 1. Check the available MySQL versions mirror of mysql Alternatively, you can search for available versions by docker search mysql. 2. Pull the mysql image 1 2 3 4 5 6 docker pull mysql:latest 或者拉取其他版本 docker
Big Data Basics: HIVE
Hive Introduction Hive, implemented by Facebook and open source, is a data warehouse tool based on Hadoop. It maps structured data into a database table and provides HQL (Hive SQL) queries. The underlying data is stored on HDFS, and Hive essentially converts SQL statements into MapReduce tasks to run, making it easy for users unfamiliar with MapReduce to process and compute structured data on HDFS using HQL, suitable for offline
Building Android interfaces for any screen size
With around 100 million new tablet devices activated in the last 12 months and Chrome OS activations up by 92%, it is the fastest growing desktop platform. This means that with more than 250 million large screen devices running Android on tablets, foldable devices and Chrome OS devices, and the number of foldable devices in use growing by more than 250% year-on-year, the ‘big screen’ is becoming an important and
What should I do if my Linux process is stuck?
When we are using Linux, if there is a problem with network or disk I/O, we may find that the process is stuck, even if we use kill -9, we cannot kill the process, and many common debugging tools such as strace, pstack, etc. are not working.
At this point, we use ps to view the list of processes and see that the status of the stuck process is shown as D.
ECMAScript 2022 Preview: 10 Proposals for Stage 4 in 2021
In 2021, a number of proposals entered Stage 4 of TC39. In the TC39 process, each proposal starts at Stage 0, and moving to Stage 4 means that the proposal has been signed off by the ECMAScript editors and has become a de facto standard feature. This article lists the 10 proposals that will enter Stage 4 in 2021 and will be incorporated into ECMAScript 2022. Class Fields Declares the
Promise or Async/Await?
1. Preface So far in front-end development, asynchronous problems have experienced the despair of Callback Hell, the normative melee of Promise/Deffered, the invincibility of Generator, and now the acceptance of Async/Await by the public, in which Promise and Async/Await are still active in code. Their perceptions and evaluations have been reversed many times, and they have their own fans, creating a love-hate relationship that continues to this day, and the
Apache PLC4X authors to stop free community support, ask enterprise users to pay for their labour
After the author of Faker.js emptied the project’s repository code, another software author has been disappointed that companies have used his open source project without giving anything back. on January 11, Christofer Dutz, creator of Apache PLC4X, posted on GitHub, stating that he will stop providing free community support to corporate users of PLC4X due to the lack of any form of return. If no company is willing to step forward to fund the project, he will cease maintenance and any form of support for PLC4X.
How is the Go timer scheduled?
This article breaks down the Go timer. Timers are an important part of both business and infrastructure development, which shows how important they are. Whether we initialise a timer with NewTimer, timer.After, or timer.AfterFun, the timer is eventually added to a global timer heap, which is managed by Go runtime. The global timer heap has also undergone three major upgrades. Before Go 1.9, all timers were maintained by a globally
High Performance C++ HTTP Client Principles and Implementation
1. What is Http Client The Http protocol, a common language across the Internet, and the Http Client, arguably the most basic method we need to get data from the Internet world, is essentially a URL to a webpage conversion process. And with the basic Http Client functionality, paired with the rules and policies we want, everything from content retrieval down to data analysis can be implemented.
Today we’re giving you a high-performance Http client in C++, and it’s easy!
Redis Large Cluster Scaling Performance Optimization in Practice
1. Background In existing network environments, some businesses using Redis clusters often need to expand their node capacity as business volume increases. I have previously learnt that some of my operations and maintenance colleagues have experienced a decrease in performance after scaling a Redis cluster with a relatively large number of nodes, as evidenced by a significant increase in access latency. Some businesses are sensitive to Redis cluster access latency,