This blog is rated  R⃣ , viewer discretion is advised

Add UTF-8 BOM header to Flask-Admin export

A simple trick to add additional bytes prepending Flask's stream_with_context

from flask_admin.contrib.sqla import ModelView
from itertools import chain

class MyAdminView(ModelView):
    can_export = True
    column_export_list = ['field1', 'field2']

    def _export_csv(self, return_url):
        r = super(MyAdminView, self)._export_csv(return_url)
        r.response …

Posted

stdout

徐州丰县,以及孝文化

抬一张地图出来,

鲁苏豫皖四省,如果让你选一个最乱的地,你可能选哪里呢?

说起来,徐州对我的印象,只是《三国演义》上一 …

Posted

stdout

Microsoft 官网的 403 错误

$ curl -H "User-Agent: User-Agent: Mozilla/5" -kvs 'http://www.microsoft.com'
*   Trying 118.123.102.107...
* TCP_NODELAY set
* Connected to www.microsoft.com (118.123.102.107) port 80 (#0)
> GET / HTTP/1.1
> Host: www.microsoft.com
> Accept: */*
> User-Agent: User-Agent: Mozilla/5
>
< HTTP/1.1 403 Forbidden
< Server …

Posted

stdout

Chrome 阉割指南

不折腾不舒服。继之前 Edge调教 之后记录一下 Chrome V70怎么阉割。

下载:

win 32 | win 64 | Mac

上面的链接已经年久失修了,对比了一下获取 …

Posted

stdout

认识「洋节」

都说 xmas eve 是洋节,我们就来数一数到底有哪些洋节

  1. 元旦1月1日。由北「洋」军阀袁世凯设立。依据是内务部总长朱启钤《定四 …

Posted

stdout

如何可视化跟踪分析 Python import 耗时

首先在本地安装 pip install tuna

然后跑个分,需要 CPython >= 3.7,输入

PYTHONPROFILEIMPORTTIME=1 python3 myscript.py 2>1.log

tuna

然后 tuna 1.log ,会自动打开浏览器围观 import 耗时分布 …

Posted

stdout

FastAPI/Starlette支持静态文件支持SPA

FastAPI 官方支持 from fastapi.staticfiles import StaticFiles 充当一个静态文件服务器

其实实现是 starlette。这玩意可以在 directory 下放一个 404.html,恰好单页应用也需要用 …

Posted

stdout

Python 3.X ctypes 和 greenlet size changed 坑三则

安装 setup.py 的时候 No module named '_ctypes' 报错

  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/usr/local/python3/lib/python3.9/site-packages/setuptools/__init__.py", line 18, in <module>
      from setuptools.dist import Distribution
    File "/usr/local/python3/lib/python3 …

Posted

stdout

reverse proxy FastCGI (fcgi) with uWSGI

People are still using FastCGI, and it's hard. I used uWSGI to convert FCGI traffic to regular http/1.0 so I can keep my existing http service running without apache mod_fcgi shit.

CGI environ variables

This is some ancient knowledge, better keep them noted

KEY description
AUTH_TYPE …

Posted

stdout

淘宝同一手机最多绑定6个小号

总结一些没用的知识

  1. 淘宝/阿里账号,可以一个手机最多绑定6个账号。淘宝注册的时候点击「企业注册」然后用邮箱注册,最 …

Posted

stdout

《兵车行》竖排实验

群里闲聊起究竟生男好还是生女好,就想起了这首诗

兵车行——杜甫 车辚辚,马萧萧,行人弓箭各在腰。 耶娘妻子走相送,尘埃不 …

Posted

stdout

Re-index page on Google Search Console

Request indexing webpage with Google used to be fun and simple, now it's a tedious task especially when you have tons of old pages ready to be crawled yet Google is reluctant to move.

Here is a simple script to speed up the stacks of page you have click in …

Posted

stdout

美国自来水 TDS 这么高?

看到个讲 Solar Roof 视频

他们家的 filtered tap water 测出来 TDS 为 358ppm

tap water 测出来 TDS 是 435 ppm,

说加州的市政供水很硬,有大量的钙、镁离子。都不 …

Posted

stdout

TiDB 的日期比较和 MySQL 不兼容

MySQL的

> select VERSION()
+-----------+
| VERSION() |
+-----------+
| 8.0.15-6  |
+-----------+


> select NOW() > '';
+------------+
| NOW() > '' |
+------------+
| 1          |
+------------+

> show warnings;
+---------+------+----------------------------------------+
| Level   | Code | Message                                |
+---------+------+----------------------------------------+
| Warning | 1292 | Truncated incorrect datetime value: '' |
+---------+------+----------------------------------------+

TiDB:

> select VERSION()
+--------------------+
| VERSION()          |
+--------------------+
| 5.7.25-TiDB-v5.1.0 |
+--------------------+
1 row in set

> select NOW() > '';
+------------+
| NOW() > '' |
+------------+
| <null>     |
+------------+

> show warnings;
+---------+------+------------------------------+
| Level   | Code | Message                      |
+---------+------+------------------------------+
| Warning | 1292 | Incorrect datetime value …

Posted

stdout

MySQL on duplicate key in SQLAlchemy

A simple function to upsert something atomically into MySQL

def upsert(val1, val2, **kwargs):
    """upsert val1-val2 pair into mysql and return the pk"""
    from sqlalchemy.dialects.mysql import insert
    from sqlalchemy.sql.expression import func

    # this val1-val2 pair should have UNIQUE KEY constraint in MySQL table.
    stmt = insert(MyModel.__table …

Posted

stdout

Win10 自动设置开机锁屏壁纸

Win10启动后,锁屏界面有一些每天更新的漂亮的墙纸,但是每个用户进去却只能看到默认的墙纸,不能自动切换。很是遗憾,于 …

Posted

stdout

Mac 命令行终端里获得视频文件的长度

记录一下,Mac OS X 10.6.8 或更高版本:

mdls -name kMDItemDurationSeconds -name kMDItemFSName  1.mp4

这命令有一个很神经病的一点,同一个 .mp4 文件,获取只读的 TF 卡上的 …

Posted

stdout

FastAPI/Starlette+Requests实现反向代理

因为某些拉垮的业务需要,不得不在代码里去反向代理别的 HTTP API

一般格式如下:

@app.get('/other/{other_path:path}')
@app.post('/other/{other_path:path}')
async def other_api(other …

Posted

stdout

OpenWRT 实现 Cloudflare 动态域名 dynamic DNS

首先得有公网 IP (废话),然后你得 OpenWRT 路由器桥接直拨。

这个方法的核心是通过 ifstatus wan | jsonfilter -e '@["ipv4-address"][0].address' 命令得到本机 WAN 的公网 IP。

根 …

Posted

stdout

nsq-py, pynsq, gnsq compared

nsq is a lightweight message queue like Kafka/RabbitMQ/RocketMQ/RedisQueue/Celery.

For python bindings there ware three libraries out there:

  • pynsq: the official build, but requires tornado
  • gnsq: the gevent only consumer/publisher, might have race condition in state machine. Don't use.
  • nsq-py: select() based, but compatible with gevent …

Posted

stdout

人和动物有什么区别

上下班通勤极度无聊,就趁着罗胖的10元优惠券买了 学而时嘻之 博主开设的 199元的 精英日课。之前一直讨厌这个名字,但 …

Posted

stdout

javascript 一句话算农历

同步发帖在 v2ex

今天发现 Intl 这个 ECMAscript 内置对象,可以一句话算农历。

new Date().toLocaleString('zh-CN-u-ca-chinese').replace(/(\d+)\s*?年/, (_,y)=>"甲乙丙丁戊己庚辛壬癸".charAt((y-4)%10) + "子丑 …

Posted

stdout

Covid-19 一些基本常识

  1. 检测 Covid-19 有几种手段:
  • 症状。比如发烧,呼吸困难,血氧浓度低
  • 影像。比如胸部 CT
  • 抗体。IgG/IgM。耗时短。比如15分钟。但是正确率 75%
  • 核酸 …

Posted

stdout

语音编程 设想

HN头条 上看到有人说用语音识别 写代码。

现在是疫情在家上班期间,感觉还是可以试试。毕竟公共办公环境搞这个不太 …

Posted

stdout

减速玻璃的原理

原来发表在 zhihu,可惜不绑手机不让发帖了。就自己写个 blog 备忘一下。

减速玻璃这个都会传说,买车前听说过,买车后也百思不 …

Posted

stdout

一些重要问题的答案 Important Why's

发现 blog 越来越喜欢记录一些哲学问题。。。

记录一些重要问题的答案,有些是自己想出来的,有些是网上抄别人的,有些是被别 …

Posted

stdout

Fix Paladins stuck at Completing Login

Paladins is one of the F2P games on Steam. It's called 枪火游侠 in Chinese market with Tencent as its Partner operator.

To play it on Steam:

  1. Add any game to cart
  2. Modify region to US on the checkout page
  3. Type the following script into browser's DevTool
    jQuery …

Posted

stdout

公司文化的三种类型

最近播音737两次空难闹得全球沸沸扬扬,中国民航局敢为天下先直接停飞,FAA 最后也只能跟进然后全球停飞,风暴的中心 …

Posted

stdout

Open Source projects Chinese companies and individuals contributed to

Chinese companies have very little presence online and many people may believe that Chinese are reluctant to engage in open source projects.

Last year, @filmaj used the GitHub REST API to pull public profile information from all 2,060,011 GitHub users who were active in 2017 (10+ commits to …

Posted

stdout