Dev's Logging

Welcome to my blog !


Mongoose populate limit 的正确用法

Published at May 2, 2020 ·  1 min read

Mongoose 作为 Nodejs 为 MongoDB 构建 Model 层的一个库,使用较为方便,其中的 Ref 与传统 SQL 中的外键较为类似,在 query 时,只需加上 populate 即可将相关的字段查找出来。 但其中有一项需要注意的是: Populate does support a limit option, however, it currently does not limit on a per-document basis. For example, suppose you have 2 stories: If you were to populate() using the limit option, you would find that the 2nd story has 0 fans: That's because, in order to avoid executing a separate query for each document, Mongoose instead queries for fans using numDocuments * limit as the limit....

redis 命名空间通知机制

Published at April 8, 2020 ·  1 min read

命名空间通知 ( Keyspace notifications ),可以让客户端订阅 Pub/Sub 获得下述通知: 所有影响到特定 Key 的命令 所有接受到 LPUSH 命令的 key 所有在 database 0 过期的 key 基于第三条,可以利用此特性,通过 Redis + expire key 构建一个延时通知的服务。但是,基于此构建的通知服务并不能保证可靠,当 Pub/Sub 客户端断开链接并重连后,期间所有的事件将会消失。 https://redis.io/topics/notifications...

is 和 == 在 Python 中的区别

Published at April 8, 2020 ·  1 min read

首先两者在语义上分别是: ==:侧重的是数学上的相等“equality” is:侧重的是身份等同性“identities” 比如 >>> a = [1, 2, 3] >>> b = a >>> a [1, 2, 3] >>> b [1, 2, 3] >>> a == b True >>> a is b True >>> c = list(a) >>> c [1, 2, 3] >>> a == c True >>> a is c False 当将 c 重新赋值后,c 与 a 已经不再是一个对象,所以 “a is c” 为 False 一个特例 nan 不能等于它自己,但是它自己。 >>> nan = float('nan') >>> nan nan >>> nan is nan True >>> nan == nan # !...

Cookie 和 Session 的区别

Published at April 8, 2020 ·  1 min read

首先 Cookie 和 Session 的最大区别是,Cookie 是保存在客户端,与域名相绑定,比如与 www.tonywang.io 绑定的 Cookie 不能被 api.tonywang.io 访问,反之亦然。 而 Session 则是保存在服务器端,每个 session 代表一个用户访问,从用户打开浏览器访问页面开始到用户关闭当前页面结束。 相较于保存在客户端的 cookie,Session 保存在服务器端,安全性更高。 两者主要区别是: Cookie 包含用户信息,保存在客户端,Session 保存在服务器端。 Cookie 不依赖于 Session,而 Session 依赖于 Cookie。 Cookie 的过期时间根据设置而定,Session 在用户关闭浏览器时失效。 Cookie 最大为 4KB,而 Session 则无限制 Cookie 没有一个类似 unsetcookie() 的函数摧毁掉相关信息,而 Session 则有 Session_destroy(). 更多:https://www.guru99.com/difference-between-cookie-session.html...

在 Javascript 中复制对象

Published at February 22, 2020 ·  1 min read

在 Javascript 中当操作 iterator 对象时,不能对当前对象进行增删改操作,若修改,则当前对象则发生了变化,因此需要用到深度拷贝,新建一份后,并对原对象进行操作。 在 Javascript 这类动态语言默认情况下赋值操作均为浅拷贝,也就是只是在内存中建立对源对象建立引用,当原对象改变时,新赋值的仍然会收到影响。所以,这里凸显到了深拷贝的重要性。 针对 dictionary 需要 new_obj = JSON.parse(JSON.stringify(oldobj)) Array 则需要 new_obj = [...oldobj] https://scotch.io/bar-talk/copying-objects-in-javascript...

网络层的通俗解释

Published at January 11, 2020 ·  1 min read

对网络架构的了解是在设计 VPN 软件过程中不可或缺的部分。 根据 OSI( Open Systems Interconnection ) 网络的定义,往往分成 7 层: Physical (线缆,如 RJ 45) Data Link (MAC,交换机) Network (IP, 路由) Transport (TCP,UDP, 端口号) Session (Syn/Ack) Presentation (encription, ASCII,PNG,MIDI) Application (HTTP,FTP) 而根据较新的 TCP/IP 模型,只分成 4 层: Network Access (or Link) Internet Transport (or Host-to-Host) Application(or Process) 网络层定义及其功能 OSI 模型 · Layer 7 (Application): 用户实际中直接接触的一层,比如浏览器或者任何需要网络链接的应用 · Layer 6 (Presentation): 这层负责应用层和其他层之间数据的转换 · Layer 5 (Session): 负责在不同设备间建立链接 · Layer 4 (Transport): 负责系统和 host 之间的数据交换,包括 error-checking 和 数据恢复(data recovery) · Layer 3 (Network): 这层决定了数据是如何发送到接送的设备,负责 packet forwarding,routing,addressing · Layer 2 (Data Link): 将二进制(或 BITs)转换成信号以便让上一层级接触媒介 · Layer 1 (Physical): 实际的硬件,负责在不同媒介之间传输信号...

Widget Communication with Flutter using VoidCallback and Function(x)

Published at December 9, 2019 ·  1 min read

VoidCallback 作为 Widget 之间相互通信的一种很好的方式,在此例中,在 count 中定义 Count 类,作为 stateless 组件,包含 count, VoidCallback 和 Function(),并定义相关的按钮,即可在其父类中 CounterPage 进行操作并传值。 Widget Communication with Flutter using VoidCallback and Function(x)...

Know Your Widgets: Scaffold in Flutter

Published at November 27, 2019 ·  1 min read

这系列是目前为止关于 Flutter 最为详细或易懂的教程,从 Flutter Widget 的源码开始,一个一个特性的讲解和代码测试 Know Your Widgets: Scaffold in Flutter...

Flutter Platform Channels

Published at November 25, 2019 ·  1 min read

Flutter 通过直接在视图层渲染 UI 摆脱了对不同操作系统的诸多限制,而成为跨平台应用开发的首选,但是对于一些与宿主平台深度结合的应用怎么办呢,比如: 通知,应用周期,深链 传感器,摄像头,电池,地理位置,声音,链接 与其他应用分享信息,唤起其他应用 持久化设置,特殊文件夹,设备信息等等 为了保证 flutter 本身不过于臃肿,设计了 “platform channel“ 的简单机制,让 Dart 与 Native 代码进行通信,也就是说,将 Native 代码暴露给 Dart 供其调用,另外也可将 Dart 暴露给 Native 供其调用。 Flutter Platform Channels...

What do mean @escaping and @nonescaping closures in Swift?

Published at November 21, 2019 ·  1 min read

在 Swift closure 中,nonescaping 是默认的,当 closure 作为参数传入的时候,当函数执行完毕后,closure 则随着函数一起在内存中消失,不再存在。 但是在一些场景中,如异步任务和需要将 closure 存储以做后续使用时,则需要将 closure 逃逸出(escaping)当前的函数,以便主体函数推出后,closure 仍然停留在内存中完成后续任务或供其他函数调用。 What do mean @escaping and @nonescaping closures in Swift?...

Tags

abcs accept acid activemq affinity algorithm allocation android array async aws b+tree b-tree backoff benchmark best-practices bfs big-o bigquery bind bitcount blog break broker bubble buffer cache cap cert cgroups channel citus class classmethod closure closures cluster concurrency config consistency consumer container context cookie cors crawler cronjob csrf ctr data-science data-structure database datadog dataflow datascience decorator deepcopy defer dfs distributed django dns docker double-shipping drf ecosia elastic-search enumerate epoll equal errgroup escaping event extra fabric2 facebook-pixel financial-report flask flutter forward-proxy freelance frontend frp garbage-collector gc gcp generator gesture get gil git golang goroutine graphql ha handbook haproxy hash hash-slot hashring hashtable hpa http http-auth http-proxy http_proxy https index init innodb instagram intention-lock intergration interview ios is javascript jinja2 jobboard json jwt k8s kafka kibana kqueue label lambda layer4 layer7 lean levels.io linked-list linux list listen loadbalancer lock logs long-tail lru marketing master matplotlib memory merge metaclass metaprogramming metrics metrics-server microservices mitm mobile model mongo mongoose mq myisam mysql namespace nat netflix network network-extension nginx nodejs nomad nosql notification npm oodesign openssl optimization orm osi pandas parallelism paramiko parkinglot patroni permission pg pipeline pixelme post postgresql postresql prefetch_related prerender private-key process proxy proxycommand put pvm python queue rabbitmq rbac react-native reactive reactjs rebase redis redis-cluster replication resource rest restfulapi retargeting retry revenue reverse-proxy rocketmq rsa rxswift saas scaffold scaleable search-engine security select seo serverless service session set shadosocks shadowsocks shard sharding shell shopify sigint signal sigterm singleton slack slave slow-query sniper sns socket socks5 source-code spa sql sqlalchemy sqs ssh ssl ssl-pinning stack startup state stateful stateless staticmethod string struct swift swiftui switch syscall system-design systemctl tcp tcp-proxy thread tmpreaper token traefik trustkit tunning type typeform udp userdefaults variable vc voidcallback vpn vuejs weak web web-development where widget with yarn zset 削峰 单例模式 宽索引 异步 看源码学-golang 窄索引 解耦 跨域 跳板机


Archives

2020 (6)
2019 (157)
0001 (5)