Python Cheat Sheet

282 words

Python pip配置默认镜像源

description: “Python Pip pypi 在连接pip官网的时候状况不是很稳定。很多国内镜像站可以使用,加速下载。 使用镜像源很简单,用-i指定就行了:

easy_install -i http://pypi.douban.com/simple/ gevent
pip install -i http://pypi.douban.com/simple/ gevent

如果觉得太麻烦,可以配制成默认:

linux下,修改~/.pip/pip.conf,如果没这文件则创建。

windows下,修改%HOMEPATH%\pip\pip.ini,内容为:

[global]
index-url = http://pypi.douban.com/simple

新的版本中会在非https传输的镜像站上报错。 解决办法就是pip.conf的内容改为:

[global]
trusted-host=mirrors.aliyun.com
index-url=http://mirrors.aliyun.com/pypi/simple/

Python生成随机密码

Python Http连接池

2744 words
HTTP是建立在TCP上面的,一次HTTP请求要经历TCP三次握手阶段,然后发送请求,得到相应数据,最后TCP断开连接。 如果我们要发出多个H

Django QuerySet高效读取百万行数据

296 words
How to fetch millions of rows from DataBase by Django Queryset in a memory efficient way? Below is a solution that chunks the QuerySets so they’re only keeping a small subset in memory. While this is somewhat heavier on the database (multiple queries) it seriously reduces the memory usage. Example import gc def lazy_fetch_iterator(table, start_pk=0, chunk_size=1000, *args, **kwargs): """ Get the entire rows of a table by iterating over Django

Django QuerySet缓存和迭代器

535 words
Lazy QuerySet A queryset in Django represents a number of rows in the database, optionally filtered by a query. For example, the following code represents all people in the database whose first name is ‘Dave’: person_set = Person.objects.filter(first_name="Dave") The above code doesn’t run any database queries. You can can take the person_set and apply additional filters, or pass

Django 数据库连接池

4270 words
数据库长连接 长连接是指程序之间的连接在建立之后,就一直打开,被后续程序重用。使用长连接的初衷是减少连接的开销。 先看看官方文档是怎么讲Djan

Django 数据库分表

2087 words
Django ORM没有提供默认的分表功能,给访问分表的数据库带来的不变。那么Django分表怎么实现呢? 分析Django ORM 在实现具体的方案之前,我们先

MySQL索引和锁

4407 words
索引失效的情况 create payment table: create table payment_tab { `id` bigint unsigned auto_increment, `payment_id` bigint unsigned not null, `user_id` bigint unsigned not null, `create_time` int unsigned not null, `update_time` int unsigned not null default 0, `amount` bigint not null default 0, `payment_status` tinyint not null default 0, `ref` varchar(64) default NULL, `payment_type` tinyint not null default 0, primary key (`id`), -- 主键 `idx_user_id` (`user_id`),

程序员的自我修养

3281 words
现在互联网用到的很多技术都相当成熟了。不必高估技术,技术是为业务服务的,认清自己作为研发人员在公司的位置。 比如小米号称黑科技、为发烧而生,实

Add Gitalk for comments in Hugo Blog

354 words

Gitalk is a comment plug based on Github issue api. Hugo can compile the Markdown files with themes and templates into static web files, such as CSS, HTML and JavaScript.

To use Gitalk in the Hugo blog, we need to add Gitalk related code as <div> into the HTML template. Then update the config.toml for Gitalk.

2019 碎碎念

2248 words
2019-01 小时候,吃奶奶做的咸鸭蛋,我只喜欢金黄泛着油香的蛋黄,不喜欢咸咸的蛋白。我把蛋黄挖出来吃掉,总是奶奶就剩下的蛋白下饭。 奶奶爱我,所以把蛋黄

2018 碎碎念

5672 words
01-01 哇哦,不经意间,又是一年过去。这个元旦没有出去溜达,只是在屋里刷一刷算法题。然后,有点感触,为啥在学校的时候没有好好学,现在工作了该补的还

2017 碎碎念

9229 words
01-01 新年第一天,天降瑞雪,真是好兆头。 看BBC地球脉动的纪录片,知道了世上有如此美景,常恨此身局限于一城一地,不能翱翔于天地间,领略异域的风光