icmyfuture

Nothing is true, everthing is permitted

简述

本文中,将使用vuejs + webpack来搭建单页应用。采用sublimetext3充当前端开发的ID E。开发时,使用nodejs作为应用宿主。部署时,则使用nginx充当静态网页宿主。

阅读全文 »

倒序匹配获取正确区域名称

问题:有些区域直属于省,但其区域编码按层级又在市级别以下,如何正确获取这些区域的名称
方案:递归查找时,标识是否找到,若找到才倒序插入列表

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
<html>

<head>
<script type="text/javascript">
var list = [];
var data = [{
value: "51",
children: [{
value: "5101",
children: [{
value: "510104",
children: []
}]
}]
}, {
value: "61",
children: [{
value: "6101",
children: [{
value: "610101",
children: []
}]
}, {
value: "610194",
children: [{
value: "61019401",
children: []
}]
}]
}];
var selectedValue = "61019401";
var got = false;
var find = function (item) {
if (selectedValue.startsWith(item.value)) {
if(item.children && item.children.length > 0) {
for (var j = 0; j < item.children.length; j++) {
find(item.children[j])
}
}
if (selectedValue == item.value) got = true
if (got) {
list.push(item);
}
}
}
find(data);
console.log(list);
</script>
</head>

</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
private static List<dynamic> GetAreaList(List<QR_Area> areaList, int type, string code = "86")
{
var list = new List<dynamic>();
var l = areaList.Where(a => (int)a.RealAreaType == type && (a.SortCode.StartsWith(code) || code == "86") && !string.IsNullOrWhiteSpace(a.Name)).
Select(a => new {
value = a.SortCode,
label = a.Name,
children = GetAreaList(areaList, type + 1, a.SortCode)
}).ToList();

if (l.Count > 0)
{
if (code == "6101")
{
l = l.Where(a => !a.value.StartsWith("610194")).ToList();
}
list.AddRange(l);
}
else
{
list = null;
}
return list;
}

组织

构建组织

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private static dynamic ConstructContractor(List<SimpleContractor> list)
{
if (list == null || list.Count == 0) return null;
var l = list;
var top = l[0];
if (l.Count > 1)
{
l.RemoveAt(0);
var groups = l.GroupBy(c => c.C.Substring(0, top.C.Length + 4));
return new { Code = top.C, Name = top.N, Children = groups.Select(g => {
var sub = g.ToList().OrderBy(c => c.C.Length).OrderBy(c => c.C).ToList();
if (sub[0].C.Length > top.C.Length + 4) return null;
return ConstructContractor(sub);
}).Where(x => x != null).ToList() };
}
return new { Code = top.C, Name = top.N };
}

获取组织

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
private static dynamic GetContractor(dynamic contractor, string code)
{
if (contractor.Code.Equals(code)) return contractor;

if (code.StartsWith(contractor.Code))
{
if (contractor.Children != null && contractor.Children.Count > 0)
{
for (var i = 0; i < contractor.Children.Count; i++)
{
var result = GetContractor(contractor.Children[i], code);
if (result != null) return result;
}
}
}

return null;
}

找出字符串的最大深度

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
func findDepth(s string) int {
var current int = 0
var max int = 0

b := []byte(s)
for i := 0; i < len(b); i++ {
x := b[i]
if x == '(' {
current += 1
if current > max {
max = current
}
}
if x == ')' && current > 0 {
current -= 1
}
}

return max - current
}
1
2
input:  (1+2+(1*2)(1+2))
output: 3

找出序列中第K大的数

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
func getKMax(s []int, k int) int {
if k < 1 || len(s) < k {
return -1
}

//将前k个数构建最小堆
constructMinHeap(s, k)

//将k以后的数与s[0]进行比较
//若比s[0]大, 则与s[0]交换, 并自顶向下重构最小堆
for i := k; i < len(s); i++ {
if s[i] <= s[0] {
continue
}

s[0], s[i] = s[i], s[0]

x := 0
for x < k {
x = reConstructMinHeap(s, k, x)
}
}

return s[0]
}

func reConstructMinHeap(s []int, k int, current int) int {
//将current与 left=2*current+1 right=2*current+2 中最小的进行比较, 若current较大,则进行交换
left := 2*current + 1
if left < k {
minIndex := left
right := 2*current + 2
if right < k && s[right] < s[left] {
minIndex = right
}
if s[minIndex] < s[current] {
s[current], s[minIndex] = s[minIndex], s[current]
return minIndex
}
}

return k
}

func constructMinHeap(s []int, k int) {
for i := k - 1; i > 0; i = i - 2 {
parent := (i - 1) / 2
left := 2*parent + 1
right := 2*parent + 2
minIndex := left
if right < k && s[right] < s[left] {
minIndex = right
}
if s[parent] > s[minIndex] {
s[parent], s[minIndex] = s[minIndex], s[parent]
}
}
}
1
2
input:  [10,9,8,7,6,5,4,3,2,1], 3
output: 8

IDEA

官网

官方教程

推荐插件

Alibaba Cloud AI Coding Assistant
Alibaba Java Coding Guidelines/CheckStyle/SonarLint
Codeium/CodeGeex/通义灵码
DubboTest
Lombok
MybatisX
Maven Helper
Monokai Pro Theme/Material Theme UI
PlantUML integration
Rainbow Brackets
RestfulTool
Save Actions
String Manipulation
Tabnine

外部推荐列表

插件01
插件02
插件03
插件04
插件05

技巧拾遗

推荐01

Eval Reset过期无法启动IDE

删除C:\Users\****\AppData\Roaming\JetBrains\GoLand2021.2\eval中文件即可
对于mac, 其地址是~/Library/Application Support/JetBrains/GoLand2021.2/eval

licence

关闭参数提示

Rider

官网

推荐插件(旧有)

Bracket Pair Colorizer
C/C++
C#
Codeium
Extension Pack for Java
GitLens
GitHub Copilot Chat
GitHub Copilot
Go
Jupyter
Python
Qwerty Learner
Rainbow Brackets
String Manipulation
Settings Sync
Tabnine
Todo Tree
Vim

推荐插件(使用中)

Cloude Code for VS Code
Claude Sessions Explorer
Monokai Pro
One Monokai Theme

快捷键

editor.action.insertCursorAtEndOfEachLineSelected: 选中多行,添加光标至行末 shift+ctrl(win)+command(mac)+L
selectAllSearchEditorMatches: 选中文本,光标选中所有匹配文本 shift+alt+I
claudeSessionsSidebarView.focus: 显示claude session view shift+alt/command+6
showActiveFileInExplorer: 在explorer中定位当前文件 shift+alt/command+7
focusActiveEditorGroup: 切换到当前编辑器窗口 shift+alt/command+8
workbench.view.extension.claude-sidebar-secondary: 切换CC窗口 shift+alt/command+9
terminal.focus: 切换到命令行窗口 shift+alt/command+0

安装CentOS

安装VirtualBox+CentOS

  • 设备->安装增强功能
    打开目录run/media/root/VBoxAddons…,
    终端运行sh VBoxLinuxAdditions.run
    重启后就可以在”应用程序-系统工具-设置-显示”里面设置分辨率了
    阅读全文 »
0%