Pinned: stuffs that I keep googling again and again and again...
FOLDED, click entry to expand
linux general
unix - file permissions
NUMBER PERM
--------------
1 x
2 w
4 r
7 rwx
6 rw-
5 r-x
4 r--
bash - check number of command line parameters
if [ ! $# -eq 1 ]; then
echo "usage: $0 -h blah blah" >&2
exit 1
fi
tools - creating / extracting archives
extension create extract notes
-------------------------------------------------------------------------------
.tar.gz tar -czvf a.tar.gz a/ tar -xzvf a.tar.gz z:gz j:gz2
-------------------------------------------------------------------------------
.tar tar -cvf a.tar a/ tar -xvf a.tar
-------------------------------------------------------------------------------
.gz gzip -c file > a.gz gzip -dk a.gz use -r for dir/
-------------------------------------------------------------------------------
.zip zip file1 file2 ... unzip a.zip use -r for dir/
-------------------------------------------------------------------------------
tools - grep and find
# grep string pattern from directory
$ grep -ril <pattern> <dir>
-r recursive
-i ignore casing
-l show the matched line (otherwise only filename)
# find by name
$ find <path> -name <pattern>
# find by type
$ find <path> -type f # find file
-type d # find directory
-executable # find executable
-perm +/-xyz # w/o permission code xyz
git / version control
git - Checking out a git(hub) PR locally
git fetch origin pull/ID/head:BRANCH_NAME
git - Delete the last commit but keep the changes
git reset HEAD^
git - Checkout (reset) a file to a specific commit
git checkout <HASH> -- file1/to/restore file2/to/restore
git - send-email
git send-email --to="rec@email" [REF]
[REF]
e.g. HEAD~ , HEAD^2, <commit id>
[EMAIL OPTS]
-v<n> patch version (in the subject)
--subject-prefix=<str> e.g. "PATCH v4"
-l<n> log e.g. -l4 (changes since v1 etc..)
--cc/--bcc=<addr>
--from=<addr>
--reply-to=<addr>
--compose: invoke editor
--reply-to=<addr>
--in-reply-to=<id>
--subject=<str>
--to option, among others can be specified multiple times
Sourcehut’s tutorial is a great starting point
git am
git am [mbox]
# For sr.ht lists:
curl -s https://lists.sr.ht/~shrik3/test_list/patches/47533/mbox | git am -3
# For mutt: directly pipe mail content to git am
`| git am`
Sourcehut’s tutorial is a great starting point
keybase
gpg - select subkey to use
gpg -u SUBKEYID! --sign ....
# the ! after keyid is important!
--local-user name
-u Use name as the key to sign with. Note that this option overrides --default-key.
When using gpg an exclamation mark (!) may be appended to force using the specified primary or secondary key and not to try and calculate which primary or secondary key to use.
Also refer to man gpg
HOW TO SPECIFY A USER ID
Sourcehut’s tutorial is a great starting point
programming
Makefile - magic variables
out.o: src.c src.h
$@ # "out.o" (target)
$< # "src.c" (first prerequisite)
$^ # "src.c src.h" (all prerequisites)
%.o: %.c
$* # the 'stem' with which an implicit rule matches ("foo" in "foo.c")
also:
$+ # prerequisites (all, with duplication)
$? # prerequisites (new ones)
$| # prerequisites (order-only?)
$(@D) # target directory
Makefile - commands and functions
c_source := $(wildcard src/*.c)
all_files := $(shell find images -name "*")
# substitutions
file = $(SOURCE: .c=.o) # .cpp => .o
list = $(patsubst %.c, %.o, $(wildcard *.c))
- # ignore errors
@ # dont print command
+ # run even in 'don't execute' mode
archlinux
pacman - frequently used commands
-Sc : clear cache
-Qqe : list explicitly installed packages
-Ql : show file list of a package
-F <file> : show which package a file belongs to
-Si : extensive information
-Qi : ^ for locally installed packages
-Qii : ^ also with list of backup files
# clean orphans
$ pacman -Qtdq | sudo pacman -Rns -
# install package from PKGBUILD
$ makepkg -si
packaging - PKGBUILD
# guidelines : https://wiki.archlinux.org/title/Category:Arch_package_guidelines
# Prototypes : /usr/share/pacman/
# Very basic example:
pkgname=myprog
pkgver=1.2.3
pkgrel=1
pkgdesc='this is a program'
arch=('x86_64' 'arm')
url="https://git.vnil.de/repo.git/"
license=('GPL3')
depends=('libretls' 'ncurses')
source=("https://git.vnil.de/${pkgname}.git/whatever_path/${pkgname}-${pkgver}.tar.gz")
md5sums=('hash of the source')
build() {
cd "${pkgname}-${pkgver}"
./configure --prefix=/usr --mandir=/usr/share/man
make all
}
package() {
cd "${pkgname}-${pkgver}"
make DESTDIR="$pkgdir/" install
}
system admin
web design
CSS - center a div (not a joke!)
.xyz {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
CSS - order : top,right,bottom,left
div {
padding: 25px 50px 75px 100px;
/* top: 25px ; right: 50px; bottom: 75px; left: 100px */
}
MISC
numbers and bases
2^n Hex Unit Note
-------------------------------------------------------------------------------
2^10 0x400 Ki
-------------------------------------------------------------------------------
2^12 0x1000 4Ki 4k page table
-------------------------------------------------------------------------------
2^20 0x10_0000 Mi
-------------------------------------------------------------------------------
2^30 0x4000_0000 Gi
-------------------------------------------------------------------------------
2^40 0x10_0000_0000 Ti
-------------------------------------------------------------------------------
2^48 - 256Ti 48 bit virtual address space
-------------------------------------------------------------------------------
2^50 - Pi
-------------------------------------------------------------------------------
2^52 - 4Pi 52 bit physical address space
-------------------------------------------------------------------------------
2^64 - 16484Pi 64 bit address space
endianess
32bit integer 0x01020304
1000 1001 1002 1003 <= byte address in RAM
--------------------------------------
Big 0x01 0x02 0x03 0x04 - LSB in higher addr
--------------------------------------
Mixed 0x02 0x01 0x04 0x03 - every two bytes in a LE group
--------------------------------------
Little 0x04 0x03 0x02 0x01 - LSB in lower addr
--------------------------------------
^
|
Endianess
apple keyboard fn
echo 2 >> /sys/module/hid_apple/parameters/fnmode
suggestions?
contact me
You can find my contacts on the about page of this website
https://shrik3.com/about/
Critia:
- prefer one-liners
- prefer simplicity
- prefer ascii and textwidth=80
- those you REALLY keep googling and forgetting
- not a cliché