MySQL问题整理

一、MySQL的下载安装

1、进入官网MySQL地址:https://dev.mysql.com/downloads/mysql/ 以下载安装包

MySQL安装1

2、选择适合您系统的指定MySQL版本,下载安装

MySQL安装2

3、MySQL安装成功后的截图如下:

MySQL安装成功

二、终端操作MySQL的问题

1、终端 -bash: mysql: command not found

遇上-bash: mysql: command not found的情况别着急,这个是因为/usr/local/bin目录下缺失mysql导致,只需要一下方法建立软链接,即可以解决:把mysql安装目录,映射到/usr/local/bin目录下即可,即将本要链接到/usr/bin下的改链接到/usr/local/bin下就好了。命令如下:

sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin

MySQL -bash- mysql- command not found

第1节:iOS项目集成Flutter高级

[TOC]

前言

要想知道怎么去高级的进行混编,那么久需要你首先对官网的混编方式进行分析。所以,下面我们先对官网的混编方式进行分析,然后在进行正式的高级混编。

一、官网的混编方式分析

1、Podfile

1
2
3
#Flutter项目路径
flutter_application_path = "../../cj_nativeflutter_fluttermodule"
eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)

2、podhelper.rb

2.1、podhelper.rb的位置

podhelper.rb在flutter SDK中的路径为:/Applications/flutter/packages/flutter_tools/templates/module/ios/library/Flutter.tmpl

flutter_tools

Flutter SDK中的podhelper.rb

在项目中的路径为:

项目中的podhelper.rb

2.2、podhelper.rb处理的事情

podhelper.rb的内容1

事情①:获取Flutter.podspecFlutterPluginRegistrant.podspec,然后pod

获取Flutter.podspec

image-20190310171127737

获取FlutterPluginRegistrant.podspec

image-20190310171011325

情况1问题:如果engine文件夹不存在,即不存在我们需要的Flutter.podspecFlutter.framework

如果engine文件夹不存在,即不存在我们需要的Flutter.podspecFlutter.framework,则我们需要从flutter sdk中的如下目录拷贝Flutter.podspecFlutter.framework,那么Flutter SDK的根目录从哪里找呢?

/Applications/flutter/bin/cache/artifacts/engine/ios/

image-20190310174505419

情况1解决:获取flutter sdk的根目录flutter_root_dir

而这个flutter sdk目录flutter_root_dir的获取,我们只需要从根据flutter_application_path路径下的Generated.xcconfig文件中的FLUTTER_ROOT获取即可。

image-20190310181117074

获取的方法为:

1
flutter_root_dir = flutter_root(flutter_application_path)

该flutter_root函数的方法为:

podhelper.rb的内容2

Generated.xcconfig数组的获取方法为:

podhelper.rb的内容3

3、xcode_backend.sh

3.1、xcode_backend.sh的位置

xcode_backend.sh的目录为/Applications/flutter/packages/flutter_tools/bin/

Flutter SDK中的xcode_backend.sh

Ruby入门

Ruby

一、安装/升级Ruby

查看Ruby版本

1
2
% ruby -v # 或 ruby --version
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-darwin21]

安装/升级Ruby

image-20220427000442104

1
2
3
4
5
6
7
8
# 1、打开环境变量配置文件
open ~/.zshrc

# 2、在文件中添加一行以下配置
export PATH="/usr/local/opt/ruby/bin:$PATH"

# 3、让环境变量生效
source ~/.zshrc

先看Ruby参考里面对eval和binding的解释:

eval(expr[, binding[, fname[, lineno=1]]])

​ 把字符串expr当作Ruby程序来运行并返回其结果。

binding

​ 生成并返回Binding对象。该对象包含变量、方法等的环境信息,它通常用作Eval的第二参数。

Python入门

[toc]

Python正则re模块介绍

含义 语法格式
re.compile 编译正则表达式,生成一个正则表达式( Pattern )对象,供 match() 和 search() 这两个函数使用 re.compile(pattern[, flags])
re.findall 在字符串中找到正则表达式所匹配的所有子串,并返回一个列表,如果没有找到匹配的,则返回空列表。 findall(string[, pos[, endpos]])

关于

含义 示例 参数 返回值
repr() 函数将对象转化为供解释器读取的形式 repr(object) 对象 该对象的 string 格式

if else

1
2
3
4
5
6
7
8
9
10
x = 5
if x < 0:
x = 0
print('Negative changed to zero')
elif x == 0:
print('Zero')
elif x == 1:
print('Single')
else:
print('More')

Python脚本增加返回值

参考文章:

场景:打包的shell脚本中,需要加入修改文件的py脚本。在shell中要根据py脚本的处理结果进行判断。

1、实例说明

1
2
3
4
5
6
7
8
9
10
11
12
13
# py_modify_env.py
if __name__== "__main__":
findTargetLine = False

print('\n')
print('\n')
print('\n')
if findTargetLine:
print('findTargetLine = ' + "True")
sys.exit(0) # 已找到,并修改成功
else:
print('findTargetLine = ' + "False")
sys.exit(1) # 没找到,修改失败

sh文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# sc_build.sh
APPENVIRONMENT=$1 # app的打包环境

echo ""
echo ""
echo ">>>>>>>>>>>>>>> step1:begin change ProjectEnviroment to APPENVIRONMENT >>>>>>>>>>>>>>>>>>>>>>>>>>"
python py_modify_env.py ${APPENVIRONMENT}
# 特别注意:如果这里想把命令退出状态的返回值$?,赋值给一个变量(如modifyEnvPyResult),然后使用echo打印出来,
# 则因为使用了echo命令,那么此时$?的值就会变成是echo这个命令的退出状态,而不是python这个命令的退出状态了,
# 即此时判断python脚本的退出状态就不能用$?,而得用相应的变量,如${modifyEnvPyResult}
if [ $? = 0 ] # 上个命令的退出状态,或函数的返回值。
then
echo "-------- 打包环境切换到${APPENVIRONMENT}成功,继续进行 --------"
else
echo "-------- Failure:打包环境切换到${APPENVIRONMENT}失败,不再继续 --------"
echo "-------- Failure:打包环境切换到${APPENVIRONMENT}失败,不再继续 --------"
echo "-------- Failure:打包环境切换到${APPENVIRONMENT}失败,不再继续 --------"
exit_script
fi
echo "<<<<<<<<<<<<<<<< step1:end change ProjectEnviroment to APPENVIRONMENT <<<<<<<<<<<<<<<<<<<<<<<<<<<<"

终端执行的命令:

1
sh sc_build.sh Develop1

Python入门

[toc]

正则表达式示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// main.dart

import 'package:flutter/material.dart';

void main() {
debugPrint("1313");
// runApp(const MyApp());

debugPrint("--------1----------");
debugPrint(RegUtil.convert1('# abcd'));
debugPrint(RegUtil.convert1('## abcd'));
// debugPrint(RegUtil.convert1('# abcd\n## efgh'));

debugPrint("--------2----------");
debugPrint(RegUtil.convert2("# [[abcd]]"));
debugPrint(RegUtil.convert2("## [[abcd]]"));
debugPrint(RegUtil.convert2("### [[lmn]]"));

debugPrint("--------3----------");
debugPrint(RegUtil.convert3("abcd\"*lmn")); // todo

debugPrint("--------4----------");
debugPrint(RegUtil.convert4(
"Introducing ChatGPT We've trained (a model) called #ChatGPT which interacts in a (conversational way). The # dialogue format makes it possible for ChatGPT to answer followup questions, admit its mistakes, challenge incorrect premises, and reject inappropriate requests."));

debugPrint("--------5----------");
debugPrint(
RegUtil.convert5("你的好朋友\$张三\$发来⼀个地址\$https://www.google.com\$,你想要打开吗?")
.toString());
debugPrint(
RegUtil.convert5("你的好朋友\$李四\$发来⼀个地址\$http://www.google.com\$,你想要打开吗?")
.toString());
}

class RegUtil {
// convert "# abcd" to "# [[abcd]]"
// convert "## abcd" to "## [[abcd]]"
static String convert1(String text) {
final pattern = RegExp(r'^(#+) (.+)$', multiLine: true);
return pattern.allMatches(text).fold('', (result, match) {
final level = match.group(1);
final content = match.group(2)?.trim();
return '$result$level [[$content]]\n';
});
}

// convert "# [[abcd]]" to "# abcd"
// convert "## [[abcd]]" to "# abcd"
// convert "### [[lmn]]" to "# lmn
static String convert2(String text) {
final pattern = RegExp(r'^#+ \[\[(.+)\]\]$', multiLine: true);
return pattern.allMatches(text).fold('', (result, match) {
if (match.group(0) == null) {
return '';
}
// final level = '#' * match.group(0)!.indexOf(' ');
const level = '#';
final content = match.group(1);
return '$result$level $content\n';
});
}

// convert `abcd"*lmn` to `abcd'lmn.com`
static String convert3(String text) {
text = 'abcd"*lmn';

String output = text.replaceAll(RegExp('"'), "'");
output = output.replaceAll(RegExp(r'\*'), "");
output += ".com";
return output;
}

static String convert32(String input) {
RegExp pattern = RegExp(r'"\*([\w]+)');
String? output = pattern.stringMatch(input);
if (output == null) {
return input;
}
output = output.replaceAll('"', '\''); // 将双引号替换为单引号
output = output.replaceAll('*', ''); // 去掉星号
output += '.com'; // 添加 .com 后缀
return input.replaceAll(pattern, output);
}

// 输出 "a model"
// 怎么获取 trained (a model) in a (conversational way). The 中的a model,但不会获取到conversational way,用dart语言和正则。
// 即我希望获取()中的字符,但如果这些字符所在的()的前面有多个空格就不要(提取的是括号中的内容,但只想要获取前面没有多个空格的内容)
static String convert4_1(String text) {
// RegExp regex = RegExp(r'(?:\(|#)\s*(\w+(?:\s+\w+)*)\)');
// RegExp regex = RegExp(r'(?:\()\s*(\w+(?:\s+\w+)*)\)');
// Iterable<Match> matches = regex.allMatches(text);
// List<String?> results = matches.map((match) {
// final level = match.group(1);
// // final content = match.group(2)?.trim();
// return '$level';
// }).toList();

String text = "trained (a model) in a (conversational way). The";
RegExp regExp = RegExp(r"\(\s*(?<!\s{2,}).*?\s*\)");
Iterable<Match> matches = regExp.allMatches(text);
String word = "";
for (Match match in matches) {
String matchWord = match.group(0) ?? '';
word = matchWord.trim().substring(1, matchWord.length - 1);
break;
}
debugPrint(word);
return word;
}

// 输出 "ChatGPT"
// 怎么获取 The # dialogue format makes #ChatGPT it 中的ChatGPT,但不会获取到dialogue,用dart语言和正则。
// 即我希望获取#后的单词,但如果这个单词和#号之间有空格,就不要
static String convert4_2(String text) {
// String text = "The # dialogue format makes #ChatGPT it";
RegExp regExp = RegExp(r"#\s*(\w+)\b");
Iterable<Match> matches = regExp.allMatches(text);
String word = "";
for (Match match in matches) {
String matchWord = match.group(1) ?? '';
if (!matchWord.contains(" ")) {
word = matchWord;
break;
}
}
debugPrint(word);
return word;
}

// conversational way is invalid since there are more than 1 space before it, dialogure is invalid since there is a space after #
static String convert4(String text) {
// String text = "trained (a model) in a (conversational way). The # dialogue format makes #ChatGPT it";
RegExp regExp = RegExp(r"\((\s*(?<!\s{2,}).*?\s*)\)|#\s*(\w+)\b");
List<String> array = [];
Iterable<Match> matches = regExp.allMatches(text);
for (Match match in matches) {
if (match.group(1) != null) {
String model = match.group(1)!.trim();
array.add(model);
}
if (match.group(2) != null) {
String word = match.group(2) ?? '';
array.add(word);
break;
}
}

return array.toString();
}

static String convert5(String text) {
RegExp nameRegex = RegExp(r'\$(.*?)\$');
RegExp urlRegex = RegExp(r'https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+');
String? name = nameRegex.stringMatch(text)?.replaceAll('\$', '');
String? url = urlRegex.stringMatch(text);

Map<String, dynamic> friend = {"name": name, "url": url};

return friend.toString();
}
}

JS语言的实现如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>

<script>


var str = "abcd test@runoo3b.com 1234";
var patt1 = /\b[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,6}\b/g;
document.write(str.match(patt1));

function convert1(text) {
const pattern = /^(#+) (.+)$/gm;
return text.replace(pattern, function(match, p1, p2) {
const level = p1;
const content = p2.trim();
return level + ' [[' + content + ']]\n';
});
}

function convert2(text) {
const pattern = /^#+ \[\[(.+)\]\]$/gm;
return text.replace(pattern, function(match, p1) {
const level = '#';
const content = p1;
return level + ' ' + content + '\n';
});
}

function convert3(text) {
let output = text.replaceAll('"', "'");
output = output.replaceAll('\*', "");
output += ".com";
return output;
}

function convert4(text) {
const regExp = /\((\s*(?<!\s{2,}).*?\s*)\)|#\s*(\w+)\b/g;
const array = [];
let matches = text.matchAll(regExp);
for (let match of matches) {
if (match[1] !== undefined) {
let model = match[1].trim();
array.push(model);
}
if (match[2] !== undefined) {
let word = match[2];
array.push(word);
break
}
}
return array.toString();
}

function convert5(text) {
const nameRegex = /\$(.*?)\$/;
const urlRegex = /https?:\/\/(?:[-\w.]|(?:%[\da-fA-F]{2}))+/;
let name = nameRegex.exec(text)?.[1].replace(/$/g, '');
let url = urlRegex.exec(text)?.[0];
let friend = {"name": name, "url": url};
return JSON.stringify(friend);
}


document.write(convert1("# abcd"));
document.write(convert2("# [[abcd]]"));
document.write(convert3('abcd"*lmn'));
document.write(convert4("Introducing ChatGPT We've trained (a model) called #ChatGPT which interacts in a (conversational way). The # dialogue format makes it possible for ChatGPT to answer followup questions, admit its mistakes, challenge incorrect premises, and reject inappropriate requests."));
document.write(convert5("你的好朋友\$张三\$发来⼀个地址\$https://www.google.com\$,你想要打开吗?"));
</script>

</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

function convert1(text) {
const pattern = /^(#+) (.+)$/gm;
return text.replace(pattern, function(match, p1, p2) {
const level = p1;
const content = p2.trim();
return level + ' [[' + content + ']]';
});
}

function convert2(text) {
const pattern = /^#+ \[\[(.+)\]\]$/gm;
return text.replace(pattern, function(match, p1) {
const level = '#';
const content = p1;
return level + ' ' + content ;
});
}

function convert3(text) {
if (typeof text != 'string') {
return "";
}
let output = text.replace(/"/g, "'");
output = output.replace(/\*/g, "");

output += ".com";
return output;
}

function convert4(text) {
const regExp = /\((\s*(?<!\s{2,}).*?\s*)\)|#\s*(\w+)\b/g;
const array = [];
let matches = text.matchAll(regExp);
for (let match of matches) {
if (match[1] !== undefined) {
let model = match[1].trim();
array.push(model);
}
if (match[2] !== undefined) {
let word = match[2];
array.push(word);
break
}
}
return array.toString();
}

function convert5(text) {
const nameRegex = /\$(.*?)\$/;
const urlRegex = /https?:\/\/(?:[-\w.]|(?:%[\da-fA-F]{2}))+/;

let name = nameRegex.exec(text) ? nameRegex.exec(text)[1].replace(/\$/g, '') : null;
let url = urlRegex.exec(text) ? urlRegex.exec(text)[0] : null;

let friend = {"name": name, "url": url};
return JSON.stringify(friend);
}



console.log(convert1("# abcd"));
console.log(convert2("# [[abcd]]"));
console.log(convert3('abcd"*lmn'));
console.log(convert4("Introducing ChatGPT We've trained (a model) called #ChatGPT which interacts in a (conversational way). The # dialogue format makes it possible for ChatGPT to answer followup questions, admit its mistakes, challenge incorrect premises, and reject inappropriate requests."));
console.log(convert5("你的好朋友\$张三\$发来⼀个地址\$https://www.google.com\$,你想要打开吗?"));

第4节:Flutter设计模式

一、单例

参照SharedPreferences

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class SharedPreferences {
SharedPreferences._(this._preferenceCache);

static const String _prefix = 'flutter.';
static SharedPreferences _instance;
static Future<SharedPreferences> getInstance() async {
if (_instance == null) {
final Map<Object, Object> fromSystem =
await _kChannel.invokeMethod('getAll');
assert(fromSystem != null);
// Strip the flutter. prefix from the returned preferences.
final Map<String, Object> preferencesMap = <String, Object>{};
for (String key in fromSystem.keys) {
assert(key.startsWith(_prefix));
preferencesMap[key.substring(_prefix.length)] = fromSystem[key];
}
_instance = SharedPreferences._(preferencesMap);
}
return _instance;
}

创建一个单例的Manager类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Manager {
// 工厂模式
factory Manager() =>_getInstance();
static Manager get instance => _getInstance();

static Manager _instance;
Manager._internal() {
// 初始化
}
static Manager _getInstance() {
if (_instance == null) {
_instance = new Manager._internal();
}
return _instance;
}
}

调用

1
2
3
// 无论如何初始化,取到的都是同一个对象
Manager manager = new Manager();
Manager manager2 = Manager.instance;