Morden Javascript Tutorial Chapter 2 - Fundamentals: 11~18

2.11 Logical operators There are four logical operators in JavaScript: || (ORA), && (AND), ! (NOT), ?? (Nullish Coalescing 空值合并). || OR result = a || b There are four logical combinations: alter( true || true ); // true alert( false || true ); // true alert( true || false ); // true alert( false || false ); // false If an operand is not a boolean it’s converted to be a boolean for the evaluation. if (1 || 0) { // works like (true || false) alter('truthy!'); } OR “||” finds the first truthy value result = value1 || value2 || value3 The OR || operator does the following: ...

September 21, 2025 · 22 min · 4603 words · Starslayerx

English for Programmers - 03

Unit 3. Discussing Code vocabulary - Modifiers When discussing code, modifiers can be extremely useful for making your feedback constructive and precise. modifiers: words that change the meaning of a sentence For example, a colleague asks: What do you think of the website? Response 1: It’s good When I click something it loads very quickly and I can navigate it easyily without any instructions. Response 2: It’s good! It’s very responsive and can be navigated intuitively. ...

September 20, 2025 · 2 min · 390 words · Starslayerx

Redis Bitmap

Bitmap 位图 Redis 的位图 bitmap 是由多个二进制位组成的数组, 数组中的每个二进制都有与之对应的偏移量(索引), 用户通过这些偏移量可以对位图中指定的一个或多个二进制位进行操作. Redis 为位图提供了一系列操作命令, 通过这些命令, 用户可以: 设置或获取索引位上的二进制值 统计位图中有多少个二进制位被设置成了1 查找位图中, 第一个被设置为指定值的二进制位, 并返回其偏移量 对一个或多个位图执行逻辑并、逻辑或、逻辑异或以及逻辑非运算 将指定类型的整数存储到位图中 SETBIT: 设置二进制位的值 SETBIT bitmap offset value 为位图指定偏移量上的二进制位设置值, 该命令会返回二进制位被设置之前的旧值作为结果. 当执行 SETBIT 时, 如果位图不存在, 或者位图当前的大小无法满足用户想要执行的设置操作, 那么 Redis 将对被设置的位图进行扩展, 使得位图可以满足用户的设置请求. 由于位图的扩展以字节为单位, 所以扩展后的位图包含的二进制数量可能会比用户要求的稍多一些. 且在扩展的同时, 会将未设置的二进制位初始化为 0. 与一些可以使用负数的 Redis 命令不同, SETBIT 命令只能使用正数偏移量, 尝试输入负数作为偏移量将引发一个错误 复杂度: O(1) GETBIT: 获取二进制位的值 GETBIT bitmap offset 与 SETBIT 命令一样, GETBIT 命令也只能接受正数作为偏移量. 对于偏移量超过位图索引的命令, GETBIT 命令将返回 0 作为结果. 复杂度: O(1) BITOCUNT: 统计被设置的二进制数量 BITCOUNT key 对于值为 10010100 的位图 bitmap001, 可以通过执行以下命令来统计有多少个二进制位被设置成了1: ...

September 19, 2025 · 5 min · 1009 words · Starslayerx

Redis HyperLogLog

之前曾介绍过使用 Redis 集和构建唯一计数器, 并将这个计数器用于计算网站的唯一房客 IP. 虽然使用集和实现唯一计数器可以实现该功能, 但这个方法有一个明显的缺陷: 随着被计数元素的不断增多, 唯一计数器占用的内存也会越来越大; 计数器越多, 他们的体积越大, 这一情况就会越严峻. 以计算唯一访客 IP 为例: 存储一个 IPv4 格式的 IP 地址最多需要 15 个字节 根据网站的规模不同, 每天出现的唯一 IP 可能会有数十万、数百万个 为了记录网站在不同时期的访客, 并进行相关的数据分析, 网站可能需要次序地记录每天的唯一访客 IP 数量 综上, 如果一个网站想要长时间记录访客 IP, 就必须创建多个唯一计数器. 如果访客比较多, 那么它创建的每个唯一计数器都将包含大量元素, 并因此占用相当一部分内存. 为了高效解决计算机唯一访客 IP 数量这类问题, 其中一种方法就是 HyperLogLog. HyperLogLog 简介 HyperLogLog 是一个专门为了计算集和的基数而创建的概率算法, 对于一个给定的集和, HyperLogLog 可以计算出这个集合的近似基数: 近似基数并非集和的实际基数, 它可能会比实际的基数大一点或者小一点, 但误差会在一个合理范围内. 因此, 那些不需要知道实际基数的程序就可以把这个近似基数当作集合的基数来使用. HyperLogLog 的优点在于计算近似基础所需的内存并不会因为集和的大小而改变, 无论集和包含元素有多少个, HyperLogLog 进行计算所需的内存总是固定的, 无论集和包含元素多少个, HyperLogLog 进行计算所需的内存总是固定的, 并且是非常少的. PFADD: 对集和元素进行计数 PFADD hyperloglog element [element ...] 根据给定元素是否已经进行过计数, PFADD 命令可能返回0, 也可能返回1: ...

September 18, 2025 · 3 min · 456 words · Starslayerx

Morden Javascript Tutorial Chapter 2 - Fundamentals: 06~10

2.6 Interaction: alert, prompt, confirm Will introduce alert, prompt and confirm in this chapter. alert It shows a message and waits for the user to press “OK”. alert("Hello"); prompt This function prompt accepts two arguments result = prompt(title, [default]); It shows a modal window with a text message, an input field for the visitor, and the buttons OK/Cancel. title: The text to show the visitor. default: An optional second parameter, the initial value for the input field. ...

September 17, 2025 · 15 min · 3118 words · Starslayerx

Morden Javascript Tutorial Chapter 2 - Fundamentals: 01~05

2.1 Hellow Wrold Firtly, let’s see how to attach a script to a webpage. For server-side environments (like Node.js), you can execute this script with a command like node my.js The “script” tag JavaScript programs can be inserted almost anywhere into an HTML docuemnt using the <script> tag <!DOCTYPE html> <html> <body> <p>Before this script...</p> <script> alert("Hello, World!"); </script> <p>...After the script...</p> </body> </html> The <script> tag contains JavaScript code which is automatically executed when the browser process the tag. ...

September 16, 2025 · 16 min · 3234 words · Starslayerx

Morden Javascript Tutorial Chapter 1 - An Introduction

An Introduction to JavaScript Let’s see what’s so special about JavaScript, what we can achieve with it, and what other technologies play well with it. Why is it call JavaScript? JavaScript initially called “Live Script”. But Java was popular at that time, so it was decided that positioning a new language as a “younger brother” of Java would help. But as it evolved, JavaScript became a fully independent language with its won specification called ECMAScript, and now it has no relation to Java at all. ...

September 15, 2025 · 3 min · 622 words · Starslayerx

English for Programmers - 02

Unit 2. Code Review & Testing this unit will cover: Differentiate between various testing strategies Write professional guidelines Sound more natural and smooth when asking questions Use colloquial language in speaking to give and accept feedback vocabulary - None Pharses 词汇: 名词短语 Testing 测试是软件开发中的重要短语, 用于检查软件是否达到特定的标准和用户需求. 使用这些名词语句来证明英语名词的专业性: None Desciption Example time box an allocated period of time for completing a task - allcate a 2-hour time box for regression testing stress test a method to assess a system’s performance under heavy loads - simulate 1000 users accessing the login page at the same time sanity check 健全性测试 a quick check to verify that something is as expected - are the units of the output value correct? ad hoc test 临时测试 a test performed without predefined test cases or plans - input unexpected characters into a search bar edge case a problem that only happens in extreme situations - upload an empty, 0-byte file 一些名词短语也可以当作动词使用: ...

September 12, 2025 · 4 min · 777 words · Starslayerx

English for Programmers - 01

Unit 1. Implementing Code This unit will cover: Use technical verbs to accurately define tasks and actoins Write commit messages in the corret Git format Confidently name the symbols used when writing code Understand vocabulary for syntax and programming rule vocaluary - action verbs 动词词汇 He optimised the queries to improve the response time. optimised: 提高 (improved) Can you implement the new feature we discussed yesterday? implement: 实现 (put int action) The team will integrate a third-party API to get real-time data. ...

September 11, 2025 · 3 min · 553 words · Starslayerx

The Evolution of Coding in the AI Era

文章翻译: The Evolution of Coding in the AI Era 人工智能时代的编码演变 2024 年 8 月 23 日 · Arvid Kahl 阅读时间:约 8 分钟 几年前,我还是一个完全不同的程序员。巅峰时我能轻松浏览文档并主要写出能用的代码;状态差的时候,我会为了一个笔误或古怪的 bug 折腾好几个小时,毫无结果。 那时我从来不会想到用 AI 来帮我 —— 因为它还不存在。 但现在情况变了。 我们生活在这样一个世界:不使用 AI 工具(AI tooling)来写代码的软件开发者,正逐渐变得少见。现在可用的技术要么极其便宜、要么免费,其实用性和影响力如此普遍,以至于过去五年或十年那种编程方式很可能被彻底替代。 代价也是存在的。 这种转变在生产力和速度上带来了若干好处,但也激发了很多恐惧,并暴露出值得探讨的潜在问题。 作为一个使用 AI 工具来构建软件产品的人,我想思考我们为何走上这条路径、存在哪些风险,以及如何缓解这些风险。我也想探讨,这对那些刚开始学习编程并要在一个把 AI 视为软件开发常态的世界里构建产品的人意味着什么。 AI 在编码中的力量 使用 AI 最大的明显优势很简单:它比你打字快。AI 生成代码的速度远超人类。即便是最近那些非 AI 的、高度复杂的代码编写工具,也比不上开源 AI 目前能做的速度与效率。这里所说的 AI 指的是专门以写代码为训练目标的大型语言模型(large language models,LLMs),或是通用到足以为用户生成代码的模型。像 ChatGPT、Claude 等都能写出代码,其中有些在产出能真正运行的软件方面表现更好。 作为软件创业者,我必须在解决有趣技术挑战的意愿和业务需求之间找到平衡。任何能让我更快地写出高质量、可靠代码的方法,我都必须去尝试。当第一批 AI 编码助手进入市场时,我很快就注意到它们的威力。对于有经验的开发者来说,这些工具非常有用——它们能生成我可以快速审阅并决定接受或拒绝的代码。 这就是关键:你必须懂得什么是好代码,才能批准好代码。 有经验的编程背景会让这些工具变得更有价值。你实际上是在外包“写逻辑”这一过程,而你所做的则是持续不断地进行代码审查(code review)。AI 做的一切就像给你发来一个拉取请求(pull request)供你审阅。这带来两点含义: 对有经验的开发者而言,这些工具对工作质量的影响是巨大的。 对于正在学习编程的人来说,仍然有必要理解编码的核心原理,才能有效评判 AI 给出的结果。 学习曲线与 AI 这是我看到人们最关心的核心问题:如果你靠 AI 学编程,你可能永远不会真正理解那些你需要用来评判代码的解决方案。你需要知道“配方”的原材料和工作原理,才能下厨;否则你只是把食物弄坏。对代码也是如此——你需要理解语法、语义、求值和执行的过程。 ...

September 11, 2025 · 1 min · 192 words · Starslayerx