su without password

Google returns a lot of meaningful results for “sudo without password” and “ssh without password.” I don’t know why googling “su without password” gives no useful info.

To allow a user to become root with su without entering the password, edit /etc/pam.d/su.

For example, in Gentoo (should be the same or similar in other distros) uncommenting the following line allows users in group wheel to su without password:
auth sufficient pam_wheel.so use_uid trust

Send Ctrl-A to sessions in SCREEN

C-A servers as the command hotkey in SCREEN. To send Ctrl-A to the session in SCREEN, simply use C-A a.

Example: the shell in SCREEN calls ssh, and SCREEN is again used in the remote machine. To detach the session in the remote SCREEN, press C-A a d.

BASH’s ‘read’ built-in supports '\0' as delimiter

I thought it was impossible to use '\0' as a delimiter in bash, but noticed yesterday that Gentoo’s ebuild.sh had pipelines like this:
find ..... -print0 |
while read -r -d $'\0' x; do
# Do something with file $x
done

This makes it possible to handle any strange filenames correctly, even if the filename contains newline ('\n') or carriage return ('\r') characters. (Some other commands, including sort and xargs, have options to make null character the delimiter based on the same reason.)

Because BASH internally uses C-style strings, in which '\0' is the terminator, read -d $'\0' is essentially equivalent to read -d ''. This is why I believed read did not accept null-delimited strings. However, it turns out that BASH actually handles this correctly.

I checked BASH’s souce code and found the delimiter was simply determined by delim = *list_optarg; (bash-3.2/builtins/read.def, line 296) where list_optarg points to the argument following -d. Therefore, it makes no difference to the value of delim whether $'\0' or '' is used.

SSH without password

Log into the client end and run ssh-keygen (In some systems parameter -t rsa is needed).

Then append ~/.ssh/id_rsa.pub (client end) to file ~/.ssh/authorized_keys (create it if not present) at the server end.

Done!

The Uncertainty Principle

If we define a global constant in C++:
const int x = 2;
The typical behavior of an optimizing compiler is to allocate memory for x only if its address is explicitly taken with an & operator or it is bound to a reference. (Otherwise constant propogation is sufficient.)

Now let’s assume we can only change the codes, compile and run them. Disassembly is not allowed. (That’s like physics - we can only do experiments and observe the results.) Then we are unable to find out whether x actually has an address. The only way we can detect it is to take its address and see whether there’s going to be a compiling error. But this process creates an address for it. (In physics, when we are measuring the position and momentum of a particle, we are changing its position and/or momentum.)

A similar thing is about the default constructor, default copy-constructor, default copy-assignment and default destructor. Some books say that a class always has them (in semantics); some books say compilers create them on demand (in implementation). Both are right - we cannot detect this in program.

Time (if any) before the Big Bang is irrelavent to our universe, so we can assert time did not exist before the Big Bang for a simpler model. Likewise, we can assert (semantically) a constant always has an address, and a class always have the four things, for a simpler model.

Do What The Fuck You Want To Public License

WTFPL stands for “Do What The Fuck You Want To Public License”. It is like GPL or BSD license or any other public license you may have heard of, but has no restrictions, allowing you to “do what the fuck you want to.”

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                    Version 2, December 2004

 Copyright (C) 2004 Sam Hocevar
  14 rue de Plaisance, 75014 Paris, France
 Everyone is permitted to copy and distribute verbatim or modified
 copies of this license document, and changing it is allowed as long
 as the name is changed.

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. You just DO WHAT THE FUCK YOU WANT TO.


This is NOT joking. You can find software licensed under WTFPL in almost all major Linux distributions. The best known one may be the ASCII-art library libcaca, which is used by the well-known player mplayer. (In Gentoo you can find the text of the license at /usr/portage/licenses/WTFPL-2.)

You may want to ask if there is any difference from WTFPL to public domain. The authors explain that the definition of public domain varies from jurisdiction to jurisdiction, and it is unclear in some countries whether works can be in public domain unless its authors have been dead for 70 years, but it is absolutely clear in most countries you have the right to choose a license for your works.


[Unlike other posts licensed under Creative Commons, this post is licensed under the Do What The Fuck You Want To Public License.]

html2text

I use an init script to log in my ISP. The script is like this
#!/bin/sh
wget -O - --post-data 'username=...&password=...' 'http://....' |
html2text | tee /tmp/$$.txt
fgrep -q 'already logged in' /tmp/$$.txt || exit 1
unlink /tmp/$$.txt
(The username and password are public in this building, so I need not worry about the clear-text password.)

It was strange that /tmp/$$.txt apparently contained the string “already logged in” but the script always exited abnormally (fgrep fails).

I finally found the reason by opening /tmp/$$.txt with bvi (a vi-style hexadecimal editor): the string in the file was actually like this: “You a\bare alr\bread\bdy logged\bd in.” (“\b” stands for backspace character.) That’s why fgrep could not find the string..

html2text sucks.

MATLAB xcb error

XCB breaks MATLAB (probably also other Java applications):
MATLAB: xcb_xlib.c:50: xcb_xlib_unlock: Assertion `c->xlib.lock' failed.
Either of the two workarounds works for me:
(1) If the libxcb version is ≥1.1, export LIBXCB_ALLOW_SLOPPY_LOCK=1 before running the broken application.
(2) Recompile libxcb with CFLAGS="-DNDEBUG". This macro disables assertions.

Workaround 2 uses some kind of brutal force, and in most cases Workaround 1 should be preferred.

[ Another workaround is found here. I think it works though I didn’t try it. However this uses even more brutal force. ]

Reference:
[1] Gentoo Forum thread: xorg-server-1.3.0 + xcb breaks java ?
[2] LFS documentation on libxcb