Skip to content

Instantly share code, notes, and snippets.

@gengwg
gengwg / supercomputing-compute-io.md
Created August 23, 2025 18:04
"supercomputing is converting a compute-bound problem into an I/O-bound problem"

From Deepseek.

1. What do "Compute-Bound" and "I/O-Bound" mean?

  • Compute-Bound: A problem is compute-bound when the speed of the calculation is limited by the CPU's (or GPU's) ability to perform mathematical operations. The processors are constantly working, and the bottleneck is their processing speed. They are waiting for nothing.
  • I/O-Bound: A problem is I/O-bound (Input/Output bound) when the speed of the calculation is limited by the system's ability to read data from or write data to storage (disks, SSDs) or to transfer data between parts of the system (e.g., between nodes over a network, or between RAM and a processor). The processors are often idle, waiting for data to arrive.

2. The "Why": How Supercomputing Causes the Shift

The core idea of supercomputing is to solve a big problem faster by breaking it into smaller pieces and solving those pieces simultaneously on thousands of processors (CPUs/GPUs).

@gengwg
gengwg / roth-conversion-timing.txt
Created August 9, 2025 22:12
什么时候做Roth Conversion是最佳时机?
1.市场低迷时
原因是我们纳税的基础是做Roth Conversion时的投资品的市场价值。在市场下跌时,传统IRA帐户中的资产价值可能大幅缩水,此时转换,税务负担也会随之减少。转换后,等市场恢复,基金、股票回涨之时,资产在Roth IRA帐户的成长将完全免税。
举例说明:
假设老张的传统IRA帐户中有100,000,由于市场下跌,资产价值降至70,000。此时进行Roth Conversion,他只需为70,000缴纳所得税。若市场反弹,资产价值回升至12万,未来提领时无须再缴税。
2、收入相对低的时期
因为Roth conversion 会增加你的应税收入,可能会让你进入更高税率区间。如果你今年收入较低,整体税率较低,那就是个好时机。比如:
•失业或收入暂时减少的一年
•休假、创业初期或其他低收入阶段
$ npm install -g @anthropic-ai/claude-code
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules'
npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules'] {
npm ERR!   errno: -13,
npm ERR! code: 'EACCES',

Coroutines vs. Generators in Python

Both coroutines and generators use Python’s yield keyword, but they serve different purposes. Here’s a breakdown:


1. Generators

What?

  • A generator is a function that produces a sequence of values lazily (on-demand) using yield.
  • It pauses execution at each yield and resumes when the next value is requested (e.g., in a for loop).
@gengwg
gengwg / class_instance_attributes.md
Created July 15, 2025 17:30
p.bar() # Calls RealObject's bar method

Class Attributes vs Instance Attributes in Python

Class Attributes

  • Defined directly inside the class definition
  • Shared by all instances of the class
  • The same value is accessible from all instances
  • Changing it affects all instances

Instance Attributes

  • Defined inside methods (typically __init__)
@gengwg
gengwg / china-visa-free-travel.md
Created May 16, 2025 02:25
中国公民可以免签旅游的国家

截至2025年5月15日,中国公民可以免签旅游的国家如下:

  • 亚洲:格鲁吉亚、哈萨克斯坦、卡塔尔、马尔代夫、泰国、新加坡、亚美尼亚、乌兹别克斯坦、伊朗、马来西亚、阿曼、巴基斯坦
  • 欧洲:阿尔巴尼亚、白俄罗斯、波斯尼亚和黑塞哥维那、塞尔维亚、圣马力诺
  • 北美:安提瓜和巴布达、巴巴多斯、巴哈马、多米尼克、格林纳达
  • 南美:苏里南
  • 非洲:毛里求斯、塞舌尔、加蓬、摩洛哥、莫桑比克、突尼斯、赞比亚、安哥拉、贝宁
  • 大洋洲:斐济、汤加、所罗门群岛、密克罗尼西亚、纽埃、萨摩亚、基里巴斯
  • 加勒比:海地、圣基茨和尼维斯、圣卢西亚、牙买加
  • 其他:阿鲁巴(荷兰的一部分,但旅行时单独对待)

In Kubernetes, Deployment and StatefulSet are both controllers used to manage Pods, but they serve different purposes based on the application's requirements. Here’s a breakdown of their key differences:

1. Use Case

  • Deployment:

    • Best for stateless applications (e.g., web servers, REST APIs).
    • Pods are interchangeable (no unique identity or persistent storage).
    • Scaling up/down or rolling updates don’t require stable identities or ordered operations.
  • StatefulSet:

  • Designed for stateful applications (e.g., databases like MySQL, Kafka, Elasticsearch).

@gengwg
gengwg / gke-terraform-simple.md
Created May 12, 2025 18:45
Provision GKE Cluster on Google Cloud with Terraform.
@gengwg
gengwg / itemgetter.md
Created May 10, 2025 00:55
python itemgetter with examples.

The itemgetter function from Python's operator module creates a callable that retrieves items from objects using indices (for sequences like lists/tuples) or keys (for mappings like dictionaries). It is efficient and commonly used with functions like sorted(), max(), and min() for clean, readable code.

Importing itemgetter

from operator import itemgetter

Examples

  1. Basic Usage with a List