V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  MoYi123  ›  全部回复第 15 页 / 共 17 页
回复总数  333
1 ... 7  8  9  10  11  12  13  14  15  16 ... 17  
我用 pg 尝试过类似的功能,用 hll 存用户看过的视频,和你的需求应该差不多 https://github.com/mmooyyii/mmooyyii/blob/master/docs/database/tiplist1.md
2021-01-04 19:55:18 +08:00
回复了 YUX 创建的主题 程序员 请问用 go 刷算法题舒服么(对比 c++)
@also24 leetcode 第一题,O(n2)的解法,python 超时,C++能过。
不清楚你具体要怎样做模糊查询,举几种常见场景
1. 查询 json 中的第一层存在 key 为 1 的行,比如{"1":"abc"},需要在 json 列建 gin 索引
create index test_data1_gin on test using gin (data1);
select * from test where data1 ? '1';

2. 查询 json 中某个具体键的值,比如{'age':18},需要对 json->>'age'建索引
create index test_data1_btree on test using btree ((data1 ->> 'age'));
select * from test where data1 ->> 'age' = 18;

3. like '":2' 比如'{"1":2}', 那这一列不应该存为 json,应该存为 text,然后加上 gin 索引
2020-11-20 23:19:51 +08:00
回复了 tuoov 创建的主题 Python 求助: Python 用 wsgiref 写数据接口
return resp.encode('utf-8') 改成 return [resp.encode('utf-8')] 即可
2020-11-17 10:34:25 +08:00
回复了 specture 创建的主题 Go 编程语言 求推荐个 demo 展示 go 相较于 Python 性能优势的
@tikazyq 你这 python 代码多用了这么多内存,公平吗?
2020-11-06 10:13:27 +08:00
回复了 hopboy 创建的主题 编程 Java 辉煌 20 年:这下“退位让贤”了!
不会有人以为会写 c++等于有能力写 numpy 吧
2020-10-29 15:45:06 +08:00
回复了 stevenkang 创建的主题 Java 有什么办法可以快速的比较两个数组差异
有这发帖的时间,你自己写一个都写完了。
2020-10-28 12:03:07 +08:00
回复了 nash 创建的主题 Go 编程语言 问大家一下 CGO 里面的参数要怎么传?
试了一下,
data := [26]byte{
0x99, 0x88, 0x02, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x0a,
0x00, 0x0e, 0x0c, 0x32, 0x31,
0x30, 0x31, 0x31, 0x38, 0x30,
0x37, 0x30, 0x30, 0x31, 0x30,
0x18}
这样能返回 F9 56
2020-10-27 15:49:56 +08:00
回复了 gdw1986 创建的主题 Python 估计面试没通过,唉
随便写了一个答案,应该是正解

def solution():
____a = [2, 3, 5, 7, 9]
____ret = []
____memo = set()

____def dp(index, acc):
________if (index, tuple(acc)) in memo:
____________return
________else:
____________memo.add((index, tuple(acc)))
________if index == 5:
____________return
________if sum(acc) == 13:
____________ret.append(tuple(acc))
________if sum(acc) >= 13:
____________return
________dp(index + 1, acc[:])
________dp(index, acc[:] + [a[index]])

____dp(0, [])
____return ret
2020-10-23 13:46:00 +08:00
回复了 smallpython 创建的主题 Python 如何使用 Python 的 subprocess 模块调用系统命令 scp?
用 expect 就行了

#!/usr/bin/expect
spawn ssh root@{host} -p {port}
expect "{host}'s password: "
send "{password}"
interact

这是 ssh 的例子
2020-10-18 01:42:14 +08:00
回复了 mathzhaoliang 创建的主题 程序员 一个概率直觉题目
1

从 A 点到 B 点的概率约等于 1/( A,B 距离画一个圆,落在圆上的点的个数)
所以只要距离原点 2-3 个点就很难回到原点了。
2020-10-16 11:50:30 +08:00
回复了 sudoy 创建的主题 Python Python 做一个闹钟,用 while 循环等待时间是否是一个好办法
不如 asyncio.sleep
@starzh 小说章节和用户是多对多的关系,一般来说会建一个只包含用户主键和小说章节的表来储存这种关系。
2020-10-04 18:32:17 +08:00
回复了 nuistzhou 创建的主题 PostgreSQL Postgres to_timestamp() 无法转换 unix epoch 字符串
select TO_TIMESTAMP("unixTime"::int) from item;
@contextmanager
def timeout_signal(second):
____signal.signal(signal.SIGALRM, raise_timeout)
____signal.alarm(second)
____try:
________yield
____finally:
________signal.signal(signal.SIGALRM, signal.SIG_IGN)


def raise_timeout(_signum, _frame):
____raise TimeoutError


def timeout(second):
____def _timeout(fun):
________@wraps(fun)
________def _fun(*args, **kwargs):
____________with timeout_signal(second):
________________return fun(*args, **kwargs)

________return _fun

____return _timeout


@timeout(1)
def f():
____pass


我平时的用脚本里是这样写的,性能好坏不确定。
@xupefei
emails = ['[email protected]']
names = {'alice', 'bob'}
min_name_length = 3
max_name_length = 10

for email in emails:
____for window_size in range(min_name_length, max_name_length):
________left, right = 0, window_size
________while right <= len(email):
____________if email[left:right] in names:
________________print(email)
____________left += 1
____________right += 1

因为 email 地址和 name 肯定都是很小的值,所以下面 2 个循环是 O(1),整体是 O(n)没有问题吧。
除了 ac 自动机外再提供一个写起来简单的方法
假设英文名长度在 3-10 之间,把英文名按长度存到 8 个哈希表中(其实存到一个里也没关系),用长度是 3-10 的滑动窗口遍历邮件地址,窗口每动一下去查一下对应长度的哈希表,时间复杂度也是 O(N)。 应该用几个小时就能跑完。
2020-08-25 21:36:54 +08:00
回复了 xmge 创建的主题 程序员 4 千万的数据量, postgre order by 优化。
min_pk,max_pk = select min(primary_key), max(primary_key) from table where a > xx;
select xxxx from tables where min_pk < pk and pk < max_pk and a > xx order by update limit 100;
可以试一试这样有没有用。
参考了这篇博客
https://github.com/digoal/blog/blob/master/202007/20200710_01.md
2020-08-12 12:41:48 +08:00
回复了 black11black 创建的主题 Python Python 有什么办法异步监控文件修改吗?
同步的库是 select,用 asyncio 应该能改成异步的。
1 ... 7  8  9  10  11  12  13  14  15  16 ... 17  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2068 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 40ms · UTC 05:02 · PVG 13:02 · LAX 22:02 · JFK 01:02
Developed with CodeLauncher
♥ Do have faith in what you're doing.