Weekly - issue 41

双面镜的原理

常见的镜子,反射层都镀在后表面,有灰扑扑的“背面”,光线照到玻璃的后表面会反射回来。

如果把指尖按在镜子上(玻璃的前表面),眼睛看到“镜子后面”先有一个同样厚度的玻璃,然后才是手指的图像,手指和镜像手指之间会有一段距离,不会贴在一起。

反射层镀在后表面有一个缺陷 —— 光线照到玻璃的前表面的时候也会多少反射一些,同时还会有折射,这会稍微影响镜像的质量。对于一些精度要求高的地方,使用前表面反光镜。把手指贴到前表面反光镜上,手指和镜像手指则会贴到一起。

普通的镜子,其反射层会把光线几乎全部反射。但如果把全反射层换成只可以反射 50%-70% 光的半反射层,就是双面镜。让镜子起到“双面不同”作用的,是两侧的光强差距:对光亮的房间来说,反射回来的光线更抢眼,镜子就只是镜子;但对昏暗的房间里,对面过来的光线更抢眼,所以镜子就成了玻璃。

一句话总结双面镜:亮处看不到暗处,暗处可以看到亮处。

Mastering curl: interactive text guide

# To specify query parts separately
curl http://httpbin/get --url-query "name=Alice" --url-query "age=25"

# URL globbing
# This command requests three different paths (al, bt, gm),
# each with two different parameters (num=1 and num=2),
# for a total of six URLs
curl --output-dir /tmp -o "out_#1_#2.txt" \
  http://httpbin/anything/{al,bt,gm}?num=[1-2]

# To extract specific information about the response
curl -w "\nstatus: %{response_code}\ntype: %{content_type}" \
  http://httpbin/status/429

# Upload file
curl -T /tmp/hello.txt http://httpbin/put

# To limit bandwidth usage.
# It accepts anything from bytes to petabytes
curl --limit-rate 3k http://httpbin/get

# Limit the number of concurrent requests.
# It accepts seconds, minutes, hours or days
curl --rate 3/s http://httpbin/anything/[1-9].txt

# Curl supports two different conditions: file timestamp and etag.
# Download the data only if the remote resource is newer
# -i, include the HTTP response headers in the output
curl -i --time-cond "Aug 30, 2023" http://httpbin/etag/etag
# Or older
curl -i --time-cond "-Aug 30, 2023" http://httpbin/etag/etag
# To checks an etag, curl must first to save it
curl --etag-save /tmp/etags http://httpbin/etag/etag
curl -i --etag-compare /tmp/etags http://httpbin/etag/etag

# HTTP POST
curl -d name=alice -d age=25 http://httpbin/post
curl -d @/tmp/data.txt -H "content-type: text/plain" \
  http://httpbin/post
curl --json '{"name": "alice"}' http://httpbin/post
curl --json @xx.json http://httpbin/post
cat xx.json | curl --json @- http://httpbin/post
# To URL-encode data
curl --data-urlencode "Name: Alice Barton" http://httpbin/post
# multipart/form-data
curl -F name=Alice -F age=25 -F photo=@/tmp/alice.png \
  http://httpbin/post

# Curl does not follow redirects by default.
# To make curl follow redirects, use --follow (-L)
# To protect against endless loop redirects, use --max-redirs
curl -L --max-redirs 3 http://httpbin/redirect/10

# Curl ignores cookies by default.
# To enable them, use the --cookie (-b) option.
# Specify a file to read from or use a blank string
curl -b "" -c /tmp/cookies http://httpbin/cookies
# Tell curl a new cookie session starts by using -j,
# --junk-session-cookies
# A new session begins.
# It is the equivalent of closing a browser and starting it up again.
curl -j -b /tmp/cookies http://httpbin/get

# This tells curl to store HSTS-enabled servers in the specified file
# and automatically convert http → https when accessing them.
curl --hsts /tmp/hsts http://httpbin/get