Hong Xu

Hong’s Personal Technology Blog

Matching an Arbitrary Number Range in Regular Expression Using Capturing Groups

| Comments

To match an arbitrary number range in a regular expression, is to match a string with a specific pattern which contains a number range. For example, to match with a pattern test{0..100}, where {0..100} denotes an integer not smaller than 0 and not larger 100, is such a case.

Although we already have some solutions to match a number range in regular expression, but they all make lengthy string and may lead to possible performance issue. In this post, I will provide an alternative solution to this problem, but it requires you to have control over the captured groups of the regex.

Back Up (Migrate) Homebrew Packages

| Comments

As one of the most popular package manager on OS X, Homebrew is indeed a very nice tool to manage packages. However, when you want to back up your packages, or migrate the packages onto another machine, Homebrew didn’t invent such a tool. If you are moving to an OS X of the same version, you can simply copy the Homebrew directory (default is /usr/local) to your new machine. Otherwise, we need to find a way to install the exactly same packages on your new machine. In order to accomplish the goal, I wrote a small piece of bash script to generate a restore script to install the packages.

Too Many Escaping Backslashes? Avoid Them!

| Comments

Backslash escaping is common in programming. Sometimes we may let a file go through a few filters or template engines, such as markdown, quik, etc. and things become even worse if we are writing the template files from a string which requires backslash escaping for any literal backslashes appearing in the string. On Windows, things are more horrible than on Unices (You know why, right? Hint: path separator). Then, if you need a “real” backslash in the final output, you may end up with four or eight or sixteen backslashes in the original file. This is horrible. To avoid this situation, I wrote a short preprocessing script in Python to double or quadruple or octuple or zzzuple your backslashes.

Use Both Homebrew and Macports on Your OS X

| Comments

Homebrew and Macports are two excellent package managers on OS X. At most of the time, Homebrew is fair enough: it has a large package collections. But sometimes, there are just some packages not available in Homebrew while they are in Macports. Although having both of them installed is not recommended, I still want to give it a try.

The basic rules here are using Homebrew packages as much as possible. When one package is not available in Homebrew, install it from Macports (you will soon see why). We will wrap the executables installed by Macports with suitable Environmental Variables.

Please note that this post only presents a workaround. It is not garanteed to work, and it is possible that it does not work under some certain circumstances.

Live Preview of LaTeX in Vim

| Comments

Vim, as a highly configurable and customizable editor, already has a powerful Vim-LaTeX plugin. However, I don’t like the lack of live preview feature. For this reason, I developed a plugin called vim-latex-live-preview last year. Although it currently can’t handle complex situations such as multiple tex files, it could basically handle single tex file project well (with or without BibLaTeX, thanks to Asis Hallab).

Note: This plugin currently doesn’t work on Windows.

Manage Multiple SSH Private Keys

| Comments

If you have multiple ssh keys, it is sometimes hard to manage. This was written before, but mostly they are handling using different keys with different host. What if you have two or more GitHub or BitBucket accounts requiring different keys? As a result, I created skm to provide a more general solution. Here I’ll give a brief introduction of how to manage multiple SSH private keys with skm.

Install and Use GNU Command Line Tools on Mac OS X

| Comments

If you are moving onto Mac OS X from Linux, you would probably find out that the command line tools shipped with Mac OS X are not as powerful and easy to use as the tools in Linux. The reason is that Mac OS X uses the BSD version command line tools, which are different from the Linux version, while they are both compliant with POSIX standards. But we can easily install the GNU tools by using Homebrew in Mac OS X and set them as default.

Note: you need to notice that you may have some compatibility issues with shell scripts written specifically for OS X after you have replaced your OS X commands with the GNU version. Although the very vast majority of shell scripts have no problem, you just need to be aware that when there comes a problem, this may be the spot to check on.