3 Notes
3.1 C notes
char *
: pointer to charchar * const
: const pointer to charconst char *, char const *
: pointer to const charconst char * const
: const pointer to const char
3.2 TCP socket programming notes
epoll event:
EPOLLHUP: the other end of a pipe called close(2)
; both direction of a TCP connection are closed (sent and received FIN?)
EPOLLRDHUP: stream peer closed their writing connection (peer sent FIN)
send(2)
returns 0: stream peer closed their writing connection (peer sent FIN)
errno:
ECONNABORTED: TCP enters TCP_CLOSE due to RST, timeout or ICMP error during connect
ECONNRESET: received RST while not in TCP_SYN_SENT (ECONNREFUSED) or TCP_CLOSE_WAIT (EPIPE)
also EPIPE: send on a shutdown writing half
3.3 Git Notes
Git version 2.28.0
3.3.1 Work In Progress
3.3.1.1 Inspect WIP
git status
shows the list of files with staged and unstaged changes and untracked files.git diff
shows unstaged changes (worktree v index)git diff --staged
show staged changes (index v HEAD)git diff @
shows unstaged and staged changes (worktree, index v HEAD). (@ is a shortcut for HEAD. See gitrevisions)<pathspec>
add be added at the end, e.g.,:/
stands for repository root.
3.3.1.2 Discard WIP
git clean -f <path>
removes untracked filesgit restore <pathspec>
discards unstaged changes (working => index)
- alternatively,
git checkout <pathspec>
- Undo
git add
:git restore --staged <pathspec>
unstages staged changes (index => HEAD) orgit rm --cached <pathspec>
if a new file was added
- alternatively,
git reset <pathspec>
,git reset
(the whole repository),git reset -p
(interactively select chunks to unstage)
git restore --source=HEAD --staged --worktree <pathspec>
discards unstaged and staged changes (worktree, index => HEAD). Shorthand:git restore -s@ -SW <pathspec>
- alternatively,
git checkout @ <pathspec>
andgit reset --hard
(the whole repository).
Note: git reset
“resets current HEAD to the specified state” (and changes the worktree and the index accordingly) while git restore
does not move HEAD.
3.3.1.3 Save and reapply WIP
git stash
stashes unstaged and staged changes (untracked files are excluded) to a stash stack
git stash -u
includes untracked files (excluding ignored files);git statsh -a
includes even ignored filesgit stash -p
is interactive
git stash pop
applies the most recent local stash (previously staged changes are restored as unstaged) and drops it from the stash stack
git stash pop --index
restores staged changes as staged
git stash apply
applies the most recent local stash butgit stash drop
drops the most recent local stash from the stash stack
git stash list
lists saved stashesgit stash show n
inspects n-th stash (0-th is the most recent one)git stash apply n
applies the n-th stash from the stash stackgit stash clear
clears the stash stack
3.3.2 History
3.3.2.2 Rewrite history
3.3.2.2.1 Rewrite, undo and revert last commit
git commit --amend
replaces your last commit with a new commit.
- supply
-m
to change commit message or--no-edit
to keep it unchanged
git reset --hard @~
rolls HEAD back to the second last commit and restores the worktree and the index.git revert @
makes a new commit to revert the changes introduced in last commit.
3.3.2.2.2 Squash, split, and rewrite past commits
git rebase --root -i
. See Rewriting History of Pro Git.
- Squash all commits:
git reset $(git commit-tree @^{tree} -m "Squash all commits")
creates a new commit out of the tree object corresponding to HEAD and resets HEAD to it (source: StackOverflow). Note that some unreachable past commits are still available in your local reflog and unreachable objects are available in your local object database, which will expire by default. Reflogs and unreachable objects are not transfered bygit push
.
3.4 WebDav Server for Zotero Library
2021-01-21
- Motivation: Zotero Library’s free space is only 300MB.
- Caveat: Group Library is not supported.
3.4.2 Steps
- Install vanilla caddy per https://caddyserver.com/docs/install#debian-ubuntu-raspbian, which contains systemd service files
- Install caddy compiled with webdav module. You can customize included modules at https://caddyserver.com/download. Unfortunately, this step has to be repeated whenever caddy is upgraded.
curl -o /tmp/caddy 'https://caddyserver.com/api/download?os=linux&arch=amd64&p=github.com%2Fmholt%2Fcaddy-webdav'
sudo install -o root -m 755 /tmp/caddy /usr/bin/caddy
- Generate password for HTTP Basic Authentication
caddy hash-password > passwd_hash # input your passwd on stdin
sudo mkdir -p /var/www/zotero
- Put in
/etc/caddy/Caddyfile
:
example.com {
basicauth {
# username passwd_hash
zotero xxxx
}
root /zotero/* /var/www
webdav /zotero/*
}
- Reload caddy config
sudo systemctl reload caddy
3.4.3 Testing
cadaver is a command-line WebDav client, suitable for testing: cadaver https://example.com/zotero/
3.4.4 Other clients compatible with Zotero Library
Papership has macOS and iOS apps that can sync with Zotero and personal WebDav servers. You should run sudo touch /var/www/zotero/lastsync.txt
on the WebDav server on first use.