Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
spaceack committed Aug 25, 2024
1 parent 3335e8f commit 20ccda2
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 40 deletions.
1 change: 1 addition & 0 deletions content/links/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ date: 2019-11-28 00:19:01
|[嘻嘻琦琦 Vickey’s Blog](https://vickey.fun/)|nginx, 云主机,https||
|[Jason's Blog](https://890214.net)|AI知识&工具分享||
|[小谷的编程随笔空间](https://gu.ink/)|小谷的编程随笔空间||
|[凡梦星尘空间站](https://lisenhui.cn)||再平凡的人也有属于他的梦想!|
## 网址导航

### 常用网站导航
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ tags:
- 示例 1:
```
输入:[2,7,4,1,8,1]
输出:1
解释:
先选出 7 和 8,得到 1,所以数组转换为 [2,4,1,1,1],
再选出 2 和 4,得到 2,所以数组转换为 [2,1,1,1],
接着是 2 和 1,得到 1,所以数组转换为 [1,1,1],
最后选出 1 和 1,得到 0,最终数组转换为 [1],这就是最后剩下那块石头的重量。
输出:1
解释:
先选出 7 和 8,得到 1,所以数组转换为 [2,4,1,1,1],
再选出 2 和 4,得到 2,所以数组转换为 [2,1,1,1],
接着是 2 和 1,得到 1,所以数组转换为 [1,1,1],
最后选出 1 和 1,得到 0,最终数组转换为 [1],这就是最后剩下那块石头的重量。
```
## 提示:
1. 1 <= stones.length <= 30
Expand All @@ -50,34 +50,34 @@ tags:
执行用时:44 ms, 在所有 Python3 提交中击败了42.77%的用户
内存消耗:14.8 MB, 在所有 Python3 提交中击败了38.92%的用户
```python
import heapq
class Solution:
def top_two(self, stones):
result = heapq.nlargest(2, stones)
return max(result), min(result)
def lastStoneWeight(self, stones: List[int]) -> int:
if len(stones) == 0:
return 0
elif len(stones) == 1:
return stones[0]
elif len(stones) > 1:
max, min = self.top_two(stones)
if max == min:
stones.remove(max)
stones.remove(min)
if len(stones) == 1:
return stones[0]
elif len(stones) > 1:
return self.lastStoneWeight(stones)
elif len(stones) == 0:
return 0
else:
stones.append(max-min)
stones.remove(max)
stones.remove(min)
if len(stones) == 1:
return stones[0]
return self.lastStoneWeight(stones)
```
```python
import heapq
class Solution:
def top_two(self, stones):
result = heapq.nlargest(2, stones)
return max(result), min(result)
def lastStoneWeight(self, stones: List[int]) -> int:
if len(stones) == 0:
return 0
elif len(stones) == 1:
return stones[0]
elif len(stones) > 1:
max, min = self.top_two(stones)
if max == min:
stones.remove(max)
stones.remove(min)
if len(stones) == 1:
return stones[0]
elif len(stones) > 1:
return self.lastStoneWeight(stones)
elif len(stones) == 0:
return 0
else:
stones.append(max-min)
stones.remove(max)
stones.remove(min)
if len(stones) == 1:
return stones[0]
return self.lastStoneWeight(stones)
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Co-350-两个数组的交集 II
title: Check same case
date: 2022-04-10 23:01:18
update: 2022-04-10 23:01:18
author: Spaceack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH

# env maven
export MAVEN_HOME=/opt/maven
export PATH=$MAVEN_HOME/bin:$PATH

# env golang
export GOROOT=/opt/go
export GOPATH=~/golib:~/goproject/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,64 @@ tags:
### 验证

#### 验证程序

由于安装程序可能很快完成,来不及看到锁文件。所以我们可以快速实现一个简易的验证程序:

```python
import os
import shutil
import time
import subprocess
def runcmd(command):
ret = subprocess.run(command, shell=True, timeout=60, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8")
if ret.returncode == 0:
return ret.stdout
else:
print(str(ret))

def check_dnf_lock_pid():
"""若进程锁文件存在,有其它正在执行的安装程序, 返回其它进程信息 或 True; 否则返回 None
早期系统 yum 包安装程序通过 '/var/run/yum.pid' 判断。
新系统 dnf 包安装程序通过以下4个进程锁文件判断。
"/var/cache/dnf/download_lock.pid",
"/var/cache/dnf/metadata_lock.pid",
"/var/lib/dnf/rpmdb_lock.pid",
"/var/log/log_lock.pid",
"""
lock_pid_path = [
"/var/cache/dnf/download_lock.pid",
"/var/cache/dnf/metadata_lock.pid",
"/var/lib/dnf/rpmdb_lock.pid",
"/var/log/log_lock.pid",
"/var/run/yum.pid",
"/var/lib/rpm/.rpm.lock",
]
for pid_path in lock_pid_path:
if os.path.exists(pid_path):
if "pid" in pid_path:
cat_command = "cat %s" % (pid_path)
pid = runcmd(cat_command)
pid = pid.replace("\n","") if pid else None
if ".rpm.lock" in pid_path:
fuser_command = "fuser %s" % (pid_path)
pid = runcmd(fuser_command)
if isinstance(pid, str):
pid = pid.replace(" ", "").replace("\n", "") if pid else None
else:
pid = pid.stdout.decode("utf-8").replace(" ", "").replace("\n", "") if pid else None
if pid and pid.isdigit():
run_time_c = "ps -p %s -o etimes=|awk '{print $1}'" % (pid)
run_time = runcmd(run_time_c)
run_time = run_time.replace("\n","") if run_time else None
if pid and run_time and pid.isdigit() and run_time.isdigit():
return "当前安前程序进程%s正在执行,已运行%s秒,请等待结束后再尝试。等待进程%s" % (pid, run_time, pid_path,)
if pid and pid.isdigit():
return "当前安装程序进程%s正在执行,请等待结束后再尝试。等待进程%s" % (pid, pid_path,)
while True:
c = check_dnf_lock_pid()
print(c)
```

#### 山穷水尽疑无路

但很遗憾,并没有发现这个锁程序。
Expand Down
17 changes: 15 additions & 2 deletions content/posts/计算机技术/python/flask/20220330-Flask笔记.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ tags:
ISBN: 9787111606598

## 基本概念

### 路由

按某路线发送,路由是一个简单的URL,它指向一个视图函数。

### 注册路由 route

设置URL规则,建立URL和函数间的映射关系。这个函数被称为视图函数(view function)
代码层面是被装饰器 `app.route('/')` 装饰的函数。

Expand All @@ -24,22 +27,26 @@ ISBN: 9787111606598
URL(Uniform Resource Lacator,统一资源定位符)

#### 相对URL(内部URL)

不包含域名的URL,如:/user/lucky
可以绑定多个URL

#### 动态URL

#### 带有默认值的URL

避免404

### flask shell

自动包含关于flask的上下文,可以直接在命令行中使用flask提供的功能
app.name

在视图函数加 `app.cli.command('xxx')`装饰器,可以将命令添加到命令行,方便调试。
flask xxx 执行

### MVC

MVC(Model-View-Controller,模型-视图-控制器)
程序被分为三个组件:

Expand All @@ -54,6 +61,7 @@ MVC(Model-View-Controller,模型-视图-控制器)
模型 - SQLAlchemy

### 项目配置

避免硬编码(hard coded)
[配置章节](flask.pocoo.org/docs/latest/config/)
app.config['ADMIN_NAME'] = 'Peter'
Expand All @@ -69,15 +77,18 @@ app.config.update(
value = app.config['ADMIN_NAME']

## 运行

`flask run --host=0.0.0.0 --port=5050`

## Flask 与 HTTP

[RFC](https://www.ietf.org/rfc/) 互联网设计文档
Request-Response-Cycle(请求-响应-周期)
Request Message 报文
Response Message 报文

### URL组成

http:// 协议字符串
spaceack.com 域名
/path 资源路径
Expand All @@ -97,6 +108,7 @@ GET /hello HTTP/1.1
报文主体

### HTTP方法

- GET:获取资源
- POST:创建资源
- PUT:更新资源
Expand All @@ -105,5 +117,6 @@ GET /hello HTTP/1.1
- OPTIONS:询问支持的方法,不返回资源内容

请求方法详细说明:
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Methods
[](https://www.iana.org/assignments/message-headers/message-headers.xhtml)
[Methods](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Methods)

[message-headers](https://www.iana.org/assignments/message-headers/message-headers.xhtml)

0 comments on commit 20ccda2

Please sign in to comment.