突突唧之家

我的疑问 & 我的解决方案

I have a beamer template for a presentation. In this template, the headline shows the section name and the subsection to which the current slide belongs to. However, even if I have defined a short title as in

\section[Short title]{The very long title that surely is way too long}

the headline always shows the long title.

Here is the code from the style file which shows the section name

\pgftext[at=\pgfpoint{\beamer@headline@lmargin}{-0.55\beamer@headline@height},left,center]{
\begin{beamercolorbox}[dp=0.5ex]{section in head/foot}
\shadowtextline{\insertsection}
\end{beamercolorbox}
}

So my question: Is there any other command for \insertsection in order to show the short title?

The outer theme should use \insertsectionhead instead of \insertsection:

1
2
3
4
5
6
7
8
9
10
11
12
13
\documentclass{beamer}

\begin{document}

\section[Short section title]{Long section title}

\begin{frame}
Long title: \insertsection

Short title: \insertsectionhead
\end{frame}

\end{document}

What are the differences between \def and \newcommand?

\def is a TeX primitive, \newcommand is a LaTeX overlay on top of \def. The most obvious benefits of \newcommand over \def are:

  1. \newcommand checks whether or not the command already exists.
  2. \newcommand allows you to define an optional argument.

In general, anything that \newcommand does can be done by \def, but it usually involves a little trickery and unless you want something that \newcommand can't do, there's no point in reinventing the wheel.


Q1: Is it possible to have parameters passed to \defed commands, both optional and required?

A1: Yes and No. A command defined using \def has to know exactly what its options are, and how they will be presented to it. However, a TeX command can be a bit clever and examine things other than its arguments. The way that optional commands are handled is to look at the next character in the stream and if it is [ then one version of the command is called, whereas if it isn't then another is called. So if you're prepared to do some hackery, then optional arguments are possible via \def, but it isn't half so easy as \newcommand.


Q2: Is there a \redef command equivalent to \renewcommand?

A2: No. Since \def doesn't check for a command already being defined, you can redefine stuff simply using \def again. To get the checking, you need to use the \@ifundefined command (note the ampersat (@) sign!).


Q3: I have only ever used \newcommand -- is there any reason I should change that habit?

A3: No.

The siunitx package has this sort of facility.

\num[group-separator={,}]{1234567890}

Should give you "1,234,567,890".

Also you can use this as a package option like so:

\usepackage[group-separator={,}]{siunitx}

Be warned, this doesn't seem to work with older versions of siunitx.

可以直接使用:

SELECT * FROM data_table
WHERE created_at < NOW() - INTERVAL 1 DAY;

下面是一个常见的错误写法:

DELETE FROM data_table
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), created_at)) / 3600 >= 24

因为 timediff() 可接受参数的取值范围和 time 数据类型的范围一致,这样写可能会遇到 Truncated incorrect time value 错误。

MySQL retrieves and displays TIME values in 'HH:MM:SS' format (or 'HHH:MM:SS' format for large hours values). TIME values may range from '-838:59:59' to '838:59:59'.

Here is a useful solution that works for various operating systems, including Linux, Windows, etc.:

import psutil
process = psutil.Process()
print(process.memory_info().rss) # in bytes

The Docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The Docker daemon always runs as the root user.

If you don't want to preface the docker command with sudo, create a Unix group called docker and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group.

The docker group grants privileges equivalent to the root user. For details on how this impacts security in your system, see Docker Daemon Attack Surface.

To run Docker without root privileges, see Run the Docker daemon as a non-root user (Rootless mode).

To create the docker group and add your user:

  1. Create the docker group.

    sudo groupadd docker
  2. Add your user to the docker group.

    sudo usermod -aG docker $USER
  3. Log out and log back in so that your group membership is re-evaluated.

    If testing on a virtual machine, it may be necessary to restart the virtual machine for changes to take effect.

    On a desktop Linux environment such as X Windows, log out of your session completely and then log back in.

    On Linux, you can also run the following command to activate the changes to groups:

    newgrp docker
  4. Verify that you can run docker commands without sudo.

    docker run hello-world

    This command downloads a test image and runs it in a container. When the container runs, it prints a message and exits.

    If you initially ran Docker CLI commands using sudo before adding your user to the docker group, you may see the following error, which indicates that your ~/.docker/ directory was created with incorrect permissions due to the sudo commands.

    WARNING: Error loading config file: /home/user/.docker/config.json - stat /home/user/.docker/config.json: permission denied

    To fix this problem, either remove the ~/.docker/ directory (it is recreated automatically, but any custom settings are lost), or change its ownership and permissions using the following commands:

    sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
    sudo chmod g+rwx "$HOME/.docker" -R

You would have to run this as root (hence the sudo):

for user in $(cut -f1 -d: /etc/passwd); do echo $user; sudo crontab -u $user -l; done

will loop over each user name listing out their crontab. The crontabs are owned by the respective users so you won't be able to see another user's crontab w/o being them or root.