April 05, 2021 Information digest
Released the original address: Digest | algorithm: edit distance calculation, the front-end performance testing tools
Learn algorithms every day
Google interview question: Calculate edit distance
The edit distance between two strings is the minimum number of inserts, deletions, and substitutions needed to convert them to another string. For example “Kitten” and “sitting” have an edit distance of 3.
The edit distance between two strings refers to the minimum number of character insertions, deletions, and substitutions required to change one string to the other. For example, the edit distance between “kitten” and “sitting” is three: substitute the “k” for “s”, substitute the “e” for “i”, and append a “g”.
Given two strings, calculate their edit distance.
Given two strings, compute the edit distance between them.
def edit_distance(string1, string2) :
"""Ref: https://bit.ly/2Pf4a6Z"""
if len(string1) > len(string2):
difference = len(string1) - len(string2)
string1[:difference]
elif len(string2) > len(string1):
difference = len(string2) - len(string1)
string2[:difference]
else:
difference = 0
for i in range(len(string1)):
ifstring1[i] ! = string2[i]: difference +=1
return difference
print(edit_distance("kitten"."sitting")) # 3
print(edit_distance("medium"."median")) # 2
Copy the code
Others worth reading
This will make you a command line ninja
英 文 : This Will Make You a command-line Ninja
The Unix philosophy
Write designed that do one thing and do it well. | programs written only do one thing, and should do well. The Write designed to work together. | program must be able to work together. The Write designed to handle the text streams, because that is a universal interface. | Write programs to deal with text flow, because it is a common interface.
variable
-
$0 – Name of the current script,
-
$1.. $9 – The first nine arguments of the script.
-
$# – The number of arguments passed to the script.
-
$@ – All parameters supplied to the script.
-
$USER – The USER name of the USER running the script.
-
$HOSTNAME – The HOSTNAME of the machine on which the script is running.
-
$SECONDS – The number of SECONDS after the script starts.
-
$RANDOM – Returns a different RANDOM number for each reference.
-
$LINENO – Returns the current line number in the Bash script.
How do I monitor basic system metrics in Linux
LFCA: How to Monitor Basic System Metrics in Linux
# Get the system's date and the time the system was turned on
uptime -s
uptime -p
# To get a glimpse of the total and available memory and swap space on your system
free -h
# provides a summary of the real-time system metrics and displays the currently running processes that are managed by the Linux kernel.
top
# $ sudo apt install htop [On Debian-based]
# $ sudo dnf install htop [On RHEL-based]
htop
# The df command provides information on hard disk utilization per filesystem.
df -Th
Copy the code
Eight free front-end performance testing tools
原文 : 8 FREE FRONT END TESTING TOOLS
- Web Page Test is a quick way to Test slow loading websites.
- GTMetrix is similar to the above, you can Google PageSpeed Grades and Yslow Grades.
- Google Page Speed Insights they offer both mobile and desktop testing. Interestingly, they use mobile views by default.
- Y-slow Y-slow is a browser plug-in (by Yahoo!) that tests web speeds and is available in almost all modern browsers except IE.
- Neustar Ultratools A collection of tools for hosting speed checks, DNS checks, and more. They keep moving things around and adding/removing features.
- Sitespeed. IO is used to evaluate client performance of real browsers.
- ManageWP manages multiple WP sites from one location.
A bit in the
- To be mature you have to realize what you value most. If you want to be a mature person, you have to realize what is most valuable to you.
- The premise of success is to learn to choose