My Week 0 in AI Era

The past week was so exciting that I skipped a couple of meals and had sleepless nights. Apparently, I am late to the party: there have been many significent moments last year or ealier that should have marked the beginning of the AI era for human being (much more appropriate than last week), while for me, it was not until last week that I got the feeling of advencing into AI era.

I learnt a plenty of things last week in order to get to the speed. This post notes down those AI techniques which excite me.

Read More

Load Grep Results Into Vim

When coding, I often need to search for the references of a variable or a function across multiple files. Usually I enter command mode of vim and do a grep command, memorize the search results and open the files having hits. This common pattern could be dramatically accelerated by a user-defined vim command:
:command Gitgrep :lex system("git grep -n " . shellescape(getreg('/'))).

Read More

Makefile MAKEOVERRIDES

TL;DR The variable MAKEOVERRIDES passes the variables defined in the make command line to sub-makes (even those make invoked indirectly). Emptying MAKEOVERRIDES can prevent sub-makes from picking up variables unexpected.

Read More

Python C API

It is usually easier to write and debug Python scripts than do it in C/C++, while for heavy computation tasks, C or C++ programs can run much faster. A common strategy to get the best of both worlds is writing the computation kernels in C/C++ and binding Python APIs to invoke the computation kernels in Python scripts. Python C API exists exactly for the purpose of binding Python with C/C++.

I learnt Python C API recently, and this post records my practice of creating a Python package, txt2qr, that uses C library libqrencode. Txt2QR generates the QR code (in SVG format) of a given text, and is easily integrated into a Django app.

Read More

Abacus: Expenses Bookkeeping Tool

About a year ago, I started a side project for fun as well as the need to keep track of my daily expenses in my own way. The outcome, Abacus, is an expenses bookkeeping web service (still under active development, but in good shape), which I have been using for months.

Abacus uses Django as the website backend engine, providing webpages for users to record, view and manage their daily expenses transactions in groups. Additionally, Abacus also has a Telegram bot interface to accomplish the same bookkeeping actions in Telegram chat. Abacus is meant to be deployed on a home PC as a self-hosted web service for personal use.

Read More

Linux From Scratch

I got to know Linux From Scratch soon after I bought my desktop machine. My first attampt failed at making gcc to setup the “cross-compile” environment. About four years later I picked it up and finally went through my first pass of building LFS. My destop machine has been running LFS happily since then. Two experiences are briefly note down: 1) break dependency circle with building twice; 2) reconfig kernel and build with additional modules.

Read More

Hash Strings at Compile Time

It is convenient to index data stored in map, and hash table by name, and the theoretical time complexity is as low as O(logn) or O(1). Nevertheless, the overhead to convert a string name into the key to index the map or hash table structure could hurt the performance sometimes. This post demonstrates a technique do the hash computation on constant strings earlier at compile time.

Read More

C++ Template Method Polymorphism

Polymorphism in C++ means a function or object of the same identity/name behaves differently under different scenarios. A common example of polymorphism is a derived class could override the method definition in the base class if it is marked virtual and a base class pointer would invoke the proper definition according to which class instance it is actually pointing to.

Polymorphism reduces trivial programming efforts in some cases and is very useful. Template method for generic programming is another style of polymorphism done at compile time to avoid unnecessary code duplication and eases the burden of programmers (see my earlier post series). However, C++ forbids template methods to be marked as virtual. So could somehow we have it all?

Read More