苹果官方的链接在这里

OS X Yosemite and later

Use the following Terminal command to reset the DNS cache in OS X v10.10.4 or later:

sudo killall -HUP mDNSResponder

Use the following Terminal command to reset the DNS cache in OS X v10.10 through v10.10.3:

sudo discoveryutil mdnsflushcache

OS X Mavericks, Mountain Lion, and Lion

Use the following Terminal command to reset the DNS cache in OS X v10.9.5 and earlier:

sudo killall -HUP mDNSResponder

Mac OS X Snow Leopard

Use the following Terminal command to reset the DNS cache in OS X v10.6 through v10.6.8:

sudo dscacheutil -flushcache

Published Date: Aug 25, 2016

  1. 简单直白的版本
import requests 

def download_file(url):
    r = requests.get(url) 
    with open("test.zip", "wb") as f:
        f.write(r.content)
  1. 大文件的下载
import requests 

def download_file(url):
    local_filename = url.split('/')[-1]
    # NOTE the stream=True parameter
    r = requests.get(url, stream=True)
    with open(local_filename, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024): 
            if chunk: # filter out keep-alive new chunks
                f.write(chunk)
                f.flush()
    return local_filename
  1. 更 robust 的版本
    可以看到这里,这篇文章作者基本上考虑到了下载中会遇到的各种情况,源代码在这里。

  1. 修改 root 密码
ubuntu@VM-46-251-ubuntu:~$ sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
  1. sudo 权限修改 /etc/ssh/sshd_config
ubuntu@VM-46-251-ubuntu:~$ su
Password:
root@VM-46-251-ubuntu:/home/ubuntu#
root@VM-46-251-ubuntu:/home/ubuntu# vi /etc/ssh/sshd_config

然后进入 sshd_config 中,/为查找命令,找到 PermitRootLogin prohibit-password# 注释掉
紧接着加入 PermitRootLogin yes,方法为 i 进入编辑模式,加入设置,:wq 写入退出

  1. 重启 SSH 服务,使配置生效
root@VM-46-251-ubuntu:/home/ubuntu# service ssh restart

Done.

为没使用过 Linux 的同学推荐 TLCL

Levenshtein 距离

叫编辑距离大家就都秒 get√ 了,经典动归。
这里给出 Python 的实现。

def levenshtein(first, second):
    first_length = len(first)
    second_length = len(second)
    if first_length > second_length:
        first, second = second, first
        first_length, second_length = second_length, first_length
    if first_length == 0:
        return second_length
    if second_length == 0:
        return first_length
    distance_matrix = [range(second_length+1) for x in range(first_length+1)]
    # print distance_matrix
    for i in range(1, first_length+1):
        for j in range(1, second_length+1):
            deletion = distance_matrix[i - 1][j] + 1
            insertion = distance_matrix[i][j - 1] + 1
            substitution = distance_matrix[i - 1][j - 1]
            if first[i - 1] != second[j - 1]:
                substitution += 1
            distance_matrix[i][j] = min(insertion, deletion, substitution)
    print distance_matrix
    return distance_matrix[first_length][second_length]

有需要的自取。