Cheatsheet: Write Multiple Lines Content in YAML

date: 2022-05-31 · Tags: #dev, #til

It's crazy that there are NINE different ways to write multi-line strings in YAML.

Here is a simple cheatsheet:

  • Use > most of the time: interior line breaks are stripped out, although you get one at the end.
  • Use | if you want those linebreaks to be preserved as \n (for instance, embedded markdown with paragraphs).
  • Use >- or |- instead if you don't want a linebreak appended at the end.
  • Use "blahblah..." if you need to split lines in the middle of words or want to literally type linebreaks as \n

And this is difference betweetn " and ' in YAML:

How to create a literal:blank without quotes"'
Single quote''''
Double quote"\""
Backslash\\\\
  • Whenever applicable use the unquoted style since it is the most readable.
  • Use the single-quoted style (') if characters such as " and \ are being used inside the string to avoid escpaing them and therefore improve readability.
  • Use the double-quoted style (") when the first two options aren't sufficient, i.e. in scenarios where more complex line breaks are required or non-printable characters are needed.

Check references for more detailed examples :(

References:

  1. YAML Multiline
  2. How do I break a string in YAML over multiple lines?
  3. YAML: Do I need quotes for strings in YAML?

What’s in which Python

date: 2022-05-31 · Tags: #python, #good-reading

You're able to look up the major key feature changes from Python 2.1 to Python 3.11 in one page!

This is a summary of what features appeared in which versions of Python. Items with a star were introduced with a __future__ import.

What’s in which Python

Lesser Known PostgreSQL Features

date: 2022-05-30 · Tags: #sql, #til

Yeah, the first I know I could do linear regression in PostreSQL.😅 At least, SQL rules all in BIG data. For the third article, It's may another way to implement workable distributed locks.

Refs:

  1. Lesser Known PostgreSQL Features
  2. Practical SQL for Data Analysis
  3. Handling Concurrency Without Locks

Customizable Python UI-Library based on Tkinter

date: 2022-05-28 · Tags: #python, #ui

Wow, what a pretty and simple UI library for Python!

macOS-system-mode-change

Python has a builtin UI toolkit named as Tkinter which do not look well actually, but it's embeded as std lib while included in many OS distributions. CustomTkinter is a small enough library to beautify your applications!

TomSchimansky/CustomTkinter: A modern and customizable python UI-library based on Tkinter

You Should Compile Your Python And Here’s Why

date: 2022-05-25 · Tags: #python

What? 通过预编译 string template 来达到性能的提升 ???

You Should Compile Your Python And Here’s Why

Tracking Side Effects in Scala

date: 2022-05-23 · Tags: #scala

This article1 is about how to use new features 234 from Scala 3 to distinguish side effects safely via type signatures in compile time.

Quite interesting to learn new syntax if you could implement them by yourself.

References:

Footnotes

  1. Tracking Side Effects in Scala

  2. Scala 3 Reference - Context Functions

  3. Scala 3 Reference - Erased Definitions

  4. Scala 3 Reference - CanThrow Capabilities

The balance has shifted away from SPAs

date: 2022-05-22 · Tags: #dev, #react, #good-reading

What is next trend in Javascript UI framework (maybe should limit to SSG)? I think "0kB JavaScript by default." must have a name. People has been bored with heavy runtime bring by framework in order to achieve the most extreme lightweight and speed. Here are serveral featured libraries:

SPAs are no longer the cool kids they once were 10 years ago. --- The balance has shifted away from SPAs

Update 2022-07-03:

New player is comming. denoland/fresh: The next-gen web framework.

Initial JSON Type Support in Python

date: 2022-05-21 · Tags: #python, #til

Because typing system in Python lacks of recursive type, we can not annotate JSON-like data for type hints. Recently, There is a progress that an experimental JSON type has been implemented under _typeshed lib.

Try it like:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from _typeshed import JSON

Of course, we still need to wait offical JSON type support.

Define a JSON type #182

Update 2022-06-22: The PR in typeshed still can not be merged.

Happy Birthday to designer Dieter Rams, who's turning 90 today!

date: 2022-05-21 · Tags: #design, #news

Happy Birthday to Dieter Rams!

I just know that from tweet of Gary Hustwit1, who's the director of the documentary film Rams2.

Dieter Rams (May 20, 1932) is a great designer ever who belief in "Less, but better" design. I also post his famous ten principles of "Good design"

To celebrate the day, Director Gary Hustwit is streaming his documentary film about Dieter free worldwide a few days.

Besides, I also strongly recommend Gary Hustwit's other films on industrial design!

Footnotes

  1. Gary Hustwit's Tweet

  2. https://www.hustwit.com/rams

Google Cloud Released AlloyDB for PostgreSQL

date: 2022-05-15 · Tags: #cloud, #news

At Google I/O 2022, Google Cloud team announced AlloyDB for PostgreSQL, a fully-managed, PostgreSQL-compatible database for demanding, enterprise-grade transactional and analytical workloads.

Features:

  • Fully compatible with PostgreSQL, providing flexibility and true portability for your workloads
  • Superior performance, 4X faster than standard PostgreSQL for transactional workloads
  • Transparent and predictable pricing, with no expensive licensing and no opaque I/O charges
  • Simplified management with machine learning-enabled autopilot systems

All in cloud native! All in PostgreSQL! :)

Introduce storage engine of AlloyDB: AlloyDB for PostgreSQL under the hood: Intelligent, database-aware storage

Product: AlloyDB for PostgreSQL

EnterpriseDB's solution for cloud-native PostgreSQL:

cloudnative-pg -> Github

PEP 690 – Lazy Imports

date: 2022-05-14 · Tags: #python

IMHO, I like lazy imports as a fancy and powerful opt-in feature, but it's quite doubtful to set this feature enabled by default in current proposal (PEP 690).

Implicit behaviors are terrible and will obviously break backward compatibility.

Do we forget the Zen of Python: "Explicit is better than implicit"?

PEP 690 – Lazy Imports

Discussions | PEP 690 Lazy Imports

Update 2022-07-05:

An article about how Meta use lazy imports to speed up Instagram Python server's slowdown caused by complex dependency hell.

Python Lazy Imports With Cinder

RFC 3339 vs ISO 8601

date: 2022-05-13 · Tags: #til, #dev

Shocked me. I just learned they have such great difference betweetn two standard specs.

Try use their intersected part as possible as you can in most scenarios.

RFC 3339 vs ISO 8601

Stroing State in the URL

date: 2022-05-10 · Tags: #backend, #dev

It's simple but useful. Learn how to parse url arguments in common way. Remember that do not play too complex tricks, KISS as possible as you can.

Storing State in the URL

Caddy 2.5.0 Upgrade Issues

date: 2022-05-01 · Tags: #dev, #news

If you put your servers behind CDN like Cloudflare or Caddy is not reaced firstly, there are serveral notable changes while updating Caddy to 2.5.0:

⚠️ Reverse proxy: Incoming X-Forwarded-* headers will no longer be automatically trusted, to prevent spoofing. Now, trusted_proxies must be configured to specify a list of downstream proxies which are trusted to have sent good values. You only need to configure trusted proxies if Caddy is not the first server being connected to. For example, if you have Cloudflare in front of Caddy, then you should configure this with Cloudflare's list of IP ranges.

References:

  1. https://github.com/caddyserver/caddy/releases/tag/v2.5.0
  2. https://caddyserver.com/docs/caddyfile/directives/reverse_proxy
  3. https://caddy.community/t/caddy-v2-5-0-rc-1-and-x-forwarded-headers/15694
  4. https://blog.hlyue.com/2021/12/01/cloudflare-caddy-mutual-TLS
  5. https://developers.cloudflare.com/ssl/origin-configuration/authenticated-origin-pull