カテゴリー

メタ情報

Background

I would like to add crates.io to Firefox Quantum but got an error saying that it cannot add it via https://crates.io/opensearch.xml
So here comes a short note of manually adding a search engine to Firefox Quantum.

Step 1: Extract search.json.mozlz4

Definitions of installed search engines are stored in the file search.json.mozlz4 which is located in your profile folder. Under Linux it’s usually ~/.mozilla/firefox/XXXXXXXX.default. If you’re unsure about it, run firefox -profilemanager (or firefox-developer-edition -profilemanager) to find it out.

The hash function for loadPathHash can be found in Mozilla’s source code. I have copied it here for your convenience. Open a Browser Console in Firefox, paste the following function, call getVerificationHash(loadPath) and the result is what you need in loadPathHash.

KDE Plasma had been taking unbearably long to startup since an update one or two months ago for me. I thought it was caused by a bug of Qt but things turned out that this was not the fix to my problem.

Then I suddenly noticed that actually only the initial start after a boot would be slow, subsequent ones are way faster. So it must be a caching issue. I have mounted my /tmp in memory and moved a bunch of hot files into it and all of them will be lost after reboot. This is a common approach to make SSDs live longer and improve performance that could be found in many tutorials.

But some caches are designed to be reused after reboot. By default, they are often located in ~/.cache or /var/cache and you have to be really careful when relocating them, e.g. XDG_CACHE_HOME. Many Qt compilation caches are stored in this path and if you erase them after shutdown, it will have to re-compile them again on each boot.

Git automatically calls less if the output is fairly long in the terminal. It is rather useful to avoid terminal history being violated and allows user to search through the output.

However, plain less isn’t the perfect solution. What I (and I believe many others also) want is:

Always colored output

Scrolling by touchpad or mouse

Auto-quit-if-one-screen

less -+F -+X -+S does everything except the last one. But if I remove -+F, there will be no output in case of one-screen; if I remove -+X as well, the output is back but it disables scrolling. I opened a thread in StackExchange but no satisfying answers came up.

I’m not a fan of rustup and I’ve been always using the installation scripts in official packages.

However, things have become troublesome since I started cross-compilation. Rust have provided their pre-compiled standard libraries in Rust Archives which saved me plenty of time. However each time a new version is released, I have to manually download and install a number of packages and I went through a lot of pain.

So finally I decided to write an updating script for Rust. It is capable of handling rustc, libraries as well as the source code (by detecting environment variable). I deem that it could work on most Linux distros. You will need aria2c as the downloader and of course you can change it easily.

Cause: The names of local and remote branches are not the same
Solution: git push remote_repo HEAD:remote_branch OR (suggested) git config push.default upstream

I’m currently working as an intern developer in an eHealth startup. They’re using the hosts from Aptible to provide their services to customers.

Aptible is generally a Docker (heroku) based hosting and every time when you push the code into a certain Git repository, which is corresponding to a container, Aptible will automatically deploy your new contents. And as we’ve got different environments, such as development, pre-production, production, I have to set up multiple remote repositories so that I can apply different Git branches to different applications.

However, despite of multiple remote repositories, names of remote branches are always “master”. So while pushing, I got

error: src refspec master does not match any.
error: failed to push some refs to 'git@example.com:username/whatever.git'

I Googled the error message and the solutions were all “before pushing, commit something in your EMPTY repository”, which was obviously not the reason of my error. Actually, it was caused by branch names mismatching between local and remote repositories. Rather than git push remote_repo master, git push remote_repo HEAD:master should be used, or simply git config push.default upstream to suppress the name check.

php-bencode is a PHP Bencode extension which supports encoding, decoding and editing Bencode strings or files. The previous version of php-bencode, which supports PHP 5, needs PHP-CPP to run while the new one now requires no other external libraries.

Written in C/C++, php-bencode gives an unbelievable performance boost for manipulations of Bencode. I’ve run a benchmark through different implements by decoding a Bencode file with 1M sub-nodes in my box (8 cores, 1G memory). The sample file can be downloaded here: Bencode Sample.

Obviously, the time needed to decode the same file is shortened dramatically by using php-bencode. The memory usage is a little higher than the pure PHP library with PHP 7 but the object array can give you real data safety rather than a plain array. (For example, if the original Bencode file contains an empty dictionary or list, data loss may be caused after decoding and re-encoding.) What’s more, because the memory usage gap between php-bencode and other pure PHP libraries goes up with the number of nodes, as the Bencode files we usually need to handle contain only less than 1,000 nodes, the gap can be just ignored.

Still, there’s much work to do. The previous version supported to get/set a node by path and search through the whole tree but they have not been implemented in the new one yet. Additionally, the new php-bencode supports only PHP 7 by now and I’m considering to support PHP 5.6 as well.続きを読む