这是正确的答案:
#Import necessary libraries
from time import sleep
import RPi.GPIO as GPIO
import telegram_send
sensor = 21 # The sensor is on GPIO pin 21
OPEN_DOOR = 1 # The state of the sensor is 1 when the door is open
CLOSED_DOOR = 0 # The state of the sensor is 0 when the door is closed
DOOR_LAST_STATE = -1
# Send the message
if __name__ == '__main__':
# Sets the GPIO pinout to BCM
GPIO.setmode(GPIO.BCM)
# Pull the sensor to 3.3v when not engaged, It will be pulled to ground when engaged
GPIO.setup(sensor,GPIO.IN,pull_up_down=GPIO.PUD_UP)
# Recovering current state of the door
DOOR_LAST_STATE = GPIO.input(sensor)
# Main Event Loop
# ------------------------------------------------------------------------
print("Program started!")
while True:
curr_state = GPIO.input(sensor)
if curr_state == OPEN_DOOR: # If the door is open
if DOOR_LAST_STATE == CLOSED_DOOR: # And the las known state is "closed"
print("The door is open") # Send the message
telegram_send.send(messages=["The door is open!"])
DOOR_LAST_STATE = OPEN_DOOR # And upate the last known state to "open"
elif DOOR_LAST_STATE == OPEN_DOOR: # But if the last known state is the same as the current
print("The door is still open")
# Do Nothing
else:
print("The door is at unknow state")
elif curr_state == CLOSED_DOOR: # If the door is closed
if DOOR_LAST_STATE == OPEN_DOOR: # And the last know state is open
print("The door is closed") # Send the message
telegram_send.send(messages=["The door is closed!"])
DOOR_LAST_STATE = CLOSED_DOOR # And update the last known state to "closed"
elif DOOR_LAST_STATE == CLOSED_DOOR: # If the last known state is te same as the current
print("The door is still closed")
# Do Nothing
else:
print("The door is at unknow state")
else:
print("The door is at unknow state")
sleep(1) # What we do we will always sleep at the end
# ------------------------------------------------------------------------
# End of loop
任务可能希望您使用功能指针。在此中,可以在某些情况下推导打印
的参数类型。请注意,如果您要同时修改和非修改功能(=函数为const引用)工作,则需要对模板的模板参数进行签名,该签名可能匹配这两种模板,例如您的增量
模板。
template <typename T >
void increment(T& t)
{
t += 1;
}
template <typename T>
void iterate(T* arr, size_t size, void (*f)(const T&)) {
for (size_t i = 0; i < size; i++) f(arr[i]);
}
template <typename T>
void iterate(T* arr, size_t size, void(*f)(T&)) {
for (size_t i = 0; i < size; i++) f(arr[i]);
}
template <typename T >
void print(const T& t) { std::cout << t << " "; };
int main(void) {
int tab[] = { 0,1,2,3,4 };
iterate(tab, 5, increment<int>); // not possible to deduce the template parameter for increment here (both const int and int would be signatures matching an overload of iterate)
iterate(tab, 5, print); // template parameter of print deduced as int
}
对于初学者,该函数具有返回类型 int
,但没有返回。另外,第二个参数应具有未签名的整数类型 size_t
,而不是签名的整数类型 int
。
另外,您应该在使用它们的最小范围中声明变量。
循环的主体
for (i = size - 1; i <= 0; i--) {
代码的主要问题是,如果 size
不小于 2
,则
将永远不会得到控制。另外,还有一个错别字,
a[j] = a[i];
您必须
a[j] = swap;
分开写入此类错字。
该功能可以在以下方式查看
void selection_sort( int *a, size_t n )
{
for ( size_t i = n; i-- != 0; )
{
size_t max = i;
for ( size_t j = 0; j < i; j++ )
{
if ( a[max] < a[j] ) max = j;
}
if ( max != i )
{
int swap = a[max];
a[max] = a[i];
a[i] = swap;
}
}
}
以下方式是一个演示程序。
#include <stdio.h>
void selection_sort( int *a, size_t n )
{
for ( size_t i = n; i-- != 0; )
{
size_t max = i;
for ( size_t j = 0; j < i; j++ )
{
if ( a[max] < a[j] ) max = j;
}
if ( max != i )
{
int swap = a[max];
a[max] = a[i];
a[i] = swap;
}
}
}
int main( void )
{
int a[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
const size_t N = sizeof( a ) /sizeof( *a );
for ( size_t i = 0; i < N; i++ )
{
printf( "%d ", a[i] );
}
putchar( '\n' );
selection_sort( a, N );
for ( size_t i = 0; i < N; i++ )
{
printf( "%d ", a[i] );
}
putchar( '\n' );
}
它的输出是
9 8 7 6 5 4 3 2 1 0
0 1 2 3 4 5 6 7 8 9
正如您正确说明的那样,产品
和位置
是两个不同的聚合。他们不能互相控制,并且拥有 product
保留对单个位置
的引用没有问题。在位置
中,持有 products
的列表(甚至简单的计数器)也是如此。
现在,假设您担心演示层(例如A UI甚至API),例如,由于可能更改位置
,或删除产品
。在这种情况下,您可能需要考虑派遣域事件并编写适当的处理程序来处理它们。您可能还需要考虑使用CQR,并创建/刷新查询模型将被演示层消费。
这是一个系统问题。重新启动后,它像往常一样再次工作。
您无法使用 is_integer
,但对于Varchar(16777216),它不支持
,因此正则表达式会更好
INSERT INTO DB.table_b
SELECT
CASE
WHEN regexp_like(emp,'^[0-9]+
) THEN emp
ELSE NULL
END AS emp_no
FROM
DB.table_a;
这里的问题似乎是实现 Promise.resolve()
函数。任何实施打字的人都不希望将类型推断出尽可能狭窄。
const c = await Promise.resolve("test")
// ^? c: string
如您所见,当调用 Promise.resolve()
使用字符串字面的字体时,该类型被宽扩大到 string
。
有趣的是,在给变量的显式类型时,这不会发生。
const d: "test" = await Promise.resolve("test")
// ^? d: "test"
这种行为似乎在版本3.5上发生了变化,但我仍在寻找解释此功能的变形值。
那么您有什么选择?
- 当使用
Promise.resolve()
时,请使用作为const
。
const [a1] = await Promise.all([Promise.resolve('test' as const)])
// ^? a1: "test"
- 您可以为
Promise.resolve()
编写自己的包装功能,该功能尊重狭窄类型。
type Every =
| null
| string
| number
| boolean
| Array<Every>
| object
| symbol
| undefined
| {
[prop: string]: Every
}
function PromiseResolve<T extends Every>(p: T): Promise<T> {
return Promise.resolve(p)
}
const [a2] = await Promise.all([PromiseResolve('test')])
// ^? a2: "test"
看来我可以使用 min
和 max
range> range
参数,
range([list.cur_page - 2, 2] | max, ...)
所以我有:
{% if list.pages > 1 %}
<ul class="pagination float-start flex-wrap ms-5">
{{ render_button(list, 1) }}
{% for p in range([list.cur_page - 2, 2] | max, [list.cur_page + 3, list.pages - 1] | min ) %}
{{ render_button(list, p) }}
{% endfor %}
{{ render_button(list, list.pages) }}
</ul>
{% endif %}
将关联映射为急切
通常是代码气味。但是,如果您有始终需要加载关联的情况,则可以通过查询进行。
您将致电:
@Repository
public interface ScoringRepository extends GenericRepository<ScoringEntity, String> {
@Query("select se from ScoringEntity se left fetch join se.contributions")
Page<ScoringEntity> findScoringWithContributions(Pageable pageable);
}
此外,我无法想象反应流与冬眠和懒惰的负载不相容。
在这种情况下,问题在于,您正在尝试在会话关闭后懒惰加载关联。
您可以使用控制器无需身份验证就可以做到这一点,然后像Odoo一样返回PDF,但使用Sudo Enviroment。
请显示一些代码以正确帮助您。
您可以这样做:
class Person with ChangeNotifier {
Person({this.name, this.age});
final String name;
int age;
void increaseAge() {
this.age++;
notifyListeners();
}
}
// here, you can see that the [ChangeNotifierProvider]
// is "wired up" exactly like the vanilla [Provider]
void main() {
runApp(
ChangeNotifierProvider(
create: (_) => Person(name: "Yohan", age: 25),
child: MyApp(),
),
);
}
当Aurelia看到元素时,就会创建一个Todolist的实例。当您将其“新”起来时,您已经创建了一个单独的实例。您应该使用view-model.ref捕获对Aurelia创建的实例的引用,而不是创建Todolist类的新实例。
app.html
<template>
<require from="./todo-list"></require>
<h1>Todo list</h1>
<form submit.trigger="addTodo()">
<input type="text" value.bind="todoDescription">
<button type="submit" disabled.bind="!todoDescription">Add Todo</button>
</form>
<todo-list view-model.ref="todoList"></todo-list>
</template>
app.ts
import { TodoList } from "todo-list";
export class App {
todoList: TodoList;
todoDescription = '';
addTodo() {
if (this.todoDescription) {
this.todoList.addOne(this.todoDescription);
this.todoDescription = '';
}
}
}
在这里远非铁路专家,但我已经看到涡轮增压表提交了422:Unprocessable_entity的回复,然后立即获得响应200的起始URL。它是令人难以置信的无证Afaik。我在这里要求提供官方文档帮助:
当涡轮在响应中找不到完整的DOM时,就会发生 它发生。它无法比较您所拥有的东西,因此只会踩踏422并获得。我已经看到这种情况在两种情况下发生:呈现部分而不是呈现完整的响应,或者从没有布局的控制器呈现。
原因1:渲染部分而不是完全渲染
以下内容会导致惊喜获得200,使您的422 Unrprocessable_entity踩踏:
# with app/views/_book.html.haml
render partial: 'book'
return
render partial: 'book', status: :unprocessable_entity
return
惊喜!您可能会认为涡轮的魔力将能够整齐地识别您的部分替代品,但不能。您可能会认为这会引起例外,但事实并非如此。
另一方面,这将起作用:
# app/views/book.html.haml
render 'book', status: :unprocessable_entity
现在,您正在呼吁进行完整的响应和422杆。
文档描述渲染
是一个完整的响应:
原因2:使用没有布局的控制器
,有一种选择布局的方法,而轨道显然可以选择没有布局或错误的布局。
如果您没有“ more_different_book”布局:
# controllers/more_different_book_controller.rb
# no layout called for
def do_stuff
...
return render 'book', status: :unprocessable_entity
end
获得200!
但是,添加明确的(现有)布局可以神奇地修复它:
# controllers/more_different_book_controller.rb
layout 'book'
def do_stuff
...
return render 'book', status: :unprocessable_entity
end
我可能会误解原因,但这是我观察到的以及如何超越它。
这可能对别人有用,这是解决方案
It might be usefull to someone else, here is the solution
firebase,无法在数组中显示地图的记录到视图中