1. 已知三角形三边长度,计算面积
三边长度:a, b, c
半周长:p = (a + b + c) / 2
三角形面积:S = √[p(p-a)(p-b)(p-c)] =(1/4)√[(a+b+c)(a+b-c)(a+c-b)(b+c-a)]
2. 已知三角形各边长度,求其中某个顶点到对边的距离
三边长度:a, b, c,求a到bc边的距离ad
根据上面公式得出三角形面积,
由公式S = 1/2 (底 x 高),则ad = 2*S / bc
三边长度:a, b, c
半周长:p = (a + b + c) / 2
三角形面积:S = √[p(p-a)(p-b)(p-c)] =(1/4)√[(a+b+c)(a+b-c)(a+c-b)(b+c-a)]
三边长度:a, b, c,求a到bc边的距离ad
根据上面公式得出三角形面积,
由公式S = 1/2 (底 x 高),则ad = 2*S / bc
使用subprocess的Popen函数创建了一个进程
使用Popen的kill和terminate函数都杀不掉这个进程
后来发现是因为Popen的时候使用了shell=True参数,如果不使用这个参数可以杀掉
后来百度找到了其他方法
1 2 3 4 5 6 7 |
import psutil def kill(proc_pid): process = psutil.Process(proc_pid) for proc in process.children(recursive=True): proc.kill() process.kill() |
想要杀掉进程的时候使用这个kill参数并传入子进程的pid就可以了
1 2 |
child = subprocess.Popen(['ping 192.168.1.10 -t'], shell=True, stdout=fileno, stderr=fileno) kill(child.pid) |
参考链接:http://www.dovov.com/shell-truepythonsubprocess.html
使用下面的代码读取mysql数据时出现TypeError: tuple indices must be integers or slices, not str错误
1 2 3 4 5 6 7 8 9 10 11 |
conn = pymysql.connect(host=dbhost, user=dbuser, passwd=dbpasswd, db=dbname) while True: cur = conn.cursor() cur.execute("SELECT * from radardevices where status=1") row_headers = [x[0] for x in cur.description] rows = cur.fetchall() for row in rows: print(row["macaddress"]) cur.close() time.sleep(1) conn.close() |
获取cursor时未指定cursor类型,默认使用tuple类型返回,将cur = conn.cursor()这一行修改为如下就可以了
1 |
cur = conn.cursor(cursor=pymysql.cursors.DictCursor) |
1 2 3 4 5 6 7 8 9 10 11 12 |
title: { text: '', style: { display: 'none' } }, subtitle: { text: '', style: { display: 'none' } }, |
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<script> function updateHomeSummary(){ $.ajaxSetup({ headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' } }); $.ajax({ type: "POST", url: "homedatasummary", dataType: "json", success: function (data) { }, error: function(XMLHttpRequest, textStatus, errorThrown) { } }); } </script> |
其中,ajax前面这段代码是用来附加token的
$.ajaxSetup({ headers: { ‘X-CSRF-TOKEN’ : ‘{{ csrf_token() }}’ } });
执行python脚本时提示ImportError: No module named six
可能机器上没有python的six模块
(本文基于Ubuntu 18.04.4)
执行以下命令安装
1 |
pip install six |
如果提示你电脑上没有pip命令,则先安装python-pip
1 |
sudo apt install python-pip |
本文基本Android8.1系统源码
1 2 3 4 5 6 7 |
#include <utils/CallStack.h> ALOGW("name=liuderu cpp stack111"); android::CallStack stack; stack.update(); stack.log("InputDispatcher", ANDROID_LOG_DEBUG, " "); |
stack.log的第一个参数是LOG_TAG,第二个是固定的ANDROID_LOG_DEBUG
使用c语言和wiringPi库
对于这种开关量的传感器,一般有三个针脚VCC、GND、OUT,通常情况下连接方式如下:
vcc接树莓派引脚的3.3v
gnd接树莓派的gnd
out接树莓派gpio0
新建inputtest.c,并输入以下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <stdio.h> #include <wiringPi.h> #define LED 0 #define BLINK_INTERVAL 100 int main(void){ printf("LED blink!\n"); wiringPiSetup(); pinMode(LED, INPUT); for(;;){ int input = digitalRead(LED); printf("input is %d\n", input); delay(BLINK_INTERVAL); } return 0; } |
使用下面的命令编译程序
1 |
gcc inputtest.c -lwiringPi -Wall -o inputtest |
在控制台中输入以下命令运行程序
./inputtest
当发出声音,声控器被触发的时候会输出input is 1
否则输出input is 0
一、思维导图
二、流程图
三、DFD数据流图
四、时序图
五、UML类图