通常,当您看到此错误时,这意味着,要么以某种方式更改了发送到Webhook处理程序的HTTP请求身体条纹,要么您可能无法使用正确的Webhook Secret。
抛出例外的最可能原因是,您的路由器将主体解析为JSON,使用 router.use(express.json())
。 constructEvent
需要您从请求中收到的原始的,无与伦比的主体来验证签名。 验证您拥有原始身体
要 像这样在路由上的 router.use('/webhook',express.raw({type:“*/*”}))
>
可以使用策略模式与
让我们从第一个示例开始。我们需要一些 processortype
的枚举:
public enum ProcessorType
{
Simple, Complex
}
这是我们的处理器的抽象:
public interface IProcessor
{
DateTime DateCreated { get; }
}
及其具体插入:
public class SimpleProcessor : IProcessor
{
public DateTime DateCreated { get; } = DateTime.Now;
}
public class ComplexProcessor : IProcessor
{
public DateTime DateCreated { get; } = DateTime.Now;
}
然后,我们需要一个具有缓存值的工厂:
public class ProcessorFactory
{
private static readonly IDictionary<ProcessorType, IProcessor> _cache
= new Dictionary<ProcessorType, IProcessor>()
{
{ ProcessorType.Simple, new SimpleProcessor() },
{ ProcessorType.Complex, new ComplexProcessor() }
};
public IProcessor GetInstance(ProcessorType processorType)
{
return _cache[processorType];
}
}
可以像这样运行代码:
ProcessorFactory processorFactory = new ProcessorFactory();
Thread.Sleep(3000);
var simpleProcessor = processorFactory.GetInstance(ProcessorType.Simple);
Console.WriteLine(simpleProcessor.DateCreated); // OUTPUT: 2022-07-07 8:00:01
ProcessorFactory processorFactory_1 = new ProcessorFactory();
Thread.Sleep(3000);
var complexProcessor = processorFactory_1.GetInstance(ProcessorType.Complex);
Console.WriteLine(complexProcessor.DateCreated); // OUTPUT: 2022-07-07 8:00:01
第二种方法
第二种方法是使用DI容器。因此,我们需要修改工厂以获取依赖性注入容器的实例:
public class ProcessorFactoryByDI
{
private readonly IDictionary<ProcessorType, IProcessor> _cache;
public ProcessorFactoryByDI(
SimpleProcessor simpleProcessor,
ComplexProcessor complexProcessor)
{
_cache = new Dictionary<ProcessorType, IProcessor>()
{
{ ProcessorType.Simple, simpleProcessor },
{ ProcessorType.Complex, complexProcessor }
};
}
public IProcessor GetInstance(ProcessorType processorType)
{
return _cache[processorType];
}
}
如果您使用ASP.NET Core,那么您可以将对象声明为单身人士:
services.AddSingleton<SimpleProcessor>();
services.AddSingleton<ComplexProcessor>();
它正在发送前飞行请求。我相信这是因为我使用的是HTTP而不是HTTP,并且请求发送给HTTPS。
我有一个问题。我使用以下命令,解决了我的问题。显然,此问题是由于字符串中的负字符而发生的。
new String(Base64.getUrlDecoder().decode());
div = c("A", "B")
div_by = "C"
DF[div] <- DF[div] / DF[[div_by]]
# A B C
# 1 0.17391304 0.34782609 23
# 2 0.01538462 0.03692308 325
# 3 0.10714286 0.41071429 56
# 4 3.47619048 11.14285714 21
# 5 0.10798122 0.10798122 213
数据
DF data.frame(
A = c(4, 5, 6, 73, 23), B = c(8, 12, 23, 234, 23), C = c(23, 325, 56, 21, 213)
)
您不需要太多代码就可以在同一画布上弹跳一些球...
当然,图书馆无需这样做。
- 移动是增加x或y的位置,代码中是
x += vx
- 弹跳我们只是更改方向,您可以看到它在我的代码
vx *= -1
中
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
class ball {
constructor(data) {
this.data = data
}
draw() {
this.data.x += this.data.vx
this.data.y += this.data.vy
if (this.data.x > canvas.width || this.data.x < 0) this.data.vx *= -1
if (this.data.y > canvas.height || this.data.y < 0) this.data.vy *= -1
ctx.beginPath()
ctx.fillStyle = this.data.color
ctx.arc(this.data.x,this.data.y, this.data.radius, 0, 2*Math.PI);
ctx.fill()
}
}
const balls = [
new ball({x: 10, y: 10, vx: 0, vy: 1, radius: 8, color: "pink" }),
new ball({x: 90, y: 90, vx: 0, vy: -1, radius: 8, color: "red" }),
new ball({x: 5, y: 50, vx: 1, vy: 1.5, radius: 8, color: "cyan" })
]
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height)
balls.forEach(b => b.draw())
requestAnimationFrame(animate)
}
animate()
<canvas id="canvas" width=100 height=100></canvas>
或者,您可以像这样更改外面颜色
Theme(
data: Theme.of(context)
.copyWith(colorScheme: ColorScheme.fromSwatch().copyWith(onSurface:Colors.white),
datePickerTheme: DatePickerThemeData());
我对这个问题的解释是,应该生成10种不同的伪随机时间。然后,用户可以通过指定索引值(0-9)来选择一个值。所选时间将被显示,并指示那些时间之间的关系 - 即,之前或之后。
如果是这样,则:
from random import randint
N = 10
PRINT = True
def hhmmss():
return randint(0, 23), randint(0, 59), randint(0, 59)
def format(t):
return f'{t[0]:02d}:{t[1]:02d}:{t[2]:02d}'
tracker = set()
while len(tracker) < N:
tracker.add(hhmmss())
tracker = list(tracker)
while True:
try:
if PRINT:
for i, v in enumerate(tracker):
print(f'{i}. {format(v)}')
print()
if (s1 := int(input(f'Select an index in the range 0-{N-1} (Ctrl-C to exit): '))) < 0 or s1 > N-1:
raise ValueError('Out of range')
if (s2 := int(input(f'Select another index in the range 0-{N-1}: '))) < 0 or s2 > N-1:
raise ValueError('Out of range')
if s1 == s2:
raise ValueError('Selected values must differ')
dt1, dt2 = tracker[s1], tracker[s2]
print('You chose:', format(dt1), 'and', format(dt2))
if dt1 < dt2:
print(format(dt1), 'is earlier than', format(dt2))
else:
print(format(dt1), 'is later than', format(dt2))
except ValueError as e:
print(e)
except KeyboardInterrupt:
break
有没有办法在转换为dataFrame时指定类型?
是的。其他答案在创建数据框后会转换DTYPE,但是我们可以指定创建时的类型。使用 dataframe.from_records
或 read_csv(dtype = ...)
取决于输入格式。
后者有时需要避免使用大数据避免内存错误。
1。 a>
从a
x = [['foo', '1.2', '70'], ['bar', '4.2', '5']]
df = pd.DataFrame.from_records(np.array(
[tuple(row) for row in x], # pass a list-of-tuples (x can be a list-of-lists or 2D array)
'object, float, int' # define the column types
))
输出:
>>> df.dtypes
# f0 object
# f1 float64
# f2 int64
# dtype: object
2。 ...)
如果您是从文件中读取数据时间。
例如,在这里,我们将30m行读取等级
为8位整数,而 genre
at extorical:
lines = '''
foo,biography,5
bar,crime,4
baz,fantasy,3
qux,history,2
quux,horror,1
'''
columns = ['name', 'genre', 'rating']
csv = io.StringIO(lines * 6_000_000) # 30M lines
df = pd.read_csv(csv, names=columns, dtype={'rating': 'int8', 'genre': 'category'})
在这种情况下,我们在加载时将内存使用量减半:
>>> df.info(memory_usage='deep')
# memory usage: 1.8 GB
>>> pd.read_csv(io.StringIO(lines * 6_000_000)).info(memory_usage='deep')
# memory usage: 3.7 GB
这是一种方式到<避免使用大数据的内存错误。加载后,并非总是可以更改dtypes ,因为我们可能没有足够的内存来加载默认类型的数据。
代替直接查询 module.objects.get(id = module_id)
,您可以实例化 module
对象使用:
模块(id = model_id)
,因此将您的方法重写为:
def reorder_modules(self, request, *args, **kwargs):
updatabale_modules = []
for module_id, module_order in request.data.get("modules", {}).items():
_mod = Module(id=module_id)
_mod.order = module_order
updatabale_modules.append(_mod)
Module.objects.bulk_update(updatabale_modules, ["order"])
return Response({"detail": "successfully reordered course modules"}, status=HTTP_200_OK)
我使用Query Inspector调试此视图,它确实仅产生一个DB查询,并且可以与不存在的IDS一起使用
您可以尝试将2D数组重塑为3D数组,并在轴0中具有一个维度:
big_array = np.zeros((1,32,32))
2d_array = np.ones((32,32))
big_array = np.append(big_array, 2d_array.reshape(1,32,32), axis=0)
big_array.shape
>>> (2,32,32)
您应该参考此文档 a>实现材料3类型量表(可以在
作为如何实现的简短说明:
材料3
主题继承,例如:不要忘记在
androidmanifest.xml中指定您的主题:
然后在您的theme.xml中:
至于
标题
vs.title
vs.标签
,您链接的文档对我来说很清楚:标题
样式的高度强调文本,用于简短title> title> title
for Mided强调可能更长的文本,例如,如果您有带标题的卡,则可以使用
标题
样式,如果它说“ ada lovelace”,但是title> title
如果它说“设计是科学和甚至是艺术中断”。You should refer to this documentation to implement the material 3 type scale (link can be found on the material 3 website in this section of the typography documentation by the way).
As a short explanation of how to implement:
Material3
theme, for example:Don't forget to specify your theme in your
AndroidManifest.xml
file:then in your theme.xml:
As for
Headline
vs.Title
vs.Label
, the documentation you linked seems clear to me:Headline
style for high emphasis text that is shortTitle
style for medium emphasis text that may be longerSo for example if you have a card with a title, you may use the
Headline
style if it says "Ada Lovelace" butTitle
if it says "Design is where science and art break even".在材料设计3中使用排版的正确方法是什么?