杂记2018/10-12

Author Avatar
Marmot 10月 11, 2018
  • 在其它设备中阅读本文章

2018-12-24

赶项目,加上泰国玩了一圈,写还是得继续得

关于预编译

  1. Prepared语句只在session的整个生命周期中存在,一旦session结束,Prepared语句也不存在了。如果下次再使用需重新创建。
  2. Prepared语句不能在多个并发的client中共有。
  3. prepared语句可以通过DEALLOCATE命令清除。
  4. 当前session的prepared语句:select * from pg_prepared_statements;
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    cursor = connections['timescale'].cursor()

    try:
    statement = f"""
    PREPARE q(text) AS
    SELECT {','.join(fields)} FROM {tb_name}
    WHERE {tb_name}.timestamp >= to_timestamp($1, 'yyyy-MM-dd hh24:mi:ss') - interval '1 minutes'
    ORDER BY {tb_name}.timestamp
    limit 1;
    """
    cursor.execute(statement)
    while t <= end_time:
    sql = f"""execute q('{t.strftime("%Y-%m-%d %H:%M:%S")}')"""
    cursor.execute(sql)
    r = cursor.fetchone()
    if r:
    r = map(lambda x: x if not isinstance(x, bool) else int(x), r)
    rows.append(list(r))
    else:
    x = [None] * len(fields)
    x[0] = (t + timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S")
    rows.append(x)
    t = t + timedelta(minutes=60)
    # 务必关闭数据库链接
    finally:
    cursor.close()

2018-11-20

###《古典密码学》

####凯撒密码(位移单词)
英文文本在足够量的情况下,单词使用频率是接近的,称为指纹,利用频率近似对比,可以有效的破解凯撒密码

####多表密码(根据规律位移单词)
使用多表密码可以淡化指纹,通过间隔取指纹对比,可以破解多表密码,但是需要耗费时间去确定间隔

####使用随机性对密文进行加密

####使用组合来判定是否是真随机(频率稳定性)

####重复会减少密码空间

####完全保密性

####随机数种子生成对随机数具有周期性,和种子的长度正相关(伪随机)

###《现代密码学》

####质数螺旋
任意数字只有一种质因数分解

2018-11-09

django exclude不同于filter
However, unlike the behavior when using filter(), this will not limit blogs
based on entries that satisfy both conditions. In order to do that, i.e. to
select all blogs that do not contain entries published with “Lennon” that were
published in 2008, you need to make two queries:

2018-10-11

放假完了,加上突然的紧迫项目,以及突然的紧迫项目还提前了
记录处理会议室订单的解决方案:
1.由于会议室预定是半小时算一次钱,使用桶来计算,在会议室的信息中存一个长度为48的list,索引第n个半小时,值为这半小时的价格,取时间区间求和即可
2.查找会议室是否被预定,需要两头取值 Q(start__lt=start, finish__gt=start) | Q(start__lt=end, finish__gt=end)
形象的例子就是,从侧面能不能同时看全两个列车,并且一辆列车不能完全挡住另一辆