利用图书馆外部访问功能访问学校内网…

不保证所有学校支持此操作…(本校是到了校外就没任何官方性的外部访问方法了,这也是不得已啊啊啊啊啊啊…)

首先,找到学校图书馆的外部访问功能,例如:

登录系统,本校用的是:

找到需要使用VPN才能外部访问的电子资源

下载客户端、连接VPN,例如:

然后康康、改改路由表

将学校内网ip指向VPN的网关…

route ADD 学校内网ip段 MASK 子网掩码 网关 -p
例:
route ADD 172.1.1.0 MASK 255.255.240.0 192.168.1.1 -p

然后应该就ojbk了…

利用now.sh加速博客访问

我最近发现我自建的CDN在不同地区表现有较大差别(比如现在我自己加载个图都加载不出来)所以现在临时换用了zeit的代理来加速,自建CDN待我调教好了再重新启用…

zeit每月提供20G免费流量,对于个人博客还是够用的,国内通常走GCP香港台湾,所以速度较快(坐标重庆,实测移动电信流量秒开图片)

下面介绍一下方法…

首先,在官网注册一个账号,可以直接用GitHub登录

然后,准备一个nodejs环境

安装Now CLI并登录

npm i -g now
now login

新建一个文件夹,在其中创建now.json

{
  "name": "项目名", //这个会体现在链接前面部分
  "version": 2,
  "routes": [
    {"src": "/目录名/(.*)","dest": "https://需要反代的地址/$1"} //只能通过该文件夹访问
  ]
}

部署

now --prod
> Deploying ~\文件夹 under 用户名
> Using project 项目名
> Synced 1 file [2s]
> https://项目名-随机字符.now.sh [6s]
> Ready! Deployment complete [1m]
- https://项目名-名词-数词.now.sh
- https://项目名.用户名.now.sh [in clipboard]

运行结果中的三个域名均可用于访问,访问地址大概是这样:

https://项目名.用户名.now.sh/目录名/

然后就可以用WP Super Cache代替所有静态文件链接来食用了….

此外,也可以在官网换用自己的域名

自制迷你PHP博客…

上周作业…时间太紧了就随手做了个…

用 Parsedown 解析md达到的…(自行去官网下载Parsedown.php才能食用哦)

目录和文章需要手动建立…

demo:(完全没有小屏幕适配)

Source:

<!doctype html>
<html>
<head>
	<title>Simple Blog</title>
	<link href="//cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
  </head>
<div class="container-fluid">
	<div class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom shadow-sm">
  	<nav class="my-0 mr-md-auto font-weight-normal">
  	<a class="p-2 text-dark" href="index.php">首页</a>
  	<a class="p-2 text-dark" href="index.php?list">目录</a>
  </nav>
  <h5 class="my-2 my-md-0 mr-md-3">博客</h5>
</div>
  </div>
  <div style="width: 90%; max-width: 800px; margin: 0 auto;">
<?php
header("content-type:text/html;charset=utf-8");
require_once('Parsedown.php');
function output($passage)
{
  if(file_exists($passage)){
    $fp = fopen($passage,"r");
	$text = fread($fp,filesize($passage));
	fclose($fp);
    $result = Parsedown::instance()->parse($text);
	echo $result;
	}
    else echo '<div style="margin-top:170px;"><h2>Sorry , 文章不存在</h2></div>';
}
if(isset($_GET['p']))output($_GET['p'].".md");
else if(isset($_GET['list']))output('list.md');
else echo '<div style="margin-top:170px;"><h2>这是个博客...</h2><br><br><br><h4>嗯,这是个博客</h4><br><br><h5>文章看目录8</h5></div>';
  ?>
  </div>
</html>

Python翻译小程序

调用网上找的api做的…

支持谷歌、必应(能否成功调用看脸)、有道、词霸、欧米翻译

直接放Source

import requests
import re
def translate_google(lanf,lant,text):
    try:
        url="https://translate.google.cn/translate_a/single?client=gtx&sl="+lanf+"&tl="+lant+"&dt=t&dt=bd&q="+text
        translation=requests.get(url).json()
        num=0
        ans={}
        try:
            for i in translation[1]:
                num+=1
                ans[num-1]=0
                for j in translation[1][num-1][1]:
                    ans[num-1]+=1
            i=0
            while i<num:
                print(translation[1][i][0],end=": ")
                j=0
                while j<ans[i]:
                    print(translation[1][i][1][j],end="")
                    if j+1<ans[i]:print(",",end="")
                    j+=1
                print()
                i+=1
            print('')
        except:
            translation=translation[0][0][0]
            print("翻译结果:"+translation)
            print('')
    except:
        print("出错")
def translate_youdao(lanf,lant,text):
    try:
        if lanf=='jp':lanf='ja'
        if lant=='jp':lant='ja'
        mode=(lanf.replace('-','_')+'2'+lant.replace('-','_')).upper()
        url="http://fanyi.youdao.com/translate?&doctype=json&type="+mode+"&i="+text
        translation=requests.get(url).json()['translateResult'][0][0]['tgt']
        print("翻译结果:"+translation)
        print('')
    except:
        print("出错")
def translate_bing(lanf,lant,text):
    try:
        url="http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=AFC76A66CF4F434ED080D245C30CF1E71C22959C&from="+lanf+"&to="+lant+"&text="+text
        translation = requests.get(url).text
        translation=re.findall(r'<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">(.*?)</string>',translation)[0]
        print("翻译结果:"+translation)
        print('')
    except:
        print("出错")
def translate_icb(lanf,lant,text):
    try:
        if lanf!='auto':
            lanf=lanf[:2]
            if lanf=='jp':lanf='ja'
        if lant!='auto':
            lant=lant[:2]
            if lant=='jp':lant='ja'
        url='http://fy.iciba.com/ajax.php?a=fy&f='+lanf+'&t='+lant+'&w='+text
        translation=requests.get(url).json()
        if translation['status']==0:
            for i in translation['content']['word_mean']:
                print(i)
        elif translation['status']==1:
            print("翻译结果:"+translation['content']['out'])
        print('')
    except:
        print("出错")
def translate_omi(lanf,lant,text):
    try:
        lanf=lanf[:1]
        lant=lant[:1]
        if lanf=='a' or lant=='a':mode='undef'
        else:
            if lanf=='z':lanf='c'
            if lant=='z':lant='c'
            mode=lanf+'2'+lant
        url='https://www.omifanyi.com/transsents.do?sentsToTrans='+text+'&languageType='+mode
        translation=requests.get(url).json()
        base=translation['sentsResults'][1][0]
        extra=translation['wordResults']
        print('翻译结果:'+base)
        try:
            for i in extra:
                print(i[0]+' '+i[1])
        except:
            pass
        print('')
    except:
        print("出错")
def main(lanf,lant,provider):
    while 1:
        if provider==1:
            text = input("键入需要翻译的内容:\n")
            translate_google(lanf,lant,text)
        elif provider==2:
            text = input("键入需要翻译的内容:\n")
            translate_bing(lanf,lant,text)
        elif provider==3:
            text = input("键入需要翻译的内容:\n")
            translate_youdao(lanf,lant,text)
        elif provider==4:
            text = input("键入需要翻译的内容:\n")
            translate_icb(lanf,lant,text)
        elif provider==5:
            text = input("键入需要翻译的内容:\n")
            translate_omi(lanf,lant,text)
        elif provider==6:
            text = input("键入需要翻译的内容:\n")
            print("谷歌:")
            translate_google(lanf,lant,text)
            print("有道:")
            translate_youdao(lanf,lant,text)
            print("词霸:")
            translate_icb(lanf,lant,text)
            print("欧米翻译:")
            translate_omi(lanf,lant,text)
            print("必应:")
            translate_bing(lanf,lant,text)
        else:
            print("错误选项")
            exit()
mode=int(input("欢迎使用翻译\n你希望怎么翻译呢?\n1).英译中\n2).中译英\n3).自动转中文\n4).自动转英文\n5).全自动(有道、词霸支持多语言)\n6).手动选择\n7).退出\n"))
if mode==1:
    provider=int(input("要哪家的服务呢?\n1).谷歌\n2).巨硬(Api次数有限)\n3).有道\n4).词霸\n5).欧米翻译\n6).我全都要\n"))
    main('en','zh-cn',provider)
elif mode==2:
    provider=int(input("要哪家的服务呢?\n1).谷歌\n2).巨硬(Api次数有限)\n3).有道\n4).词霸\n5).欧米翻译\n6).我全都要\n"))
    main('zh-cn','en',provider)
elif mode==3:
    provider=int(input("要哪家的服务呢?\n1).谷歌\n2).巨硬(Api次数有限)\n3).有道\n4).词霸\n5).欧米翻译(仅中英)\n6).我全都要\n"))
    main('auto','zh-cn',provider)
elif mode==4:
    provider=int(input("要哪家的服务呢?\n1).谷歌\n2).巨硬(Api次数有限)\n3).有道\n4).词霸\n5).欧米翻译(仅中英)\n6).我全都要\n"))
    main('auto','en',provider)
elif mode==5:
    provider=int(input("要哪家的服务呢?\n1).有道\n2).词霸\n3).欧米翻译(仅中英)\n"))
    if provider==1:provider=3
    elif provider==2:provider=4
    elif provider==3:provider=5
    elif provider==6:pass
    else:provider=0
    main('auto','auto',provider)
elif mode==6:
    lanf=input("输入源语言(zh-cn,en,jp,auto...):\n")
    lant=input("输入目标语言(zh-cn,en,jp...):\n")
    provider=int(input("要哪家的服务呢?\n1).谷歌\n2).巨硬(Api次数有限)\n3).有道\n4).词霸\n5).我全都要\n"))
    if provider==5:provider=6
    elif provider==6:provider=0
    main(lanf,lant,provider)
elif mode==7:
    print('欢迎下次使用')
    exit()
else:
    print('错误选项')
    exit()

就这样8…

Python简易聊天室

这是第二个

一、一对一版

1).服务端

我又倦了,直接贴代码

import socket
import threading
s = socket.socket()
s.bind(("", 2333))
s.listen(5)
nick = input("输入昵称:")
print("Start Server...")
sock, addr = s.accept()
print(addr, " Connected")
print("输入q以退出")
other = sock.recv(1024).decode()
def reciver():
    while 1:
        data = sock.recv(1024)
        print(other, " : ", data.decode())
def sender():
    while 1:
        sock.send(nick.encode())
        massage = input()
        if massage == 'q':
            break
        print(nick + " : " + massage)
        sock.send(massage.encode())
t1 = threading.Thread(target=reciver, name='recive')
t2 = threading.Thread(target=sender, name='send')
t1.start()
t2.start()
t2.join()
sock.close()
print("断开连接")

2).客户端

import socket
import threading
s = socket.socket()
nick = input("输入昵称:")
ip = input("输入服务器ip:")
port = 2333
s.connect((ip, port))
print("已连接服务器\n输入q以退出")
s.send(nick.encode())
def sender():
    while 1:
        massage = input()
        if massage == 'q':
            break
        print(nick + " : " + massage)
        s.send(massage.encode())
def reciver():
    while 1:
        other = s.recv(1024).decode()
        massage = s.recv(1024).decode()
        print(other, " : ", massage)
t1 = threading.Thread(target=reciver, name='recive')
t2 = threading.Thread(target=sender, name='send')
t1.start()
t2.start()
t2.join()
print("断开连接")
s.close()

二、多人聊天室

1).服务端

import socket
import threading
user={}
address={}
def send(text,addr):
    for i in user:
        try:
            if addr != '' and i == address[addr]:
                pass
            else:
                s.sendto(text.encode(),user[i])
        except:
            logout(i)
def preload():
    while 1:
        preloading=s.recvfrom(1024)
        mess=preloading[0].decode()
        addr=preloading[1]
        if addr in address:
            try:
                if mess == 'q':
                    logout(address[addr])
                else:
                    send(address[addr]+ ':' + mess,addr)
            except:
                logout(address[addr])
        else:
            login(mess,addr)
            print(addr," Connected\n当前在线人数:",len(user))
def login(nick,addr):
    if nick in user:
        s.sendto("系统消息:用户名存在\n请重新输入:".encode(),addr)
    else:
        user[nick]=addr
        address[addr]=nick
        send("系统消息:欢迎"+nick+"进入直播间",'')
def logout(nick):
    send("系统消息:"+nick+"褪出了直播间",'')
    s.sendto("sys_exit".encode(),user[nick])
    print(user[nick],"Logout\n当前在线人数:",len(user)-1)
    del address[user[nick]]
    del user[nick]
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind(('',2333))
print("Start Server...")
thread=threading.Thread(target=preload)
thread.setDaemon(True)
thread.start()
thread.join()

2).客户端

import socket
import threading
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
nick = input("输入昵称:")
ip = input("输入服务器ip:")
port = 2333
s.connect((ip,port))
print("连接服务器...\n如需退出,按q(请务必不要强制退出)")
s.send(nick.encode())
def sender():
    try:
        while 1:
            massage = input()
            s.sendto(massage.encode(),(ip,port))
            if massage == 'q':
                exit()
    except:exit()
def reciver():
    try:
        while 1:
            massage=s.recvfrom(1024)[0].decode()
            if massage == 'sys_exit':
                break
            print(massage)
    except:print("IF YOU MEET SOME TROUBLE,Please Contact Developer\nBye~")
t1 = threading.Thread(target=reciver, name='recive')
t2 = threading.Thread(target=sender, name='send')
t1.start()
t2.start()
t2.join()

就这样8…

感谢以下文章:

Python基础socket一对一聊天室

Python实现简易聊天室(Linux 终端)

socket编程学习——-python打造多人聊天室

基于python的聊天室程序

python实现socket+threading处理多连接

【python】udp 数据的发送和接收

python-udp接受数据

这些文章我或多或少进行了参考,可能只是一个点,可能只是一句话,亦有可能是一段代码,但非常感谢这些文章在我完成这个作业时对我的帮助

…不想写了…明天再说,我去康康有什么新优惠

TCP完成简易GET

咕咕咕,这段时间主要是期中考试…还关注了几天黑五…然后拖到今天才写完…

这是第一个,用仅TCP实现GET功能

import socket
import ssl
s=ssl.wrap_socket(socket.socket())
s.connect(('www.bilibili.com', 443))
s.send('GET / HTTP/1.1\r\n'.encode())
s.send('Host: www.bilibili.com\r\n'.encode())
s.send('User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36\r\n'.encode())
s.send('Connection: close\r\n\r\n'.encode())
response=b""
while 1:
    temp = s.recv(1024)
    if temp:
        response+=temp
    else:break
s.close()
response=response.decode("utf8").split("\r\n\r\n")[1]
f = open('bilibili.html','w',encoding='utf-8')
f.write(response)
f.close()

这样就行了,很简单的,就是输出出来的文件会有点奇怪:

有些地方UTF-8无法解析,谁来救救我…

参考了许多大佬的文章,在此一并感谢

Python爬取网易云歌手信息

这个同样是作业…

早写完了,鸽了好久才发出来…

首先是根据指定歌手id获取歌手名和简介

import requests
import re
def spider(id):
    url="https://music.163.com/m/artist?id="+id
    headers={"user-agent": "Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1"}
    response=requests.get(url,headers=headers)
    response=response.text
    singer=re.findall(r'<meta name="keywords" content="(.*?)" />',response)
    introduce=re.findall('"briefDesc":"(.*?)"',response)
    result=dict(zip(singer,introduce))
    print(result)
id=input('请输入歌手id:\n')
spider(id)

我发现移动版的网易云更好搞,不需要cookie啥的,只要有个UA就能获取成功…

然后稍微处理一下就能取得信息了…

然后是获取所有亚洲男歌手id和姓名

import requests
import re
def spider(id):
    url="https://music.162.com/discover/artist/cat?id=1001&initial="+str(id)
    headers={"user-agent": "Mozilla/4.0 (Windows NT 10.0; Win64; x64; Cortana 1.11.6.17763; 10.0.0.0.17763.805) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763"}
    response=requests.get(url,headers=headers)
    response=response.text
    singer=re.findall(r'<a href="/artist\?id=(.*?)" class="nm nm-icn f-thide s-fc-1" title="(.*?)的音乐"',response)
    singer=dict(singer)
    return singer
list={64,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,0}
singers=spider(-2)
for id in list:
    singers=dict(singers,**spider(id))
print(singers)

这个也很简单…UA用的Cortana的…虽然不知道有什么用…

就这样吧,这次的没什么难度

华为云两款2X4G鸡比较

我曾在今年7月多上了华为云的双核4G1M学生机,当时是s2.large.2而且只有广州数据中心,今天,我再次进入华为云的学生优惠页,发现我居然还能买2x4g学生机,活动内容基本一样,但这次不同的是,型号变成了t6.large.2,而且有上海、北京可选(现在还有云数据库可供选购),因为我腾讯和阿里的机子都在上海,所以这次我上了北京的年付车

首先,说一下s2.large.2和t6.large.2的区别

t6.large.2
s2.large.2

可以看出,t6有性能限制,超过基准就要算CPU积分,积分用完就会强制限制到基准(积分啥的我完全搞不懂)

直接放跑分结果把,虽然不是在一个地区,但应该还是有参考性的

这是s2的,性能还过得去,就是不知道为什么speedtest跑不动
------------------------------------------------------------------------
Benchmark Run: Tue Oct 29 2019 19:52:14 - 12:20:51
2 CPUs in system; running 1 parallel copy of tests

Dhrystone 2 using register variables       33486251.2 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     3802.8 MWIPS (13.2 s, 7 samples)
Execl Throughput                               4723.8 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        859295.0 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          226276.3 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       2355875.5 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1570786.9 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                  89506.2 lps   (10.0 s, 7 samples)
Process Creation                              10460.1 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                   7195.0 lpm   (60.3 s, 2 samples)
Shell Scripts (8 concurrent)                   1553.7 lpm   (60.0 s, 2 samples)
System Call Overhead                        2015708.8 lps   (10.0 s, 7 samples)
 
System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   33486251.2   2869.4
Double-Precision Whetstone                       55.0       3802.8    691.4
Execl Throughput                                 43.0       4723.8   1098.6
File Copy 1024 bufsize 2000 maxblocks          3960.0     859295.0   2169.9
File Copy 256 bufsize 500 maxblocks            1655.0     226276.3   1367.2
File Copy 4096 bufsize 8000 maxblocks          5800.0    2355875.5   4061.9
Pipe Throughput                               12440.0    1570786.9   1262.7
Pipe-based Context Switching                   4000.0      89506.2    223.8
Process Creation                                126.0      10460.1    830.2
Shell Scripts (1 concurrent)                     42.4       7195.0   1696.9
Shell Scripts (8 concurrent)                      6.0       1553.7   2589.6
System Call Overhead                          15000.0    2015708.8   1343.8
                                                                   ========
System Benchmarks Index Score                                        1349.2
 
------------------------------------------------------------------------
Benchmark Run: Tue Oct 29 2019 12:20:51 - 12:49:32
2 CPUs in system; running 2 parallel copies of tests
 
Dhrystone 2 using register variables       65907398.7 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     7605.8 MWIPS (13.2 s, 7 samples)
Execl Throughput                               9185.6 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks       1147725.8 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          303610.9 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       3320440.7 KBps  (30.0 s, 2 samples)
Pipe Throughput                             3039240.7 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 499038.8 lps   (10.0 s, 7 samples)
Process Creation                              22374.7 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                  11306.6 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                   1647.2 lpm   (60.0 s, 2 samples)
System Call Overhead                        3151873.1 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   65907398.7   5647.6
Double-Precision Whetstone                       55.0       7605.8   1382.9
Execl Throughput                                 43.0       9185.6   2136.2
File Copy 1024 bufsize 2000 maxblocks          3960.0    1147725.8   2898.3
File Copy 256 bufsize 500 maxblocks            1655.0     303610.9   1834.5
File Copy 4096 bufsize 8000 maxblocks          5800.0    3320440.7   5724.9
Pipe Throughput                               12440.0    3039240.7   2443.1
Pipe-based Context Switching                   4000.0     499038.8   1247.6
Process Creation                                126.0      22374.7   1775.8
Shell Scripts (1 concurrent)                     42.4      11306.6   2666.6
Shell Scripts (8 concurrent)                      6.0       1647.2   2745.3
System Call Overhead                          15000.0    3151873.1   2101.2
                                                                   ========
System Benchmarks Index Score                                        2429.5

Superbench
----------------------------------------------------------------------
 Superbench.sh -- https://www.oldking.net/350.html
 Mode  : Standard    Version : 1.1.5
 Usage : wget -qO- git.io/superbench.sh | bash
----------------------------------------------------------------------
 CPU Model            : Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz
 CPU Cores            : 2 Cores @ 2394.454 MHz x86_64
 CPU Cache            : 35840 KB 
 OS                   : CentOS 7.6.1810 (64 Bit) KVM
 Kernel               : 5.3.7-1.el7.elrepo.x86_64
 Total Space          : 3.2 GB / 40.0 GB 
 Total RAM            : 233 MB / 3938 MB (745 MB Buff)
 Total SWAP           : 0 MB / 0 MB
 Uptime               : 0 days 1 hour 55 min
 Load Average         : 0.00, 0.00, 0.16
 TCP CC               : bbr
 ASN & ISP            : AS55990, Huawei Cloud Service
 Organization         : Huawei Cloud Service
 Location             : Guangzhou, China / CN
 Region               : Guangdong
----------------------------------------------------------------------
 I/O Speed( 1.0GB )   : 166 MB/s
 I/O Speed( 1.0GB )   : 157 MB/s
 I/O Speed( 1.0GB )   : 179 MB/s
 Average I/O Speed    : 167.3 MB/s
----------------------------------------------------------------------
 Node Name        Upload Speed      Download Speed      Latency     
 Speedtest.net    2.28 Mbit/s       84.12 Mbit/s        43.286 ms  
 Wuhan     CT     1.95 Mbit/s       71.59 Mbit/s        -          
----------------------------------------------------------------------
 Finished in  : 6 min 1 sec
 Timestamp    : 2019-10-29 13:42:05 GMT+8
 Results      : /root/superbench.log
----------------------------------------------------------------------
这是t6的,性能要差点,但也过得去,ip貌似是广播上海的
------------------------------------------------------------------------
Benchmark Run: Tue Oct 29 2019 12:21:24 - 12:49:30
2 CPUs in system; running 1 parallel copy of tests

Dhrystone 2 using register variables       33006253.8 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     3927.5 MWIPS (9.8 s, 7 samples)
Execl Throughput                               4615.3 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks        670588.1 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          183666.3 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       1806455.5 KBps  (30.0 s, 2 samples)
Pipe Throughput                             1057433.7 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                  75775.1 lps   (10.0 s, 7 samples)
Process Creation                               9376.1 lps   (30.4 s, 2 samples)
Shell Scripts (1 concurrent)                   7090.6 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                   1458.5 lpm   (60.0 s, 2 samples)
System Call Overhead                         928061.5 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   33006253.8   2828.3
Double-Precision Whetstone                       55.0       3927.5    714.1
Execl Throughput                                 43.0       4615.3   1073.3
File Copy 1024 bufsize 2000 maxblocks          3960.0     670588.1   1693.4
File Copy 256 bufsize 500 maxblocks            1655.0     183666.3   1109.8
File Copy 4096 bufsize 8000 maxblocks          5800.0    1806455.5   3114.6
Pipe Throughput                               12440.0    1057433.7    850.0
Pipe-based Context Switching                   4000.0      75775.1    189.4
Process Creation                                126.0       9376.1    744.1
Shell Scripts (1 concurrent)                     42.4       7090.6   1672.3
Shell Scripts (8 concurrent)                      6.0       1458.5   2430.8
System Call Overhead                          15000.0     928061.5    618.7
                                                                   ========
System Benchmarks Index Score                                        1118.3

------------------------------------------------------------------------
Benchmark Run: Tue Oct 29 2019 12:49:30 - 13:17:34
2 CPUs in system; running 2 parallel copies of tests

Dhrystone 2 using register variables       66023784.7 lps   (10.0 s, 7 samples)
Double-Precision Whetstone                     7831.6 MWIPS (9.8 s, 7 samples)
Execl Throughput                               8116.9 lps   (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks       1067156.4 KBps  (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks          279506.3 KBps  (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks       2916760.0 KBps  (30.0 s, 2 samples)
Pipe Throughput                             2090724.8 lps   (10.0 s, 7 samples)
Pipe-based Context Switching                 419397.7 lps   (10.0 s, 7 samples)
Process Creation                              14908.3 lps   (30.0 s, 2 samples)
Shell Scripts (1 concurrent)                  10863.4 lpm   (60.0 s, 2 samples)
Shell Scripts (8 concurrent)                   1540.2 lpm   (60.0 s, 2 samples)
System Call Overhead                        1620902.1 lps   (10.0 s, 7 samples)

System Benchmarks Index Values               BASELINE       RESULT    INDEX
Dhrystone 2 using register variables         116700.0   66023784.7   5657.6
Double-Precision Whetstone                       55.0       7831.6   1423.9
Execl Throughput                                 43.0       8116.9   1887.6
File Copy 1024 bufsize 2000 maxblocks          3960.0    1067156.4   2694.8
File Copy 256 bufsize 500 maxblocks            1655.0     279506.3   1688.9
File Copy 4096 bufsize 8000 maxblocks          5800.0    2916760.0   5028.9
Pipe Throughput                               12440.0    2090724.8   1680.6
Pipe-based Context Switching                   4000.0     419397.7   1048.5
Process Creation                                126.0      14908.3   1183.2
Shell Scripts (1 concurrent)                     42.4      10863.4   2562.1
Shell Scripts (8 concurrent)                      6.0       1540.2   2566.9
System Call Overhead                          15000.0    1620902.1   1080.6
                                                                   ========
System Benchmarks Index Score                                        2038.8

Superbench
----------------------------------------------------------------------
 Superbench.sh -- https://www.oldking.net/350.html
 Mode  : Standard    Version : 1.1.5
 Usage : wget -qO- git.io/superbench.sh | bash
----------------------------------------------------------------------
 CPU Model            : Intel(R) Xeon(R) Gold 6161 CPU @ 2.20GHz
 CPU Cores            : 2 Cores @ 2200.000 MHz x86_64
 CPU Cache            : 30976 KB 
 OS                   : CentOS 7.6.1810 (64 Bit) KVM
 Kernel               : 5.3.7-1.el7.elrepo.x86_64
 Total Space          : 3.2 GB / 40.0 GB 
 Total RAM            : 239 MB / 3938 MB (674 MB Buff)
 Total SWAP           : 0 MB / 0 MB
 Uptime               : 0 days 0 hour 57 min
 Load Average         : 9.54, 7.40, 4.25
 TCP CC               : bbr
 ASN & ISP            : AS55990, Huawei Cloud Service
 Organization         : Huawei Cloud Service
 Location             : Shanghai, China / CN
 Region               : Shanghai
----------------------------------------------------------------------
 I/O Speed( 1.0GB )   : 182 MB/s
 I/O Speed( 1.0GB )   : 156 MB/s
 I/O Speed( 1.0GB )   : 156 MB/s
 Average I/O Speed    : 164.7 MB/s
----------------------------------------------------------------------
 Node Name        Upload Speed      Download Speed      Latency     
 Speedtest.net    1.80 Mbit/s       84.02 Mbit/s        47.467 ms  
 Fast.com         0.00 Mbit/s       0.8 Mbit/s          -           
 Wuhan     CT     1.85 Mbit/s       84.62 Mbit/s        -          
 Hangzhou  CT     1.56 Mbit/s       78.70 Mbit/s        -          
 Lanzhou   CT     1.75 Mbit/s       48.04 Mbit/s        -          
 Shanghai  CU     1.58 Mbit/s       93.58 Mbit/s        -          
 Heifei    CU     1.94 Mbit/s       64.39 Mbit/s        -          
 Xizang    CM     1.55 Mbit/s       70.12 Mbit/s        -          
----------------------------------------------------------------------
 Finished in  : 6 min 25 sec
 Timestamp    : 2019-10-29 13:24:13 GMT+8
 Results      : /root/superbench.log
----------------------------------------------------------------------

在测试过程中,后台显示s2最高跑到了94%的CPU占用率,而t6最高只有80%,积分也用了不少…

说不清楚是变坑了还是怎么样…

如何做一个假wei斯

这个其实也是在完成作业时的副产品,之所以选择百度就是因为便宜还有易于开发

一、获取百度SDK

首先,你需要拥有一个百度账号(估计都有吧,这年代还有人不用百度云?)

然后,登陆 https://console.bce.baidu.com/ai/#/ai/speech/overview/index 创建应用,接口默认即可

点击查看应用详情,获取 AppID,API Key,Secret Key

安装Python SDK

pip install baidu-aip

无pip也可在应用页下载SDK手动安装,解包后执行

python setup.py install

二、安装依赖

这部分没pip的只有自己想办法了…

除SDK外,还需安装playsound,pyaudio,scipy,numpy

第一个用于播放合成出来的语音

后面三个主要用在录音环节

依次执行

pip install 包名

如果pyaudio无法安装

https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio 下载对应包

pip install 包名.whl

即可完成安装

另外,还需对playsound进行修改,否则循环时会一直占用音频文件,导致无法写入

请参考 python下playsound模块解除占用

三、码代码

我们分成四个部分来完成

第一部分:语音识别

参考官方文档,我们首先需要将之前获得的APP_IDAPI_KEYSECRET_KEY 填入

from aip import AipSpeech

""" 你的 APPID AK SK """
APP_ID = '你的 App ID'
API_KEY = '你的 Api Key'
SECRET_KEY = '你的 Secret Key'

client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

再参照文档中的示例

# 读取文件
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

# 识别本地文件
client.asr(get_file_content('audio.pcm'), 'pcm', 16000, {
    'dev_pid': 1536,
})

这个示例是将目录下的audio.pcm上传识别

因此,能想到,如果有什么方法能自动录音,判断我们已经停止说话,然后将文件上传识别,那么这个模块就已经完善

然而,我对这个自动录音想的太过简单,最终,录音部分通过对python录音程序提供的源码进行修改实现

大佬的源码非常完善,我们只需要对其中几个参数进行修改即可,录音阈值可以按环境进行适度调整,为了美观,可以将其中的两个print进行修改

删除源码的最后两行,保存为record.py

录音模块便制作完成

将其import后就可以直接调用了,我们可以直接recording(‘in.wav’)完成录音

再看回百度这边,client.asr调用后会返回一个dict,处理起来非常方便,只需dict.get(‘result’)就可以获取到[‘内容’]形式的结果

我通过对字符串的简单处理去除了[‘和’]

questionall = client.asr(get_file_content('in.wav'), 'pcm', 16000, {'dev_pid': 1536, }) # 此部分实现语音识别,返回值在questionall内
questional = str(questionall.get('result'))
    lens = int(len(questional))
    ques = questional[2:lens - 2]str(questionall.get('result')) # 此部分将结果提取并转为字符串
lens = int(len(questional)) # 获取字符串长度
ques = questional[2:lens - 2] # 只保留内容到ques

第二部分:调用机器人

因为懒,我直接用了一个百度出来的机器人http://api.qingyunke.com/ 说实话,还蛮好的

我们通过GET来获取回答,信息已存入message中,需注意,message必须urlencode,否则可能报错

r=requests.get('http://api.qingyunke.com/api.php?key=free&appid=0&msg='+message)

结果为一个dict和json都会报错的东西(大概是我太蔡了),所以我只能再次进行字符串处理

answer=str(r.json()) # 转为字符串
lens=int(len(answer)) # 计算长度
ans=answer[26:lens-2] # 保留结果

第三部分:语音合成

同样,根据官方文档

result  = client.synthesis('你好百度', 'zh', 1, {
    'vol': 5,
})

# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
    with open('auido.mp3', 'wb') as f:
        f.write(result)

所以我们只需把‘你好百度’换成我们需要的文字即可,可以修改参数来优化语音

播放语音通过playsound(‘out.mp3’)实现

第四部分:逻辑主体

这里主要是逻辑方面的编写,你们自己看着办吧…

比如一阵机械的嘘寒问暖之后,开始循环,直到识别到关键字退出或进行指定回答…

最终节:出来吧,假wei斯

唔,我还是直接贴代码吧,不想写了,安装完依赖后,直接执行应该能得到一个假wei斯吧…(记得替换APP_ID啥的,record.py必须在同目录下)

from aip import AipSpeech
import requests
import urllib.parse
from record import recording
from playsound import playsound

# 认证部分
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''

client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

# 读取文件
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

# 录音并调用SDK进行语音识别,输出并返回结果
def voice():
    recording('in.wav')
    questionall = client.asr(get_file_content('in.wav'), 'pcm', 16000, {'dev_pid': 1536, })
    questional = str(questionall.get('result'))
    lens = int(len(questional))
    ques = questional[2:lens - 2]
    print('.',end='')
    print(ques)
    ques = urllib.parse.quote(ques)
    return ques

# 根据给入的文字调用SDK输出并播放音频
def voiceout(message):
    result  = client.synthesis(message, 'zh', 1, {'vol': 5,})
    if not isinstance(result, dict):
        with open('out.mp3', 'wb') as f:
            f.write(result)
    playsound('out.mp3')

# 向机器人发送信息并对返回值处理
def ai(message):
    r=requests.get('http://api.qingyunke.com/api.php?key=free&appid=0&msg='+message)
    answer=str(r.json())
    lens=int(len(answer))
    ans=answer[26:lens-2]
    return ans

# 程序主体
print('欢迎使用聊天机器人')
ainame=input('给你的机器人取个名字吧\n')
name=input('你叫什么名字?\n')
print(ainame,':你好',name,',说些什么吧')
voiceout('你好,'+name+',说些什么吧')
i=1;
while i==1:
    print(name,':',end='')
    requ=voice()
    requ=urllib.parse.unquote(requ)
    if '再见' in requ or '晚安' in requ or '退出' in requ or '拜拜' in requ:
        i=0
    anse=ai(requ)
    if anse=='未获取到相关信息':
        anse='听不清,请再说一遍'
    print(ainame,':',anse)
    voiceout(anse)
print('谢谢使用!')
voiceout('谢谢使用!')

最后,再次感谢百度SDK,聊天机器人录音脚本playsound修改等教程或服务的作者或开发者

利用Docker一键安装WordPress

同样,这也是社团任务…

这次,我选用Centos8来进行

配置Docker及系统环境

首先,安装Docker

推荐使用自动脚本安装(省事,快捷),通过mirror选项更换国内源

curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh --mirror Aliyun

启用Docker

systemctl enable docker
systemctl start docker

开启v4转发(不开就没法关防火墙…容器也可能连不了外网)

vi /etc/sysctl.conf
#在其中添加
net.ipv4.ip_forward=1
#重启网络生效
systemctl restart network

关闭防火墙及SELinux(也是因为懒)

#停止firewalld服务
systemctl stop firewalld
#禁止firewalld自起
systemctl disable firewalld
#临时关闭SELinux
setenforce 0
#永久关闭SELinux
vi /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled

使用YAML一键构建

建立一个wordpress.yml文件

vi wordpress.yml

在其中键入(3.1版语法)

version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 80:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpressuser
      WORDPRESS_DB_PASSWORD: wordpresspass
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wordpress:/var/www/html

  db:
    image: mariadb
    restart: always
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpressuser
      MYSQL_PASSWORD: wordpresspass
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

volumes:
  wordpress:
  db:

以上根据官方文档修改

一键安装

docker stack deploy -c stack.yml wordpress

安装完成后可通过http://swarm-iphttp://localhost, or http://host-ip访问

附1:

我是使用DaoCloud一键构建的,但由于平台只支持YAML 2.0,因此,我修改了上方代码,形成下方代码(适用于DaoCloud,别的不清楚)

wordpress:
  image: wordpress
  ports:
  - 80:80
  environment:
  - WORDPRESS_DB_HOST=db
  - WORDPRESS_DB_USER=wordpress
  - WORDPRESS_DB_PASSWORD=password
  - WORDPRESS_DB_NAME=wordpress
  restart: always
  links:
  - db
  volumes:
  - wordpress:/var/www/html
db:
  image: mariadb
  restart: always
  environment:
  - MYSQL_DATABASE=wordpress
  - MYSQL_USER=wordpress
  - MYSQL_PASSWORD=password
  - MYSQL_RANDOM_ROOT_PASSWORD='1'
  volumes:
  - db:/var/lib/mysql

附2:

还顺便研究了下Minecraft的Docker一键部署(同样2.0版)

minecraft:
  image: index.docker.io/itzg/minecraft-server:20190824  //有新版本自行更换
  privileged: false
  restart: always
  ports:
  - 25575:25575  //推荐更改此端口,这个为控制端口
  - 25565:25565
  volumes:
  - /data:/data
  environment:
  - EULA=TRUE  //不同意不能部署

详见 https://hub.docker.com/r/itzg/minecraft-server