「C」- Scope, Linkage, Storage Duration, Storage Class

问题描述
该笔记是《C Primer Plus, 中文版, 第 6 版》/ 第 12 章 存储类别、链接和内存管理(Page 373)的学习笔记。
Scope
Scope,作用域:定义变量的作用范围;
Block Scope
Block Scope,块作用域: 1)该类型的作用域是 从定义处开始 到 包含该定义的块的末尾; 2)另外,虽然形式参数声明在函数的左花括号({)之前,但是它们也是块作用域;
形态:

double blocky(double cleo) {
double patrick = 0.0; // 仅当前块内能够访问,且仅在该声明之后

return patrick;
}

Function Scope
Function Scope,函数作用域: 1)仅用于 goto 语句的标签,即:对于在函数内的标签,其作用域直接延伸到整个函数;
形态:

int main() {

for (i = 1; i <= 5; ++i) {
if (i > 4)
goto jump;
}

jump: // 该函数的任何位置都能访问该
printf(“end”);
return 0;
}

Function Prototype Scope
Function Prototype Scope,函数原型作用域: 1)该类型的作用域是 从形参定义处 到 原型声明结束;
File Scope
File Scope,文件作用域: 1)该类型的作用域是 从定义开始 到 文件末尾 均可见;
Linkage
Linkage(链接)是对 File Scope 的进一步定义,分为:
External Linkage
External Linkage(外部链接):能够在多文件程序中使用,即能够被其他源文件引用;
Internal Linkage
Internal Linkage(内部链接):仅在当前 Translation Unit 内部可见(当前文件可见);
No Linkage
No Linkage(无链接):即仅能块内部使用;例如 Function Scope、Block Scope 等等都属于 No Linkage 类型;
Storage Duration
Storage Duration(存储期),描述被访问对象(变量)的生存期,分为
Static Storage Duration
Static Storage Duration,静态存[……]

READ MORE

「C」- 开发环境搭建

on Ubuntu 20.04 LTS

# for Ubuntu
apt-get install gcc eclipse build-essential[……]

READ MORE

「C」- 快速开始

简单程序示例

#include <stdio.h>

int main(void) {
int num;
num = 1;

printf(“I am a simple “);
printf(“computer.\n”);
printf(“My favorite number is %d because it is first.\n”, num);

return 0;
}

进一步的使用

#include <stdio.h>

void butler(void); // 函数原型

int main(void) {
printf(“I will summon the butler fucntion.\n”);
butler(); // 函数调用
printf(“Bring me some tea and writeable DVDs.\n”);

return 0;
}

void butler() { // 函数定义
printf(“You rang, sir?\n”);
}

06、循环控制
while
11、[……]

READ MORE

「C」- 数据类型

数据类型的关键字

K&R C90 C99
—————————————
int signed _Bool
long void _Complex
short _Imaginary
unsigned
char
float
double

int:整数类型; long、short、unsigned、signed:提供基本整数类型的变形:unsigned long int、long long int; char:字母、字符、较小的整数; float、double:带小数点的数;long double; _Bool:布尔值 ⇒ C99 _Complex:复数; _Imaginary:虚数;
浮点类型: 在计算机内,浮点数被分为 小数部分 和 指数部分 来表示,并分开存储这两部分,使用二进制和 2 的幂进行存储。
int,有符号整型

// 声明
int erns;
int hogs, cows, goats;

// 赋值
cows = 5;
goats = 0x20; // 十六进制赋值,0x20 = 32
erns = 020; // 八进制赋值,020 = 16
scanf(“%d”, &hogs);
int hen, dogs = 3; // 变量初始化能够在声明中直接完成
// 但是,这里仅初始化 dogs 变量

// 打印
printf(“%d”, dogs); // 打印整数
// %d, %o, %x:分别以 十进制,八进制,十六进制 打印;
// %#o, %#x, %#X:添加 0、0x、0X 的八进制或十六进制前缀;

其他整数类型: 1)short int 2)long int / long 3)long long int / long long ⇒ C99 4)unsigned int / unsigned 5)unsigned long int / unsigned long / unsigned int / unsigned short ⇒ C90 6)unsigned long long int / unsigned long long ⇒ C99 7)signed,用于强调使用有符号类型;
整数类型的大小取决于编译器(鉴于 C 标准只规定最小大小): 1)int:2 Byte 或 4 Byte;[……]

READ MORE

「C」- struct,结构

结构声明(Struct Declaration)
Struct Declaration(结构声明),即描述 struct 的组织布局。

struct book {
char title[MAXTITLE];
char author[MAXAUTL];
float value;
}

结构变量(Struct Variable)
Struct Variable(结构变量),即使用某个 struct 类型的变量。
变量定义

struct book my_library;
struct book my_dickens;
struct book * my_ptbook;

// 直接定义并使用

struct book {
char title[MAXTITLE];
char author[MAXAUTL];
float value;
} my_ptbook;

struct { // 省略 struct 的标记 —— book
char title[MAXTITLE];
char author[MAXAUTL];
float value;
} my_ptbook;

变量初始化

struct book my_ptbook = {
“Computer Sicence”,
“John”,
12.3
};
struct book your_ptbook = my_ptbook; //

// 注意事项:
// 1)对于 Static Storage Duration 的 struct 初始化,必须使用常量;
// 2)对于 Automatic Storage Duration 的 struct 初始化,必须使用常量;

// —————————————————————————–

struct book my_ptbook = {
.value = 15.4,
.author = “Tom”,
13.2
}

// 补充说明:
// 1)根据需要来初始化变量,这是 C99 C11 新增特性(designated initializer);
// 2)最后 .value 的值为 13.2,因为其紧随 .author 之后;

成员访问

my_ptbook.title
s_get(my_ptbook.author)
scanf(“%f”, &my_ptbook.value) // & 优先级高于 .

结构数组(Struct Arra[……]

READ MORE

「C」- 库、构建工具

Gprof,性能分析工具 访问Gprof维基百科主页[……]

READ MORE

「GNU C Library」- GNU 的 C 库

glibc vs. libc6
What’s the difference between glibc and libc6?
libc6 and glibc are the same version of libc; officially, it’s version 2 of the GNU C Library (but it’s the sixth major version of the Linux C library). You can read more about glibc at the GNU C Library pages.
libc6: Version 6 of the Linux C Library is version 2 of the GNU C Library; the confusion is because Linux has had multiple C library versions. This is the newest technology available, and includes features (like “weak symbols”) that theoretically allow new functions and modified structures in the library without breaking existing code that uses version 6, and avoid kernel version dependency problems. You should be coding and compiling all code against this version.
从发行版的源中安装
使用源码编译安装
参考LFS/Glibc-2.24: http://www.linuxfromscratch.org/lfs/view/7.10/chapter06/glibc.html
安装的二进制程序
catchsegv Can be used to create a stack trace when a program terminates with a segmentation fault
gencat Generates message catalogues
getconf Displays the system configuration values for file system specific variables
getent Gets entries from an administrative database
iconv 用于进行字符集的转换。
iconvconfi[……]

READ MORE

「C」- 框架、模板

[……]

READ MORE

「Emacs Lisp」- a dialect of the Lisp

Lisp – List Processing
Lisp,是种到处都是括号的语言,被戏称为 Lots of Isolated Silly Parentheses,它拥有各种方言(如下截图),而我们要学习的是 Emacs Lisp 方言。

Emacs Lisp
https://www.gnu.org/software/emacs/manual/html_node/eintr/index.html https://www.gnu.org/software/emacs/manual/html_node/emacs/index.html https://www.gnu.org/software/emacs/manual/html_node/elisp/index.html https://github.com/emacs-helm/helm
Common Lisp
http://www.clisp.org/ https://common-lisp.net/project/slime/ https://common-lisp.net/
参考文献
Wikipedia / LISP[……]

READ MORE

「Emacs Lisp」- 环境搭建

因为我们使用 GNU Emacs 编辑器所以才学习 Emacs Lisp 语言,而搭建运行环境只需要安装 Emacs 编辑器即可:[……]

READ MORE

「Emacs Lisp」- 语法(学习笔记)

定义变量,并为其赋值
如下定义 flower 的值为列表(List),其中包含 rose violet daisy 三个值:

(set ‘flower ‘(rose violet daisy))

或者使用 setq 定义变量:

(setq flower ‘(rose violet daisy))

;; 此外 setq 支持为多个变量赋值
(setq flower ‘(rose violet daisy)
herbivores ‘(deer sawfly))[……]

READ MORE

「Emacs Lisp」- 常用函数(学习笔记)

car、cdr
https://www.gnu.org/software/emacs/manual/html_node/eintr/car-_0026-cdr.html#car-_0026-cdr%20
car:返回列表的第一个元素:(car ‘(rose violet daisy buttercup)) => rose
cdr:返回列表的第一个元素后面的元素:(cdr ‘(rose violet daisy buttercup)) => (violet daisy buttercup)
cons
https://www.gnu.org/software/emacs/manual/html_node/eintr/cons.html#cons%20
cons:构建列表:(cons ‘pine ‘(fir oak maple)) => (pine fir oak maple)
dolist
https://www.gnu.org/software/emacs/manual/html_node/eintr/dolist.html%20
(dolist (element list) body…):循环地将 list 的首个元素赋值到 element,并移除该首个元素[……]

READ MORE

「Emacs Lisp」- 调试(学习编辑)

问题描述
在我们刚入行的时候,唯一的调试方式就是打印输出调试,echo printf message,各种打印,从来没使用过调试器,一直觉得调试器很难搞。现在想想,多半是因为当时的我们不愿意接受新事物吧,或者不想学习新东西。
后来代码越来越复杂,打印调试变得不再可行,调试器成为最佳方法。再后来,我们也越来越喜欢使用调试器。当然,有时候只是为了查看某个值,也没有必要使用调试器。
该笔记将记录:在 Emcas Lisp 中,如果使用 GNU Emacs 进行调试的各种方法,以及常见问题处理。
解决方案
debug-on-entry
适用范围: 1)该方法比较初级,适用于简单调试单个函数; 2)如果函数调用栈较深,不适合使用该方法;
进入调试: 1)使用 M-x debug-on-entry [RET] <function name> [RET] 启用; 2)在代码中,当调用 <function name> 函数时,进入该函数的调试模式; 2)调试信息(栈信息),将显示在 *Backtrace* 缓冲区,可以观察调用栈;
调试方法: 1)当进入调试模式后,在 *Backtrace* 中,按下 d 键进行逐步调试,每次执行一个表达式求值。 2)在 *Backtrace* 中,按下 q 键退出函数调试。
关闭调试: 1)如果要关闭函数调试,通过 M-x cancel-debug-on-entry [RET] <function name> [RET] 关闭。
debug-on-error
适用范围: 1)在出现错误时,进入错误函数的调试模式; 2)该方法不能选择函数;
进入调试: 1)M-x set-variable [RET] debug-on-error [RET] t 2)在下次遇到错误时,进入调试模式,调试信将显示在 *Backtrace* 缓冲区。
调试方法: 1)与 debug-on-entry 想法
关闭调试: 1)M-x set-variable [RET] debug-on-error [RET] nil
补充说明: 使用 M-x toggle-debug-on-error 功能,进行 debug-on-error 切换,而无需设置该变量。
debug-on-quit
适用范围: 1)该方式的特征是:在按下 C-g 时进入调试模式,用于调试死循环;
进入调试: 1)M-x toggle-debug-on-quit,或者 M-x set-variable [RET] debug-on-quit [RET] t 2)在启用后,任何时刻按下 C-g 都可以进入调试。
关闭调试: 1)M-x[……]

READ MORE

「Emacs」- 4.Packages and Build Tools

Url Package
EmacsWiki: Url Package
(setq defcustom url-debug t) => *URL-DEBUG*
如果需要查看请求数据,需要使用代理服务:

(setq url-proxy-services ‘((“http” . “localhost:8888”)))[……]

READ MORE

「Expect」

expect
Linux expect 详解
让 Expect 代替我们与交互式程序进行交互:

#!/usr/tcl/bin/expect

set timeout 30
set host “101.200.241.109”
set username “root”
set password “123456”

spawn ssh $username@$host
expect “*password*” {send “$password\r”}
interact

EXPECT,Homepage[……]

READ MORE

「GTK」- GIMP Toolkit

相关链接
The Python GTK+ 3 Tutorial — Python GTK+ 3 Tutorial 3.4 documentation
使用 TextView 编写编辑器的示例:TextView (Python)

章节列表
「GTK+3 」- 在 TextView 中,插入图片(学习笔记)[……]

READ MORE

「GTK+3 」- 在 TextView 中,插入图片(学习笔记)

问题描述
该笔记将记录:在 GTK+ 3 中,如何使用 Pixbuf 向在 TextView 中插入图片
解决方案
使用 Python 实现

import gi
gi.require_version(“Gtk”, “3.0”)
from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf
import gi.repository.GdkPixbuf

class PluginInsertedObjectAnchor(Gtk.TextChildAnchor):

def create_widget(self):
return Gtk.Image.new_from_file(“/usr/local/share/icons/d3rm/24×24-010editor.png”)

def dump(self, builder):
attrib, data = self.objecttype.data_from_model(self.objectmodel)
builder.start(OBJECT, dict(attrib)) # dict() because ElementTree doesn’t like ConfigDict
if data is not None:
builder.data(data)
builder.end(OBJECT)

class EditWindow(Gtk.Window):
def __init__(self):
# 创建 Window 控件
Gtk.Window.__init__(self)
self.set_default_size(200, 200)
# 创建 TextView 控件
textview = Gtk.TextView()
textbuffer = textview.get_buffer()

# 插入位置
iter = textbuffer.get_iter_at_mark(textbuffer.get_insert())

# 方法一、通过 Pixbuf 将图片插入 TextView 的 TextBuffer 中
pixbuf = Pixbuf.new_from_file(“/usr/local/share/icons/d3rm/24×24-010editor.png”)
textbuffer.insert_pixbuf(iter, pixbuf)

# 方法二、通过 Anchor 插入
anchor = textbuffer.create_child_anchor(iter)
image = Gtk.Image[……]

READ MORE

「Go」

设置 go get 路径
SettingGOPATH · golang/go Wiki · GitHub

export GOPATH=/usr/local

下载国外模块的方法(SOCKS5)
How to: go get through socks5 proxy

# 初始设置
git config –global http.proxy socks5://127.0.0.1:1080
export http_proxy=socks5://127.0.0.1:1080

# 执行某些命令

# 还原设置
git config –global –unset http.proxy
unset http_proxy[……]

READ MORE

「Go」- Template

问题描述
现在(04/27/2021)很多使用 Golang 开发的工具或服务都使用 Go templating 来进行页面的渲染(或者输出文本控制)。即使我们不是 Golang 开发者,我们也需要学习部分相关内容,毕竟工作需要嘛,而且想单凭一种编程语言就成为技术高手那是基本不可能的,谁还不会个三门五门编程语言呢:-)
我们 Alertmanager 的告警消息便是使用 Go templating 进行渲染,然后再进行发送。Alertmanager 也是我们学习 Go templating 的原因。再比如 kubectl 命令也支持使用 Go templating 进行输出的控制。所以即使不学习 Golang 进行编程,也要学习 Go templating 的使用方法,然后有一天误入歧途开始学习 Golang 编程。
该笔记将记录:在 Golang 中,Template 的使用方法,以及相关问题的处理。
解决方案
该笔记是对官方文档**重点内容**的学习整理,旨在形成对 Go templating 作用及使用的整体认识。详细内容及使用细节,参考 template – The Go Programming Language 文档。
参考文献
template – The Go Programming Language[……]

READ MORE

「Groovy」- 彩色化输出日志

问题描述
在执行 Groovy 脚本时,我们希望可以彩色化输出日志,以进行提醒、区分不同的信息。比如,错误信息显示为红色,警告信息显示为黄色,成功信息显示为绿色,普通信息显示为正常颜色。
该笔记将记录:在 Groovy 中,如何使用 ANSI Color 转义序列,来控制日志输出颜色。
解决方案
方案一、直接使用转义序列

def ANSI_RESET = “\u001B[0m”;
def ANSI_BLACK = “\u001B[30m”;
def ANSI_RED = “\u001B[31m”;
def ANSI_GREEN = “\u001B[32m”;
def ANSI_YELLOW = “\u001B[33m”;
def ANSI_BLUE = “\u001B[34m”;
def ANSI_PURPLE = “\u001B[35m”;
def ANSI_CYAN = “\u001B[36m”;
def ANSI_WHITE = “\u001B[37m”;

println “${ANSI_GREEN}GREEN COLORED${ANSI_RESET}NORMAL”

方案二、使用第三方的类库

@Grapes([
@GrabResolver(name=’aliyun’, root=’https://maven.aliyun.com/repository/central’, m2Compatible=’true’),
@Grab(group=’com.pi4j’, module=’pi4j-core’, version=’1.3′)
])

import com.pi4j.util.ConsoleColor

println “${ConsoleColor.RED}RED COLORED${ConsoleColor.RESET}NORMAL”

参考文献
java – How to print color in console using System.out.println? – Stack Overflow The Pi4J Project – Home[……]

READ MORE

「Apache Groovy」- 连接 SQLite 数据库

问题描述
在 Groovy 中,我们需要连接 SQLite 数据库,以进行某些简单的数据存取操作。
该笔记将记录:在 Groovy 中,如何连接数据库。
解决方案
我们依旧使用 JDBC 连接数据库,所以与 Java 的用法是类似的(存在的问题也多半相仿),只是函数调用不同。

@Grapes([
@Grab(group=’org.xerial’,module=’sqlite-jdbc’,version=’3.7.2′),
@GrabConfig(systemClassLoader=true)
])

import java.sql.*
import org.sqlite.SQLite
import groovy.sql.Sql

def sql = Sql.newInstance(“jdbc:sqlite:/path/to/sample.db”, “org.sqlite.JDBC”)

// 创建表
sql.execute(“drop table if exists person”)
sql.execute(“create table person (id integer, name string)”)

def people = sql.dataSet(“person”)
people.add(id:1, name:”leo”)
people.add(id:2,name:’yui’)

sql.eachRow(“select * from person”) {
println(“id=${it.id}, name= ${it.name}”)
}

参考文献
Use Groovy language JDBC with SQLite database – T. C. Mits 108[……]

READ MORE

「Groovy」- 常用 JSON 操作(Object 与 JSON)

问题描述
该笔记将记录:在 Groovy 中,常用 JSON 操作,以及相关问题处理。
解决方案
Object 转为 JSON
如下代码,可以将对象(List、Map)转化为 Json String:

import groovy.json.JsonOutput

println JsonOutput.toJson(dataObject)

但是,如果数据中包含 Unicode 字符,则 toJson() 将对其进行转义。如下示例以及解决方法:

import groovy.json.JsonOutput
import groovy.json.JsonGenerator.Options

def mapWithUnicode = [key : “好”]

println JsonOutput.toJson(mapWithUnicode)
// {“key”:”\u597d”}

println new Options().disableUnicodeEscaping().build().toJson(mapWithUnicode)
// {“key”:”好”}

在 Jenkins Pipeline 中,使用 JsonGenerator.Options 会提示 unable to resolve class groovy.json.JsonGenerator.Options 错误,因为 Jenkins Pipeline 使用 Groovy 2.4 版本(09/16/2020 Jenkins 2.241)。为了解决该问题,我们需要求助于第三方类库,比如 Gson 库:

@Grab(group=’com.google.code.gson’, module=’gson’, version=’2.8.2′)
import com.google.gson.Gson

println new Gson().toJson([key : “好”])
// {“key”:”好”}

解析 JSON 字符串(JSON 转为 Object)

import groovy.json.JsonSlurperClassic

return new JsonSlurperClassic().parseText(jsonString)

常见问题处理
判断返回类型
假如远程 HTTP API 返回 JSON Array([]) 但是在错误时返回 JSON OBJECT({}),这就需要我们判断返回类型:

import groovy.json.JsonSlurperClassic

def object = new JsonSlurper().parseT[……]

READ MORE

「Groovy」- 处理路径地址

问题描述
在 Jenkins Pipeline 中,我们需要使用路径,比如拼装、替换、判断等等。但是大家对于路径书写习惯不同,比如当前目录是否会使用 ./ 前缀,目录结尾是否会使用 / 后缀。这些不同书写习惯会影响路径处理,比如比较、判断、截取等等。
该笔记将介绍处理路径的 Path、Paths 类库,以解决路径书写风格迥异的问题。
相关文档
Java SE 7/java.nio.file.Paths Java SE 7/Interface Path
使用方法

import java.nio.file.Paths

// 加载并格式化路径
def p = Paths.get(“./note/demo/f.txt”).normalize()
println p.toString() // => note/demo/f.txt
println Paths.get(“./note/demo/”).normalize().toString() // => note/demo

// 判断路径是否以 XXXXX 开始
println p.startsWith(Paths.get(“./././././note”).normalize())

// 获取父级路径
println p.getParent() // 去除最后部分的路径 note/demo

// 获取文件名,即路径最后部分
println p.getFileName().toString() // => f.txt

参考文献
How to split a path platform independent? Java SE 7/java.nio.file.Paths Java SE 7/Interface Path[……]

READ MORE

「Apache Groovy」- 编写 retry 函数

问题描述
在 Jenkins Pipeline 中,通过 retry 函数,能够对某个操作重复进行,直到成功。尤其是在网络请求中,我们更应该使用 retry 函数,以防止服务器负载过高而产生的临时失败。
但是,Jenkins Pipeline 的执行速度“较慢”(这是 Jenkins 的优化,防治对服务器产生过大压力),并且会大量产生 Pipeline Step 执行日志,因此我们希望通过 Groovy 实现 retry 函数,并加入一些特性。
该笔记将记录:在 Apache Groovy 中,如何实现自定义的 retry 函数,以及相关问题处理。
解决方案
代码 retry() 示例

def retry(int times = 5, Closure errorHandler = {e-> e.printStackTrace()}, Closure body) {
int retries = -1
while(times < 0 || ++retries <= times) {
try {
return body.call()
} catch(e) {
errorHandler.call(e)
}
}
throw new Exception(“Failed after $times retries!”)
}

这里的代码也许写的比较罗嗦,我们是为了赋予三个区间含义: 1)如果重试次数小于零,将无限重试; 2)如果重试次数等于零,将执行一次(而不重试)。 3)如果重试次数大于零,将执行 times + 1 次(即重试 times 次)
使用示例

retry(3) {
errorProneOperation()
}

retry(2, {e-> e.printStackTrace()}) {
errorProneOperation()
}

参考文献
java – Retry after Exception in Groovy – Stack Overflow Pipeline: Basic Steps/retry[……]

READ MORE

「Apache Groovy」- java.lang.NoSuchMethodError: x.x.x: method ()V not found

问题描述
在执行 Groovy 代码中,产生如下错误:

ava.lang.NoSuchMethodError: com.lispstudio.model.TeamLispstudio: method <init>()V not found

问题原因
在继承父类之后,没调用父类的构造函数。
解决方法
有两种解决方法:1)调用与父类相同的构造函数;2)使用 InheritConstructors 注解;
调用与父类相同的构造函数

class Creature {
Creature (String feature) {}
}

class Humman extends Creature{
Humman (String feature) {
super(feature)
}
}

new Humman(“legs”)

使用 InheritConstructors 注解

class Creature {
Creature (String feature) {}
}

@groovy.transform.InheritConstructors
class Humman extends Creature{
}

new Humman(“legs”)

参考文献
<init>()V not found when defining superclass constructor InheritConstructors (groovy 2.4.9 API)[……]

READ MORE

「JSON」- JavaScript Object Notation

[……]

READ MORE

「NVM」- 管理多种版本 Node.js 环境

问题描述
NVM,Node Version Manager,用于在系统中安装并管理多个版本 Node.js 环境,并能够自如切换。
该笔记将记录:在 Linux 中,如何安装 NVM 工具,以及管理安装并管理多个版本 Node.js 环境的方法。
解决方案
第一步、安装 nvm 工具(Linux)
Debian GNU/Linux 10 (buster) and Bash:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash

cat >> ~/.bashrc <<EOF

export NVM_DIR=”$([ -z “${XDG_CONFIG_HOME-}” ] && printf %s “${HOME}/.nvm” || printf %s “${XDG_CONFIG_HOME}/nvm”)”
[ -s “$NVM_DIR/nvm.sh” ] && \. “$NVM_DIR/nvm.sh” # This loads nvm
EOF

第二步、使用 nvm 安装 Node.js 环境
查看可用 Node.js 的全部版本:

# nvm ls-remote

// 查看所有可用的 13 版本

# nvm list-remote v13.10
v13.10.0
v13.10.1

安装 Node.js 环境:

# nvm install v13.10.1 # 安装 v13.10.1 版本
Downloading and installing node v13.10.1…
Downloading https://nodejs.org/dist/v13.10.1/node-v13.10.1-linux-x64.tar.xz…
################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v13.10.1 (npm v6.13.7)

# nvm install[……]

READ MORE

「JavaScript」- 语法学习

解决方案
for / forEach / for..of

// for

for (var b; b = a.pop(); ) { // for 循环的特殊用法
do_sth(b);
}

// forEach

[].forEach(function (item, index) {
console.log(index + ” ” + item)
});

[].forEach(function (item, index) {
it => console.log(it)
});

[].forEach(element => {
// do some stuff
});

// for…of => does use an object-specific iterator and loops over the values generated by that.

const array1 = [‘a’, ‘b’, ‘c’];
for (const element of array1) {
console.log(element);
}

// for…in => loops over enumerable property names of an object.

const object = { a: 1, b: 2, c: 3 };
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}

async…await
async function – JavaScript | MDN javascript – Using async/await with a forEach loop – Stack Overflow
通过 async 定义的函数,允许异步执行,而对该函数的调用使用 await 能够等待该异步函数执行结束。

function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve(‘resolved’);
}, 2000);
});
}

async function asyncCall() {
console.log(‘calling’);
const result = await resolveAfter2Seconds();
console.log(result);
// expected output: “resolved”
}

asyncCall();[……]

READ MORE

「JavaScript」- 数据类型

问题描述
该笔记将记录:在 JavaScript 中,八大基本数据类型。
解决方案
String
用于表示文本数据。
例如:’hello’, “hello world!”
Number
整数或者浮点数
例如:3, 3.234, 3e-2
BigInt
任意精度的整数
例如:900719925124740999n, 1n
Boolean
true 或 false 之一
例如:true,false
undefined
变量值为定义的数据类型
例如:let a;
null
赋予 null 值
例如:let a = null;
Symbol
实例是唯一且不变的数据类型
例如:let value = Symbol(‘hello’);
Object
数据集合的键值对
例如:let student = { };
注意事项
除了 Object 类型,其他皆为原始类型(Primitive Type)
参考文献
JavaScript Array length Property JavaScript Data Types (with Examples)[……]

READ MORE

「JavaScript」- Array(数组)

问题描述
该笔记将记录:在 JavaScript 中,与数组 Array 有关的操作,以及相关问题处理。
解决方案
Array 并不是基本数据类型,它派生自 Object 类型
计算数组长度:

var fruits = [“Banana”, “Orange”, “Apple”, “Mango”];
fruits.length;

参考文献
JavaScript Array length Property Array is not a data type in Javascript? – Stack Overflow[……]

READ MORE