计算机网络学习

计算机网络概述 OSI七层协议 物理层 传输的数据类型:比特流 主要定义物理设备标准,如网线的接口类型、光纤的接口类型、各种传输介质的传输速率等。它的主要作用是传输比特流(就是由1、0转化为电流强弱来进行传输,到达目的地后在转化为1、0,也就是我们常说的数模转换与模数转换)。这一层的数据叫做比特 数据链路层 传输的数据类型:帧 ...

5 min · 2092 words · Luenci

转载 | C结构体打包技艺

失传的 C 结构体打包技艺(转) 转自: https://fishc.com.cn/forum.php?mod=viewthread&tid=83418&extra=page%3D2%26filter%3Dtypeid%26typeid%3D571 作者:Eric S. Raymond 原文链接:http://www.catb.org/esr/structure-packing 谁应阅读本文 如果你在内存容量受限的嵌入式系统中写程序,或者编写操作系统内核代码,就有必要了解这项技术。如果数据集巨大,应用时常逼近内存极限,这项技术会有所帮助。倘若你非常非常关心如何最大限度地减少处理器缓存段(cache-line)未命中情况的发生,这项技术也有所裨益。 2013 年底,我大量应用了一项 C 语言优化技术,这项技术是我早在二十余年前就已掌握的,但彼时之后,鲜有使用。 通过精心调整结构成体员的顺序,可以在这种情况下大幅减少内存占用。其效果显著——在上述案例中,可以减少 40% 的内存空间。程序应用于更大的软件仓库,也不会因内存耗尽而崩溃。 事出有因。计算机科学课程(正确地)引导人们远离微观优化,转而寻求更理想的算法。计算成本一路走低,令压榨内存的必要性变得越来越低。旧日里,黑客们通过在陌生的硬件架构中跌跌撞撞学习 —— 如今已不多见。 ...

7 min · 3232 words · Luenci

转载 | Django的ORM字段介绍

Django的Field详解(转载) 本文转载于:https://www.cnblogs.com/ellisonzhang/p/10679054.html 字段 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 1、models.AutoField 自增列 = int(11) 如果没有的话,默认会生成一个名称为 id 的列,如果要显示的自定义一个自增列,必须将给列设置为主键 primary_key=True。 2、models.CharField 字符串字段 必须 max_length 参数 3、models.BooleanField 布尔类型=tinyint(1) 不能为空,Blank=True 4、models.ComaSeparatedIntegerField 用逗号分割的数字=varchar 继承CharField,所以必须 max_lenght 参数 5、models.DateField 日期类型 date 对于参数,auto_now = True 则每次更新都会更新这个时间;auto_now_add 则只是第一次创建添加,之后的更新不再改变。 6、models.DateTimeField 日期类型 datetime 同DateField的参数 7、models.Decimal 十进制小数类型 = decimal 必须指定整数位max_digits和小数位decimal_places 8、models.EmailField 字符串类型(正则表达式邮箱) =varchar 对字符串进行正则表达式 9、models.FloatField 浮点类型 = double 10、models.IntegerField 整形 11、models.BigIntegerField 长整形 integer_field_ranges = { 'SmallIntegerField': (-32768, 32767), 'IntegerField': (-2147483648, 2147483647), 'BigIntegerField': (-9223372036854775808, 9223372036854775807), 'PositiveSmallIntegerField': (0, 32767), 'PositiveIntegerField': (0, 2147483647), } 12、models.IPAddressField 字符串类型(ip4正则表达式) 13、models.GenericIPAddressField 字符串类型(ip4和ip6是可选的) 参数protocol可以是:both、ipv4、ipv6 验证时,会根据设置报错 14、models.NullBooleanField 允许为空的布尔类型 15、models.PositiveIntegerFiel 正Integer 16、models.PositiveSmallIntegerField 正smallInteger 17、models.SlugField 减号、下划线、字母、数字 18、models.SmallIntegerField 数字 数据库中的字段有:tinyint、smallint、int、bigint 19、models.TextField 字符串=longtext 20、models.TimeField 时间 HH:MM[:ss[.uuuuuu]] 21、models.URLField 字符串,地址正则表达式 22、models.BinaryField 二进制 23、models.ImageField 图片 24、models.FilePathField 文件 参数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 1、null=True 数据库中字段是否可以为空 2、blank=True django的 Admin 中添加数据时是否可允许空值 3、primary_key = False 主键,对AutoField设置主键后,就会代替原来的自增 id 列 4、auto_now 和 auto_now_add auto_now 自动创建---无论添加或修改,都是当前操作的时间 auto_now_add 自动创建---永远是创建时的时间 5、choices sex_choice=((“F”,“FEMAL”),(“M”,’Male’),) #admin专用下拉选项 gender=models.CharFiled(max_length=2,choice=sex_choice) 6、max_length 7、default 默认值 8、verbose_name Admin中字段的显示名称 9、name|db_column 数据库中的字段名称 10、unique=True 不允许重复 11、db_index = True 数据库索引 12、editable=True 在Admin里是否可编辑 13、error_messages=None 错误提示 14、auto_created=False 自动创建 15、help_text 在Admin中提示帮助信息 16、validators=[] 17、upload-to

4 min · 1664 words · Luenci

转载 | Django重定向指南

原文转载自:https://www.jianshu.com/p/5e322fb5b61c(简书:爱吃鱼de大猫) 当你使用 Django 框架构建 Python Web 应用程序时,在某些时候需要将用户从一个URL重定向到另一个URL。本指南将提供 HTTP 重定向所需要了解的所有知识,以及在 Django 中该如何处理。 ...

20 min · 9778 words · Luenci

转载 | Python后端架构演进

Python后端架构演进 本文转自python社区:https://www.pythontab.com/html/2018/pythonweb_0725/1329.html ...

5 min · 2197 words · Luenci

转载 | Python的asyncio(协程)

本文转载自:https://pythonav.com/wiki/detail/6/91/ 1.协程 协程(Coroutine),也可以被称为微线程,是一种用户态内的上下文切换技术。简而言之,其实就是通过一个线程实现代码块相互切换执行。例如: 1 2 3 4 5 6 7 8 9 10 11 12 def func1(): print(1) ... print(2) def func2(): print(3) ... print(4) func1() func2() 上述代码是普通的函数定义和执行,按流程分别执行两个函数中的代码,并先后会输出:1、2、3、4。但如果介入协程技术那么就可以实现函数见代码切换执行,最终输入:1、3、2、4 。 在Python中有多种方式可以实现协程,例如: greenlet,是一个第三方模块,用于实现协程代码(Gevent协程就是基于greenlet实现) yield,生成器,借助生成器的特点也可以实现协程代码。 asyncio,在Python3.4中引入的模块用于编写协程代码。 async & awiat,在Python3.5中引入的两个关键字,结合asyncio模块可以更方便的编写协程代码。 1.1 greenlet greentlet是一个第三方模块,需要提前安装 pip3 install greenlet才能使用。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 from greenlet import greenlet def func1(): print(1) # 第1步:输出 1 gr2.switch() # 第3步:切换到 func2 函数 print(2) # 第6步:输出 2 gr2.switch() # 第7步:切换到 func2 函数,从上一次执行的位置继续向后执行 def func2(): print(3) # 第4步:输出 3 gr1.switch() # 第5步:切换到 func1 函数,从上一次执行的位置继续向后执行 print(4) # 第8步:输出 4 gr1 = greenlet(func1) gr2 = greenlet(func2) gr1.switch() # 第1步:去执行 func1 函数 注意:switch中也可以传递参数用于在切换执行时相互传递值。 1.2 yield 基于Python的生成器的yield和yield form关键字实现协程代码。 1 2 3 4 5 6 7 8 9 10 11 12 def func1(): yield 1 yield from func2() yield 2 def func2(): yield 3 yield 4 f1 = func1() for item in f1: print(item) 注意:yield form关键字是在Python3.3中引入的。 1.3 asyncio 在Python3.4之前官方未提供协程的类库,一般大家都是使用greenlet等其他来实现。在Python3.4发布后官方正式支持协程,即:asyncio模块。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import asyncio @asyncio.coroutine def func1(): print(1) yield from asyncio.sleep(2) # 遇到IO耗时操作,自动化切换到tasks中的其他任务 print(2) @asyncio.coroutine def func2(): print(3) yield from asyncio.sleep(2) # 遇到IO耗时操作,自动化切换到tasks中的其他任务 print(4) tasks = [asyncio.ensure_future( func1() ), asyncio.ensure_future( func2() )] loop = asyncio.get_event_loop()loop.run_until_complete(asyncio.wait(tasks)) 注意:基于asyncio模块实现的协程比之前的要更厉害,因为他的内部还集成了遇到IO耗时操作自动切花的功能。 1.4 async & awit async & awit 关键字在Python3.5版本中正式引入,基于他编写的协程代码其实就是 上一示例 的加强版,让代码可以更加简便。 Python3.8之后 @asyncio.coroutine 装饰器就会被移除,推荐使用async & awit 关键字实现协程代码。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import asyncio async def func1(): print(1) await asyncio.sleep(2) print(2) async def func2(): print(3) await asyncio.sleep(2) print(4) tasks = [ asyncio.ensure_future(func1()), asyncio.ensure_future(func2())] loop = asyncio.get_event_loop()loop.run_until_complete(asyncio.wait(tasks)) 1.5 小结 关于协程有多种实现方式,目前主流使用是Python官方推荐的asyncio模块和async&await关键字的方式,例如:在tonado、sanic、fastapi、django3 中均已支持。 接下来,我们也会针对 asyncio模块 + async & await 关键字进行更加详细的讲解。 ...

21 min · 10099 words · Luenci

转载 | windows 配置同时使用 Gitlab、Github、Gitee(码云) 共存的开发环境

原文链接:https://blog.csdn.net/flowerspring/article/details/104962002 清除 git 的全局设置(针对已安装 git) 新安装 git 跳过。 若之前对 git 设置过全局的 user.name 和 user.email。 类似 (用 git config –global –list 进行查看你是否设置) 1 2 $ git config --global user.name "你的名字" $ git config --global user.email "你的邮箱" 必须删除该设置 1 2 $ git config --global --unset user.name "你的名字" $ git config --global --unset user.email "你的邮箱" 生成新的 SSH keys 1)Gitee 密钥 跳转到keygen目录,git bash here。 先键入第二行命令 第四行 指定 id 文件名称为id_rsa_gitee 第五、六行 设置无密码,直接回车两次。 会在keygen目录下生成文件 id_rsa_gitee 和 id_rsa_gitee.pub。 id_rsa_gitee.pub中存放的是公钥。 把公钥保存到gitee网页密钥中。 1 2 3 4 5 6 7 8 9 10 11 12 honey@honey MINGW64 /d/keygen $ ssh-keygen -t rsa -C [email protected] Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/honey/.ssh/id_rsa): id_rsa_gitee Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in id_rsa_gitee. Your public key has been saved in id_rsa_gitee.pub. The key fingerprint is: ... The key's randomart image is: ... 也可指定文件路径,方便后面操作:~/.ssh/id_rsa.gitlab ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C "[email protected]" 直接回车3下,什么也不要输入,就是默认没有密码。 注意 gitee 和 gitlab 的文件名是不同的。 ...

4 min · 1696 words · Luenci

高德无人机科技研发岗(测试工程师)面试总结

高德无人机科技研发岗(测试工程师)面试总结 技术面 1.在51job上面投递的简历,本科院校“双非”,有一些项目经验。 2.面试的时候是技术工程师来一面。问了我关于C++问题(本人主攻Python),有点把我问住了, ...

2 min · 553 words · Luenci