Sự chia cắt của Việt Nam dưới thời Pháp

Ngày xưa học lịch sử ở trường, vẫn nghe rằng thực dân áp dụng chính sách "chia để trị", rằng dưới thời Pháp, nước ta bị chia thành 3 kì: Bắc Kì, Trung Kì, Nam Kì. Tuy nhiên, mình hồi đó vẫn chưa hiểu nổi sự chia cắt đó, 3 "kì" đó ngăn cách nhau ra sao, vì nhìn quanh thời nay thấy người ta vẫn chia ra mà gọi thành "miền Bắc", "miền Trung", "miền Nam" mà có thấy gì là "chia cắt" đâu, vẫn là 1 đất nước dưới cùng 1 chính quyền, 1 lá cờ, 1 quốc ca.

Rồi nhân cách đây mấy hôm ngồi giải thích cho thằng bạn lí do Sài Gòn - Tp HCM giàu hơn Hà Nội, hay miền Nam nói chung lại giàu hơn miền Bắc, dù Hà Nội là thủ đô thì vấn đề chia cắt này lại được nêu lên, như 1 trong các lý do dẫn đến sự thịnh vượng của Sài Gòn, miền Nam.

Vậy 3 miền đó bị phân biệt nhau thế nào dưới thời Pháp?

Liên bang Đông Dương


Thiết bị mã hóa, smartcard và OpenSC (phần 1)

Tôi mới quay trở lại phát triển tiếp CryptoStick, sau 1 năm gián đoạn. Thực ra công việc của tôi không phải là phát triển phần cứng hay firmware cho nó, mà là mở rộng bộ phần mềm OpenSC để nó có thể nói chuyện, khai thác CryptoStick nói riêng và mọi smartcard theo chuẩn OpenPGP nói chung.

##Thế CryptoStick là gì?

CryptoStick là một loại thiết bị có hình dáng giống bút nhớ USB (pen drive, USB key), nhưng thay vì để lưu trữ dữ liệu như bút nhớ thì nó làm công việc mã hóa, giải mã dữ liệu. Dữ liệu được chuyển vào CryptoStick ở dạng nguyên bản rồi được lấy ra ở dạng đã được mã hóa, hoặc ngược lại.

CryptoStick

...

Flask-SQLAlchemy consuming 100% CPU with multi-thread WSGI server.

These days I has been taking my hairs with a critical issue on my web app, when it eats up to 100% CPU of my VPS.

My web app plays role as an authentication server for splash-protected Wifi network. When people want to use the network, the router (with WifiDog installed) will drive them to a login page first, requiring them to authenticate to get Internet access. With this usage, I don't expect the server to get too many guests. That's why I chose to build it with Flask. For database utilization, I pick SQLAlchemy for safety and because at that time, none of others supports Python3.

The website runs smoothly until one recent day we realized that it took 100% CPU and made the server irresponsive. I tried many ways, including rollbacking the code to old revisions, downgrading the libraries but none helps. At first I ran with CherryPy as WSGI server, then I tried switching to Waitress. No help. When I ran with Flask's built-in Flask server, I noticed that the CPU usage no longer increased to 100%, but in other hand, the web kept hanging. The browser could connect and make HTTP request, but got no response.

After many days trying and testing as well as doing optimize code which exploits database, I try the last option: switching to Gunicorn. Surprisingly, this helps! Though I don't know how Gunicorn fix the problem, or where is the defect in my code, I can assert that it is not because "Gunicorn is superior to others". The difference between Gunicorn and the other forementioned is that one is multi-process type and one is multi-thread (CherryPy, Waitress). My use, my setup of SQLAlchemy/PostgreSQL is somehow compatible with multi-process server rather than multi-thread. But by which manner, I don't know. There are many of setup of Flask+SQLAlchemy+CherryPy out there but no one complaints about 100% CPU issue. It proves that the issue is not CherryPy/Waitress's fault.

...

Tạo nhanh web/FTP server với Python

Khi cần chia sẻ file qua mạng nội bộ, tôi thường nghĩ đến việc chạy 1 web server hay FTP server, nhưng lại ngại cài những phần mềm chuyên dụng như Apache, ProFTP vì tôi chỉ muốn chạy server trong 1 khoảng thời gian ngắn, chỉ phục vụ tải file cho một thư mục nhất định và không muốn cấu hình username/password để login.

Chẳng hạn, nếu cài webserver chuyên dụng như Apache, Nginx thì thường thư mục gốc sẽ là /var/wwww/, nếu muốn chia sẻ file từ 1 thư mục bất kì thì phải tạo symlink vô đây, và phải gõ password để lên sudo. Nếu cài 1 FTP server chuyên dụng như ProFTP thì từ client truy cập vô, luôn đụng phải thư mục root và phải đăng nhập username, password.

Thật mừng là Python có những thư viện đáp ứng rất tốt nhu cầu. Chẳng hạn tôi muốn chia sẻ file từ thư mục /home/hongquan/Documents, tôi chỉ việc vào thư mục đó và chạy:

...

Thu thập log của Flask với Logentries

logentries.com là 1 dịch vụ phân tích, trích xuất thông tin từ log của các ứng dụng. Các log được thu thập và gửi đến server của logentries và được xử lý tại đó. Các log này có thể được thu gom ngay từ chương trình đang chạy của chúng ta mà không phải sinh ra file rồi thu thập file đó. Để làm được việc này, logentries cung cấp 1 số thư viện của những ngôn ngữ hay dùng, để ta có thể tích hợp vào ứng dụng của mình.

Trang web của tôi cũng đang thí nghiệm với dịch vụ này, mặc dù nhu cầu sử dụng cũng chỉ đơn giản là muốn có 1 nơi lưu trữ log, để debug ứng dụng web, chứ không cần phân tích gì. Sau đây là cách tôi sử dụng với Flask, framework được dùng để xây dựng nên website.

Theo cách tổ chức của tôi thì tôi sẽ có 1 file config.py chứa các thông tin cấu hình. Vì source code của website được public nên những thông tin cần bảo mật (key, password...) được lưu trong file secret.py không public và được import vào config.py. Sau khi đăng ký account trên logentries.com và tạo 1 thư mục trên đó, tôi copy lấy token của thư mục đó và gán cho hằng LOGENTRIES_TOKEN trong config (config.pysecret.py ở trên).

logentries chỉ nhằm dùng khi chạy ở production mode (chứ ở development mode thì log luôn ra Terminal cho tiện làm việc) nên tôi sẽ cấu hình để sử dụng logentries trong file wsgi.py, là file mà tôi dùng để chạy website ở production. Đây là nội dung của file:


Hello world

Hello,

Today I start new blog system, to replace my old blogs at My Opera and Wordpress, and also to possess a website with my own domain name.

This website is started as a blog, but I have been planning to add something fun to it. The idea has existed long time ago, but because of lack of money and time, I could not start the work until now.

Well, people may say that there are many good blogging system out there, with the most noteworthy Wordpress, why not just pick one and place in some shared host, which is rather cheap and doesn't take long time. The reason why I don't do is that I want to code some features by my own. I no longer like PHP, instead I prefer Python, so I don't want to code for Wordpress. Besides, I want to write about programming (primary in Python, of course), Linux, Open source, so I want the blog system to support code highlighting, and support to write in Markdown or reStructedText, which is my new choice of writing format. Wordpress is a good platform and revolve so fast that all plugins of my need (Markdown, code highlighting) become incompatible with newest version of Wordpress.