Category: Python

  • Log rotation for uwsgi and python related applications

    Don’t send SIGHUP or restart your servers if you want to do log rotation. SIGHUP is NOT used for log rotation, but used for configuration/module reload. Take uwsgi as example, as Managing the uWSGI server described, SIGHUP will gracefully reload all the workers and the master process. Thus, the newly coming connection cannot be accepted…

  • Yet another opml checker

    Just wrote a opml checker to test invalid rss feeds for my feedly subscriptions. The biggest motivation is that 無名小站 was closed at 26 December, 2014. Most of my friends’ blogs cannot be reached anymore. Usage: $ opml-checker feedly.opml Source Code: Performance: It analyzes my 510 feeds in 80 seconds.

  • Use connection pool in Python Requests

    Requests is a great library for performing HTTP related request and response. As it’s description, it supports connection pool automatically. Requests takes all of the work out of Python HTTP/1.1 — making your integration with web services seamless. There’s no need to manually add query strings to your URLs, or to form-encode your POST data.…

  • may be slow in some cases

    A simple test using Python 3.3 Sample Code Result References: doesn’t batch function arguments by chunks

  • Using wheel for python deployment

    I’ve discussed with my colleagues for better deployment process which replaces existing RPM based deployment. There are several projects provides binary format, virtualenv manipulation, and caching for python deployment. For example: Terrarium pip-accel They are both great projects, but somehow our requirements are trivial Install python package system-wise (may not be virtualenv) Avoid binary recompile,…

  • Use textwrap.dedent

    If you’re writing long string in python, it will break indent and look like the followings You can use textwrap.dedent to solve it

  • Trend Writing Secure Code Materials

    這應該是我最後一次教趨勢的 Engineer Training Program: Writing Secure Code 在今天把成績送出去之後,留一下紀念 這原本是從 Microsoft 的 Writing Secure Code, Second Edition 找一些教材出來上。 但是有一些東西不見得要看,也有一些更重要的東西想多說一下。 幾次作業分別是包含 Buffer Overflow SQL Injection CSRF XSS Password Storage Threat Modeling 我自已比較喜歡的幾點是 用 gdb 觀察 buffer overflow 的狀況,跟設計 payload 用 Flask 做簡單的 web framework 實際請同學玩 blind sql injection,也可以試試看 sqlmap 使用 SQLAlchemy 跟 MySQL-Python 避免 SQL Injection 讓他們實際使用…

  • 5月「測試可以簡單一點嗎?」投影片

    Source Code Slides 測試可以簡單一點嗎? 內容包含 tox 跟 testfixtures 的一些簡單的介紹

  • Using tox and jenkins to have python continuous integration environment

    在看幾個 github 上的專案,像是 celery 都會發現他們的 repo 有一個 tox.ini,剛好手邊有個小小的 python 專案,就順便看一下 tox 是什麼。 節錄 tox 官網的介紹。 Tox as is a generic virtualenv management and test command line tool you can use for: checking your package installs correctly with different Python versions and interpreters running your tests in each of the environments, configuring your test tool of…

  • Filter is good

    Java PHP Python JavaScript 憑著直覺寫的,如果不能動的話再說 XD 這種寫法通常好讀又簡單,不過有些語言要寫的囉嗦一點…