CodingTour
ARTS #69 | Netlify 镜像

Algorithm

本周选择的算法题是:Best Time to Buy and Sell Stock

规则如下:

Say you have an array for which the ith element is the price of a given stock on day i.

If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Note that you cannot sell a stock before you buy one.

Example 1:

Input: [7,1,5,3,6,4]
Output: 5
Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
             Not 7-1 = 6, as selling price needs to be larger than buying price.

Example 2:

Input: [7,6,4,3,1]
Output: 0
Explanation: In this case, no transaction is done, i.e. max profit = 0.

Solution

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        if not prices: return 0
        min_price, max_profit = prices[0], 0
        for price in prices:
            if price <= min_price:
                min_price = price
            else:
                max_profit = max(max_profit, price - min_price)
        return max_profit

Review

What’s new in Xcode 12

看看 Xcode 的变化。

摘取了几个我感兴趣的:

  • 支持 Apple Silicon Macs,不用改一行代码

  • tab 终于像 Code 那样好用了

  • 代码完成响应得更快,但是隐藏了一些信息,比如函数的返回值

  • 模拟器支持“置顶”了

  • 断点可以命名联动了,比如先创建一个叫 MyBreakpoint 的断点并禁用它,然后在另一个断点的 action 里启用:

    break enable MyBreakpoint
    
  • 支持本地调试 StoreKit

Tip

彻底解决 CI & CD 机器访问 github 慢的问题:

git config --global url."https://hub.fastgit.org/".insteadOf https://github.com/

只需要在构建机器的部署脚本里增加一个全局配置即可,优势很明显:对上层透明,无侵入,而且对 submodule 也生效。

Share

GitHub Pages 越来越慢了,本周尝试在 Netlify 上搭了个镜像,记录一下过程:

  • GitHub 上的源码不用 Gemflie 也能编译,但是 Netlify 不行,所以需要创建并提交 Gemfile,这一系列基础过程可以看这里

  • 如果还想继续使用 github-pages 的话,得配置一下 repository,原因可以看这里。这样一来可以同时支持 GitHub Pages 和 Netlify

  • 更新 favicon 的链接路径,去掉对 site.github.url 的依赖

  • 减少混合内容,此举可以让站点变得更安全

  • 我在原先的 CSS 里引入了其他的字体:

    @import url("https://fonts.googleapis.com/css?family=Open+Sans:400,700");
    

    但是被 Netlify 优化后这条语句及对应的功能似乎缺失了,为此可以单独将对应的内容写进同一个 CSS 文件,这样还能减少浏览器下载的开销

  • Done

然后就可以同时在两个域名下访问了:

之所以选择 Netlify 也有两个原因:

  • 自带 CDN
  • 可以白嫖 SSL 证书

目前加速效果不是特别明显:

再多观察几天看看。