Monday, October 14, 2019

Autoconf: example of checking for a feature in

AC_MSG_CHECKING([for string])

                           #include <string>
                           string str = "a string";
                  [AC_DEFINE([HAS_STRING], [1], [support string])


Monday, September 23, 2019

PHP: list all files and sub-directories under the current directory

Create a file index.php:

$allItems = scandir(".");
$toHide = array('.', '..', 'index.php');
$toShow = array_diff($allItems, $toHide);

foreach ($toShow as $oneItem) {
    echo "<a href='$oneItem'>$oneItem</a><br>";

Friday, September 20, 2019

GNU Autoconf issues

For the following errors in configure and make:

WARNING: 'aclocal-1.1x' is missing on your system.
WARNING: 'automake-1.1x' is missing on your system.
WARNING: 'autoheader' is probably too old.

We may probably install the required version of the GNU Autoconf tools and run the reconfiguration:

$ autoreconf -fi

before running ./configure again.

If the problem is only caused by the timestamps of the autoconf-generated files that make autoconf think that a re-configuration is necessary, we can fool autoconf by changing the timestamps of those files in the following order:

touch m4/*
touch build-aux/*
touch aclocal.m4
touch configure

Another trick is to assign no-op to the required autoconf commands to allow the build go through without running the actual reconfiguration:


Tuesday, September 3, 2019

Java programming: use Matcher to replace patterns with captured groups (code example)

String str = "=123-abc=   =7890-ABCD=";
Pattern pattern = Pattern.compile("=([0-9]*)-([A-Za-z]*)=");
Matcher matcher = pattern.matcher(str);
if (matcher.find())
    str = matcher.replaceAll("# $2 + $1 #");


The output will be:
# abc + 123 #   # ABCD + 7890 #

Friday, August 30, 2019

Python: redirect output to a file

To redirect the standard output to a file by the source code, add this in the beginning of the Python script:

import sys
sys.stdout = open('/path/to/outputfile', 'a')

Friday, August 23, 2019

Windows 10: check the starting time of the system

Method 1:

1. Right click on the Start icon and select "Run"
2. Run "cmd" to open a terminal.
3. In the terminal run command "net stats workstation"
4. In the beginning of the output, it says: "Statistics since 2019-08-20 7:22:39 PM". The highlighted part is the last reboot time.

Method 2:

1. Right click on the task bar and select "Task Manager"
2. Click on the Performance tab, then CPU
3. At the bottom of the CPU data, it shows "UP time", e.g. "3:01:01:16". It tells you the OS has been running for 3 days 1 hour 1 minute and 16 seconds.

Thursday, August 22, 2019

Git error: cannot spawn .git/hooks/post-commit: No such file or directory

This error could happen when on the Windows.

error: cannot spawn .git/hooks/post-commit: No such file or directory

To fix it, simply add this as the first line of the file .git/hooks/post-commit:


Thursday, August 15, 2019

Linux: skip a directory in find command

For example, to skip a sub-directory named .git and all the contents under it, run command:

$ find . -path ./.git -prune -o -print

option -prune is used to skip the directory specified by -path.

Friday, July 12, 2019

Perl: Convert hex string to the character

my $hx = "41";
my $ch = chr(hex($hx));
print $ch;

The output will be:

Wednesday, July 3, 2019

Linux: base64 encoding command

Encode a string with base64:

$ echo -n abc | base64

Decode a base64 encoded string:

$ echo -n YWJj | base64 -d

Get This <