diff options
-rw-r--r-- | CGI.md | 11 | ||||
-rw-r--r-- | android.md | 7 | ||||
-rw-r--r-- | apt.md | 26 | ||||
-rw-r--r-- | audio.md | 8 | ||||
-rw-r--r-- | awk.md | 52 | ||||
-rw-r--r-- | bash.md | 78 | ||||
-rw-r--r-- | bluetooth.md | 14 | ||||
-rw-r--r-- | certbot.md | 6 | ||||
-rw-r--r-- | date.md | 4 | ||||
-rw-r--r-- | display.md | 23 | ||||
-rw-r--r-- | ffmpeg.md | 56 | ||||
-rw-r--r-- | file-operations.md | 13 | ||||
-rw-r--r-- | git.md | 6 | ||||
-rw-r--r-- | gpg.md | 12 | ||||
-rw-r--r-- | grep.md | 3 | ||||
-rw-r--r-- | html.md | 6 | ||||
-rw-r--r-- | image-manipulation.md | 21 | ||||
-rw-r--r-- | imagemagick.md | 14 | ||||
-rw-r--r-- | java.md | 12 | ||||
-rw-r--r-- | jellyfin.md | 13 | ||||
-rw-r--r-- | keyboard.md | 5 | ||||
-rw-r--r-- | latex.md | 17 | ||||
-rw-r--r-- | ledger.md | 9 | ||||
-rw-r--r-- | lilypond.md | 35 | ||||
-rw-r--r-- | makefile.md | 47 | ||||
-rw-r--r-- | mariadb.md | 5 | ||||
-rw-r--r-- | markdown.md | 8 | ||||
-rw-r--r-- | mp3.md | 18 | ||||
-rw-r--r-- | mpv.md | 9 | ||||
-rw-r--r-- | mutt.md | 8 | ||||
-rw-r--r-- | network.md | 28 | ||||
-rw-r--r-- | nginx.md | 12 | ||||
-rw-r--r-- | pacman.md | 61 | ||||
-rw-r--r-- | pdf.md | 14 | ||||
-rw-r--r-- | postgres.md | 24 | ||||
-rw-r--r-- | python.md | 15 | ||||
-rw-r--r-- | qutebrowser.md | 7 | ||||
-rw-r--r-- | ranger.md | 19 | ||||
-rw-r--r-- | raspberry-pi.md | 19 | ||||
-rw-r--r-- | rss.md | 13 | ||||
-rw-r--r-- | sc-im.md | 61 | ||||
-rw-r--r-- | ssl.md | 3 | ||||
-rw-r--r-- | system-utils.md | 24 | ||||
-rw-r--r-- | systemd.md | 10 | ||||
-rw-r--r-- | text-utils.md | 35 | ||||
-rw-r--r-- | time.md | 5 | ||||
-rw-r--r-- | tmux.md | 15 | ||||
-rw-r--r-- | user-management.md | 16 | ||||
-rw-r--r-- | vim.md | 10 | ||||
-rw-r--r-- | xdg-open.md | 30 | ||||
-rw-r--r-- | xrandr.md | 9 |
51 files changed, 966 insertions, 10 deletions
@@ -0,0 +1,11 @@ +# CGI scripting + +## Inputs + +GET requests: `$QUERY_STRING` + +POST requests: in standard input + +## Redirect + + Location: <url to redirect to> diff --git a/android.md b/android.md new file mode 100644 index 0000000..c9fdefa --- /dev/null +++ b/android.md @@ -0,0 +1,7 @@ +# For interacting with an Android device + +Mount on system: + + aft-mtp-mount <mount directory> + +Later just `umount`. @@ -0,0 +1,26 @@ +# Apt package manager for Debian + +## List installed packages + + apt list --installed + +By size + + dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n + +## Remove packages + +Only removes the binary, leaving behind configs, logs, etc. Does not remove +dependencies. + + apt remove <package> + +Remove orphaned dependencies: + + apt autoremove + +Purge package (i.e. removes everything, including configs, etc.) + + apt purge <package> + # or + apt remove --purge <package> diff --git a/audio.md b/audio.md new file mode 100644 index 0000000..abafcd2 --- /dev/null +++ b/audio.md @@ -0,0 +1,8 @@ +# Various audio-related utilities + +## CD ripping with `cdparanoia` + + cdparanoia -w -B 1-<number of tracks> + +* `-w` for WAV output +* `-B` for batch mode (output to one file per track) @@ -13,4 +13,54 @@ Program is ;-separated pattern-action statements. `$0` is whole line, `$1`, `$2`, ... are fields separated by `FS` (by default, whitespace). -Set `FS` with `-F <sepstring>` +Set `FS` with `-F <sepstring>`. This can be a regular expression. + +Actually, the first part is any *condition*, and a /grep/ pattern is just one +possible one. Another useful example: `awk '$2 > 100 { print $3 }'`: print the +third column, if the line's second column is greater than 100. + +## Flags + +* `-F`: set the field separator, `FS` +* `-v`: set any variable + +## Conditions + +* Numerical comparisons: `==`, `!=`, `>`, `>=`, `<`, `<=` +* Regex matches: `~`, `!~` +* Logical operators: `&&`, `||`, `!` + +Special conditions: + +* `BEGIN`: triggered before processing any lines +* `END`: triggered after processing all lines + +If multiple conditions match, each action will be executed for it. In +particular, if multiple actions print, each will print. `next` can come in +useful, skipping all other conditions. + +## Built in Variables + +* `NR`: number of lines processed so far +* `NF`: number of fields (columns) in current line +* `FS`: input field separator, used to split each line into fields. +* `OFS`: output field separator, i.e. what gets printed between comma-separated + items in a `print` statement. Default: ' ' (space). Typical pattern: set it to + something else in a BEGIN block or with the `-v` flag. + +Useful when processing multiple files: + +* `FNR`: like `NR`, resets to 0 on new file +* `FILENAME`: name of currently processed file (`-` when STDIN) + +## Actions + +* `next`: skips processing of following conditions +* `exit`: finish processing (`END` will be executed) +* `printf`: formatted printing + +## Arrays + +* They're really more like hashmaps. +* Index with `[]`. +* Iterate over keys: `for(x in arr) print x, arr[x]` @@ -14,7 +14,7 @@ Remove longest from start # e.g. ${FILEPATH##*/} # get only file name portion -%% - longst from end, # - shortest from start +%% - longest from end, # - shortest from start ## Control flow @@ -53,3 +53,79 @@ Don't interpolate variables: cat << 'EOF' > file bla bla EOF + +## Arrays + +Declaring indexed arrays: + + declare -a name + +Associative arrays: + + declare -A name + +Assignment: + + # Indexed + array=(foo bar "baz bom"...) + # Associative + array=([bla]=foo [ble]=bar...) + +All values: + + ${array[*]} # one word, elements separated with first character of $IFS + ${array[@]} # separate words when double quoted + +All keys: + + ${!array[*]} + ${!array[@]} + +So looping: + + # Over values + for x in "${array[@]}"; do ... + # Over keys (0-based indices for indexed) + for x in "${!array[@]}"; do ... + + +Array size: + + ${#array[@]} + +Slice: + + # n elements starting at index i + ${array[@]:i:n} + +## Commandline arguments + +* `$#`: number of arguments. + +## Getopts example + + while getopts 'a:b:c' flag; do + case "${flag}" in + a) do_something $OPTARG ;; + b) b_option=$OPTARG ;; + c) c_flag=1 ;; + *) error "Unexpected option ${flag}" ;; + esac + done + +### With positional arguments + +Positional arguments will have to be supplied after flag options (`command +[options] <args>`): + + shift $((OPTIND-1)) + + +## Shell optional behavior/settings/options (`shopt` builtin) + + # Enable + shopt -s <option> + # Disable + shopt -u <option> + +* `nocaseglob`: glob matching is case insensitive diff --git a/bluetooth.md b/bluetooth.md new file mode 100644 index 0000000..c6fb78b --- /dev/null +++ b/bluetooth.md @@ -0,0 +1,14 @@ +# Using Bluetooth on Linux + +`bluez` and `bluez-utils` packages. `pulseaudio-blootooth` for audio. + +Start `bluetooth` service. + +## `bluetoothctl` + +* `scan on` to search for unpaired devices +* `devices` to list known devices +* `pair <MAC>` to pair with device +* `connect <MAC>` to connect +* `disconnect <MAC>` to disconnect +* might need to `trust <MAC>` diff --git a/certbot.md b/certbot.md new file mode 100644 index 0000000..5d8de41 --- /dev/null +++ b/certbot.md @@ -0,0 +1,6 @@ +# Free SSL certificates with Let's Encrypt + +## Multiple domains on one certificate + + # Can be used alongside with e.g. `--nginx` + certbot -d domain1.tld,domain2.tld,... @@ -5,3 +5,7 @@ ## UNIX timestamp date +%s + +From timestamp to human readable: + + date -d @<timestamp> diff --git a/display.md b/display.md new file mode 100644 index 0000000..d66e07f --- /dev/null +++ b/display.md @@ -0,0 +1,23 @@ +# Display management + +## DPMS + +Display Power Management Signaling controls power saving features on displays. + +Query current settings: + + xset q + +Turn DPMS on/off: + + xset -dpms # screen will not timeout + xset dpms + +Force screen poweroff: + + xset dpms force off + xset dpms force standby + xset dpms force suspend + +Off/standby/suspend are different power-off modes. They have trade-offs in power +consumption vs. time to restart. @@ -1,16 +1,46 @@ # ffmpeg tricks +## Convert + +Works for audio, too. + + ffmpeg -i in.EXT1 out.EXT2 + ## Cut ffmpeg -i in.mp4 -codec:v copy -codec:a copy -ss START_TIME -t DURATION out.mp4 ffmpeg -ss START_TIME -t DURATION -i in.mp4 -codec:v copy -codec:a copy out.mp4 -## Resize +## Quality + +### Resize ffmpeg -i in.mp4 -s 720x480 out.mp4 # -1 means to automatically preserve aspect ratio ffmpeg -i in.mp4 -filter:v scale=720:-1 out.mp4 +### Bitrate + +* `-b:a 192k`: specify audio bitrate to 192 kbps +* `-b:v 2M`: specify video bitrate to 2 mbps + +### Encoding + +H.265 is one of the top recommended formats, for size:quality ratio. + + ffmpeg -i in.mp4 -vcodec libx265 -crf <value> out.mp4 + +Reasonable `crf` values could be 24 to 30. + +## Audio/video delay + + ffmpeg -i "$input" -itsoffset <offset in seconds> -i "$input" -map 1:v -map 0:a -c:a copy -c:v libx264 "$output" + +For reverse offset, swap 1 and 0. + +Basically, take the input once with an offset, once without. Take the audio from +one of them, video from the other. + ## Rotate # 90 degrees clockwise @@ -39,7 +69,21 @@ For the transpose parameter you can pass: ## Concatanate audio - ffmpet -i in1.mp3 -i in2.mp3 -i in3.mp3 -filter_complex '[0:0][1:0][2:0]concat=n=3:v=0:a=1' output.mp3 + ffmpeg -i in1.mp3 -i in2.mp3 -i in3.mp3 -filter_complex '[0:0][1:0][2:0]concat=n=3:v=0:a=1' output.mp3 + +## Concatanate videos + +Works well especially for large number. + +Create file `list.txt` + + file 'video1.mp4' + file 'video2.mp4' + ... + +Then + + ffmpeg -f concat -i list.txt -c copy combined.mp4 ## Fitlering @@ -52,3 +96,11 @@ For the transpose parameter you can pass: [in1] ... [ink] filter_name=option1=val1:...:optionn=valn [out1] ... [outm] * Use `-filter_complex` if more than one input or output stream. + +## Video file info + +Just running + + ffmpeg -i video.mp4 + +will fail, but give a bunch of info about the file (including resolution, fps, etc) diff --git a/file-operations.md b/file-operations.md new file mode 100644 index 0000000..9ed0441 --- /dev/null +++ b/file-operations.md @@ -0,0 +1,13 @@ +# General file operations and utilities + +## `shred` + +Overwrites a file repeatedly with random data, to prevent data recovery. + +* `-z`: zeroes out at the end +* `-n <N>`: does `N` iterations (deafults to only 3) +* `-u`: deallocates and removes file + +So a common usage: + + shred -zun100 <file> @@ -30,3 +30,9 @@ Outputs to stdout a tar archive of the index at the given commit. Make a directory of just the code, not a repo: git archive <commit> | tar --extract --directory <output dir> + +## Remotes + +Change remote url: + + git remote set-url <remote> <new url> @@ -29,6 +29,10 @@ Add `--armor` to make it readable-ASCII encoded. gpg --import <key file> +Receiving a key from key server: + + gpg --recv-key "<key ID>" + ## Asymmetric crypto gpg --encrypt [--sign] [-u <signer>] [--recipient <receipient>] file @@ -54,6 +58,14 @@ use in mutt: # specify the signing key (by default it's your first one) gpg --local-user <signing key> --edit-key <key to sign> +## Key Fingerprint/ID + +The long hex fingerprint in `gpg --list-keys` is, as could be expected, a +standardized hash of the key info. + +Sometimes a shorter ID is used -- this is actually a suffix of the full +fingerprint. + ## gpg-agent `gpg-agent` is a daemon that e.g. provides a passphrase cache for GPG. Running @@ -0,0 +1,3 @@ +# Greppin' it up + +- `-o, --only-matching`: only print part of line that matches the expression @@ -46,3 +46,9 @@ To check by default: By default pretty prints the full selected HTML elements. Setting display function to `text{}` prints out just the inner text. + +### Extracting attributes + +Use the `attr` display function. + + pup ... audio attr{src} diff --git a/image-manipulation.md b/image-manipulation.md new file mode 100644 index 0000000..ccee16e --- /dev/null +++ b/image-manipulation.md @@ -0,0 +1,21 @@ +# Image manipulation (other than with Image Magick) + +## QR codes + +Decode: + + zbarimg -q --raw qrcode.png + +Create: + + qrencode -o <file.png> <string> + +## SVG + +Convert to PDF: + + inkscape -D word.svg -o word.pdf + +Compatible with LaTeX (see also latex.md): + + inkscape -D word.svg -o word.pdf --export-latex diff --git a/imagemagick.md b/imagemagick.md index 57261e9..3985c73 100644 --- a/imagemagick.md +++ b/imagemagick.md @@ -14,6 +14,16 @@ Force resize to be exactly the given geometry with `!` convert in.jpg --resize 720x720\! out.jpg +## Compress + +### JPG + +convert -strip -interlace Plane -gaussian-blur 0.05 -quality 85% source.jpg result.jpg + +## Convert PDF + +PDFs can be converted to images. Set `-density XxY` for better resolution. + ## Options with enum arguments List possible option values @@ -21,3 +31,7 @@ List possible option values convert -list <option> # e.g. convert -list dither + +## Remove EXIF data + + convert in.jpg -strip out.jpg @@ -0,0 +1,12 @@ +# Using Java on Arch + +## Managing JDK versions + + archlinux-java set java-11-openjdk # or other package + +## Android SDK + +Currently using [F-Droid's `sdkmanager`](https://gitlab.com/fdroid/sdkmanager) + + sdkmanager --install + sdkmanager --licenses diff --git a/jellyfin.md b/jellyfin.md new file mode 100644 index 0000000..1bbd277 --- /dev/null +++ b/jellyfin.md @@ -0,0 +1,13 @@ +# Jellyfin media server + +## Setting up as jukebox with Mopidy + +Install `mopidy-jellyfin`, configure in `/etc/mopidy/mopidy.conf`, adding: + + [jellyfin] + hostname = localhost:8096 + username = username + password = password + libraries = Library1, Library2 (Optional: will default to "Music" if left undefined) + albumartistsort = False (Optional: will default to True if left undefined) + album_format = {ProductionYear} - {Name} (Optional: will default to "{Name}" if left undefined) diff --git a/keyboard.md b/keyboard.md new file mode 100644 index 0000000..9ecd548 --- /dev/null +++ b/keyboard.md @@ -0,0 +1,5 @@ +# Dealing with keyboards and their inputs + +Identifying keycodes: + + xev | awk -F'[ )]+' '/^KeyPress/ { a[NR+2] } NR in a { printf "%-3s %s\n", $5, $8 }' @@ -29,3 +29,20 @@ Forward implication: Backwards implication: \impliedby + +## Figures + + \begin{figure} + \centering + \def\svgwidth{\columnwidth} + \input{input.pdf_tex} + \caption{ + Description + }\label{ref-label} + \end{figure} + +Note, `\label` comes after `\caption`. + +To embed an svg: + + inkscape -D word.svg -o word.pdf --export-latex diff --git a/ledger.md b/ledger.md new file mode 100644 index 0000000..3101567 --- /dev/null +++ b/ledger.md @@ -0,0 +1,9 @@ +# The Ledger Accounting System + +## Dates + +* `--begin/--end` (`-b/-e`): date bounds + +## List transactions + + ledger print <account> diff --git a/lilypond.md b/lilypond.md index a59c48d..993effc 100644 --- a/lilypond.md +++ b/lilypond.md @@ -16,6 +16,14 @@ Docs: `info LilyPond`. tagline = ##f } +## Paper settings + +Indentation of first line: + + \paper { + indent = 0 + } + ## Rhythm stuff ### Setting beat divisions @@ -36,3 +44,30 @@ Docs: `info LilyPond`. \time 3/4 \partial 8 e8 | a4 c8 b c4 | + +## Output formats + +### Images (PNG/SVG) + + lilypond --svg file.ly + lilypond --png file.ly + +It's useful to have these cropped: + + lilypond --svg -dcrop file.ly + +Will output both an A4-sized file.svg, and the cropped file.cropped.svg. +Suppress the non-cropped output with `-dno-print-pages`. + +### MusicXML + +Not supported natively, but the `python-ly` package on `pip` has experimental +support. + + ly musicxml file.ly + +## Notation + +Tie: + + a~ a diff --git a/makefile.md b/makefile.md new file mode 100644 index 0000000..50b5aae --- /dev/null +++ b/makefile.md @@ -0,0 +1,47 @@ +# Writing Makefiles + +## Pattern rules + +In prerequesite, use exactly one `%`. Can then be used in requirements. E.g. + + %.o: %.c + # compile .c file to .o + +Details: <https://www.gnu.org/software/make/manual/html_node/Pattern-Rules.html> + +## Automatic variables + +* `$@`: current target +* `$<`: first prerequisite +* `$^`: all prerequisites, separated by spaces +* `$*`: target without extension +* `$(@F)`: file-within-directory part of target path + +More: <https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html> + +## C-related flags + +* `CC`: C compiler +* `CFLAGS`: flags for `CC` +* `LDFLAGS`: flags for the linker + +## Text functions + +* `$(var:suffix=replacement)`, syntax sugar for + `$(patsubst %suffix, $replacement, $(var))` + +More: <https://www.gnu.org/software/make/manual/html_node/Text-Functions.html> + +## Filename functions + +<https://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html> + +## Recipes + +* `@<command>`: don't print command ran +* `-<command>`: don't exit on command failure + +## Arguments + +* `-B, --always-make`: force to make all targets + diff --git a/mariadb.md b/mariadb.md new file mode 100644 index 0000000..24a144c --- /dev/null +++ b/mariadb.md @@ -0,0 +1,5 @@ +# Managing and interacting with MariaDB + +* `SHOW DATABSES` +* `USE <database>` +* `SHOW TABLES` diff --git a/markdown.md b/markdown.md index 6df4493..88a6ee1 100644 --- a/markdown.md +++ b/markdown.md @@ -1,5 +1,9 @@ # Markdown/Pandoc tricks +## Formatting + +Force a line break: empty line with `\`. + ## Math $\text{\LaTeX}$ @@ -27,6 +31,10 @@ [reference]: https://url.of/image.png +Can place images side-by-side and control width: + + {width=50%} {width=50%} + ## Presentations pandoc in.md -t beamer -o out.pdf @@ -0,0 +1,18 @@ +# Manipulating mp3s + +## id3v2 + +For editing/viewing mp3 tags. + +* `-a`, `--artist` +* `-A`, `--album` +* `-t`, `--song` +* `-y`, `--year` +* `-T`, `--track` (track number) + +E.g. + + # Can pass multiple files + id3v2 --artist "Blind Guardian" --album "At the Edge of Time" --year 2010 * + +* `-l`, `--list`: lists all tags @@ -0,0 +1,9 @@ +# Using MPV + +* `ctrl+/-`: A/V delay + +## Zoom/Pan + +* `alt+/-`: zoom in/out +* `alt+arrow`: pan +* `alt+backspace`: reset pan/zoom @@ -9,3 +9,11 @@ Copy `/usr/share/doc/mutt/samples/gpg.rc` to config dir and source it. On Arch, had to change `/usr/libexec/neomutt/pgpewrap` to `/usr/bin/pgpewrap`. After composing message, press `p` to select crypto actions. + +## Search patterns + +- `~C`: search in TO and CC fields + +## Marking + +`exec toggle-new` to toggle read/unread status @@ -1,5 +1,9 @@ # Basic networking operations +## Basic networking info + + ifconfig + ## Find process binding a port # specifically tcp @@ -17,3 +21,27 @@ DNS lookup: So to lookup TXT records, drill host.com TXT + +## Connecting to WIFI with iwctl + + iwctl + device list + +Ensure device and adapter are turned on: + + device <device> set-property Powered on + adapter <adapter> set-property Powered on + +Begin scan (no output), list networks, connect: + + station <device> scan + station <device> get-networks + station <device> connect SSID + +## MAC spoofing + + sudo ip link set dev eth0 down + sudo ip link set dev eth0 address 00:00:00:00:00:01 + sudo ip link set dev eth0 up + +Or use `macchanger` utility, where you can specify the vendor, device type, etc. @@ -1,5 +1,9 @@ # The Nginx HTTP server +## Check config syntax + + nginx -t + ## Logs Specify separate logging file for given server @@ -10,3 +14,11 @@ To set up rotating/compressed logs, use `logrotate`. Config in `/etc/logrotate.d/nginx`. Run the following to reload config: logrotate -v -f /etc/logrotate.d/nginx + +## Enable website + + ln -s /etc/nginx/sites-available/<config> /etc/nginx/sites-enabled/ + +## SSL Certificate + + certbot --nginx @@ -4,7 +4,9 @@ pacman -U /var/cache/pacman/pkg/package-version... -## Cleaning cache +## Debloating + +### Cleaning cache paccache -r @@ -13,3 +15,60 @@ # remove all versions of uninstalled packages paccache -ruk0 + +### Removing orphaned packages + + pacman -Qtdq | pacman -Rns - + +### List packages by size + + LC_ALL=C pacman -Qi | awk '/^Name/{name=$3} /^Installed Size/{print $4$5, name}' | sort -h + +## Troubleshooting failed installations + +Usually enough to update keyring: + + pacman -Sy archlinux-keyring + +Might need to update mirrorlist first if outdated: + + sudo pacman -Sy pacman-mirrorlist + +(this might put it in /etc/pacman.d/mirrorlist.pacnew, uncomment wanted mirrors +there and remove the .pacnew suffix) + +## Query (-Q) + +By itself, outputs all installed packages. + +### Info + +Includes provided binaries/libraries, dependencies, installed size, etc. + + pacman -Qi <package> + + +Double info, includes more information, including packages that require (depend +on) this one: + + pacman -Sii <package> + +### Browsing installed packages with `fzf` + + pacman -Qq | fzf --preview 'pacman -Qil {}' --layout=reverse --bind 'enter:execute(pacman -Qil {} | less)' + +## Files (-F) + +Query the files database. + +Download/update database: + + pacman -Fy + +Lists packages that contain `file`: + + pacman -F <file> + +List files contained in `package`: + + pacman -Fl <package> @@ -11,3 +11,17 @@ ## Extract pages pdfjam --outfile out.pdf in.pdf 1,3,4-7 + +## Images to pdf + + convert in1.jpg in2.jpg out.pdf + +## DjVu to pdf + + ddjvu -format=pdf file.fjvu file.pdf + +* `-quality=85`: can be used to produce smaller output + * `-quality=uncompressed`: disable compression +* `-page=23-48,59`: select pages to convert +* `-verbose` +* `-eachpage`: generates a separate file per page diff --git a/postgres.md b/postgres.md new file mode 100644 index 0000000..28a0043 --- /dev/null +++ b/postgres.md @@ -0,0 +1,24 @@ +# The PostgreSQL DBMS + +Default user, db: `postgres` + +## User management + +Everything should be done as user `postgres`. + +New user: + + createuser --pwprompt mypguser + +Change password: + + # in `psql` + ALTER ROLE user WITH PASSWORD 'xxx'; + +## New database + + sudo su postgres + createdb -O mypguser mypgdatabase + + # delete db + dropdb mypgdatabase @@ -20,7 +20,13 @@ Install from requirements: python -m pip install -r requirements.txt -### Jupyter Notebook +## Executing a package + +Create `./package/__main__.py` script you want to execute. Then + + python -m package + +## Jupyter Notebook Setting default browser: @@ -28,3 +34,10 @@ Setting default browser: jupyter notebook --generate-config # edit the newly generated config c.NotebookApp.browser = '<browser command> %s' + +Using a venv: + + # once in venv + pip install ipykernel + python -m ipykernel install --user --name <name for the env in Jupyter> + # then select the new kernel in the web app diff --git a/qutebrowser.md b/qutebrowser.md index 3324252..fa67e81 100644 --- a/qutebrowser.md +++ b/qutebrowser.md @@ -5,3 +5,10 @@ By default bound to Alt+m. :tab-mute + +## Cookies + + :set content.cookies.accept no-3rdparty + + Supposedly breaks gmail. Change to `no-unknown-3rdparty` or back to `all` if + it does. @@ -1,5 +1,8 @@ # Ranger tricks +[Official User Guide](https://github.com/ranger/ranger/wiki/Official-User-Guide) + + ## Bulkrename :bulkrename @@ -20,3 +23,19 @@ Like in vim * `gc` - close * `uq` - restore tab * `M-<n>` - go to nth tab (create new if not exists) +* `~` - multi-tab view + +## Tags + +Files can have a single arbitrary tag, persistent between restarts. + +* `t` toggles/sets `*` tag +* `"<key>` toggles/sets `<key>` tag + +## Selection + +* `<space>` - toggle select on single file +* `v` - invert selection +* `uv` - deselect all + * Or `:unmark` + * Can also use `:unmark <regex>` diff --git a/raspberry-pi.md b/raspberry-pi.md new file mode 100644 index 0000000..dd5df21 --- /dev/null +++ b/raspberry-pi.md @@ -0,0 +1,19 @@ +# Info for running a Raspberry Pi system + +## Arch ARM + +Details on running Arch Linux ARM on a Pi + +### Sound + +`/boot/config.txt` needs the following to enable the audio card: + + dtparam=audio=on + +(Source: https://archlinuxarm.org/forum/viewtopic.php?f=9&t=13463#p60706) + +And + + dtoverlay=audremap,pins_12_13,enable_jack + +(Source: https://raspberrypi.stackexchange.com/questions/133199/no-audio-through-jack-despite-config-audio-on-raspi-config-also-fails/133200) @@ -0,0 +1,13 @@ +# On RSS feeds + +As per https://stackoverflow.com/a/11787940 + +> The specification has lacked clarity regarding whether HTML is permitted in +> elements other than an item's description, leading to wide variance in how +> aggregators treat character data in other elements. This makes it especially +> difficult for a publisher to determine how to encode the characters "&" and +> "<", which must be encoded in XML. + +`&`, `—`, etc won't work in XML title tags. This will break some feed +readers entirely (e.g. Thunderbird). Fix by using hexcode (e.g. for mdash: +`—`) diff --git a/sc-im.md b/sc-im.md new file mode 100644 index 0000000..367122c --- /dev/null +++ b/sc-im.md @@ -0,0 +1,61 @@ +# The TUI Spreadsheet + +Resources: + +* <https://github.com/groessler/scim/blob/master/src/doc> +* <https://github.com/jonnieey/Sc-im-Tutorial> + +## Basic editing + +* `<`/`\`/`>`: insert left/center/right-aligned string +* `=`: insert numeric expression +* `e`: edit numeric + * If accidentally added to text field, can erase with `=<RET>` (inserting an + empty numeric value) +* `E`: edit string +* `ir`/`c`: insert row/column above/to the left +* `or`/`c`: insert row/column below/to the right + +## Copying + +* `mc`: (where `c` is a lowercase character) marks cell or range with `c` +* `cc`: (where the second `c` is a previous mark) copies content from mark into + current cell, preserving formatting and adjusting formula. +* `yy`: copy current cell/selection +* `Pv`: paste only the value +* `Pf`: paste only the formatting +* `yr`/`c`: yank row/column +* `p`: paste below/on the left +* `t`: paste above/on the right + +## Movement + +* `hjkl` +* `^`/`#`: move to top/bottom of column (bottom is the last filled cell) +* `0`/`$`: move to left/right of row (rightmost is the last filled cell) +* `goc3`: go to cell C3 +* `g0`/`$`: move to left/rightmost visible column +* `c-e`/`y`: scroll down/up maintaining cursor position +* `zh`/`l`: scroll left/right maintaining cursor position +* `c-f`/`b`: scroll page down/up + +## Hiding/unhiding + +"Z" for "zap" when hiding. + +* `Z[cr]`: zap current column/row. +* `S[cr]`: shows hidden columns/rows in selected range (select with c-v) + +## Formatting + +* `c-j`: auto-fit column width +* `{`/`|`/`}`: align text left/center/right +* `f-`/`+`: decrease/increase decimal precision +* `f<`/`>`: decrease/increase column width + +### Scientific notation + + :format "#.##e-#" + +The two `#`s after the decimal point give precision. `e-` means scientific +notation, with sign only if the exponent is negative. @@ -0,0 +1,3 @@ +# SSL/TLS tools + + openssl x509 -in <file.pem> -text diff --git a/system-utils.md b/system-utils.md new file mode 100644 index 0000000..3c7adab --- /dev/null +++ b/system-utils.md @@ -0,0 +1,24 @@ +# For basic OS utilities + +* `mktemp`: creates a temporary file in /tmp and returns filename + +## `mount` + +Set file permissions of mounted drive at mount time: + + mount /dev/foo /mnt/bar -o umask=000 + +## Setting up a swap file + +From https://linuxize.com/post/create-a-linux-swap-file/ + + sudo fallocate -l 1G /swapfile + # or if the above fails: + # sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576 + sudo chmod 600 /swapfile + sudo mkswap /swapfile + sudo swapon /swapfile + # Add to /etc/fstab + /swapfile swap swap defaults 0 0 + # Check with + free -h @@ -9,3 +9,13 @@ Find unit file for given service: After editing unit file, need to reload wih systemctl daemon-reload + +### Drop-in editing + +Drop-ins will be in `/etc/systemd/system/<service>.d/`. Edit with + + systemctl edit <service> --drop-in=<drop-in name> + +## Logs + + journalctl -u <service> diff --git a/text-utils.md b/text-utils.md new file mode 100644 index 0000000..eb801e7 --- /dev/null +++ b/text-utils.md @@ -0,0 +1,35 @@ +# Various small text manipulation utilities + +## `cut` + +Select fields from each line based on some delimeter + + cut -d <delimiter> -f <list of fields> + +Setting a different output delimiter: + + --output-delimiter <delimiter> + +## `comm` + + comm file1 file2 + +Outputs three columns: + +1. Lines unique to `file1` +2. Lines unique to `file2` +3. Lines in both files + +Assumes files are sorted. + +Suppress a column with e.g. `-1`. + +So intersection of two files: + + comm -12 file1 file2 + +## `diff` + +Side by side: + + diff -y @@ -0,0 +1,5 @@ +# System time on Linux + +## Use a time server to synchronize clocks + + timedatectl set-ntp true @@ -12,6 +12,7 @@ ## Pane management q display pane indices + :move-pane -t <session id>:<window id> ## Run command in new session @@ -22,3 +23,17 @@ * `:setw synchronize-panes on` turn off with `:setw synchronize-panes off` + +## Packages + +First clone TPM: + + $ git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm + +Then in config: + + set -g @plugin 'tmux-plugins/tpm' + set -g @plugin 'tmux-plugins/tmux-sensible' + run '~/.tmux/plugins/tpm/tpm' + +Then `<prefix>+I` to download listed plugins. diff --git a/user-management.md b/user-management.md new file mode 100644 index 0000000..09d5d15 --- /dev/null +++ b/user-management.md @@ -0,0 +1,16 @@ +# Managing Linux users + +## Adding a user + + useradd [-m|--create-home] [-G|--groups <group,...>] -s <shell> <username> + passwd <username> + # as root, to add to sudoers + visudo + +## Adding user to a group + + gpasswd -a user group + +## Listing users' groups + + getent group @@ -93,10 +93,12 @@ g<c-a/x> - increment/decrement by 1 more on each selected line ## Spellcheck - :setlocal spell spelllang=en_us - [/]s - previous/next marked word - [/]S - previous/next bad word - z= - replacement suggestions +* `:setlocal spell spelllang=en_us`: start English spell checker in current pane +* `[/]s`: previous/next marked word +* `[/]S`: previous/next bad word +* `z=`: replacement suggestions +* `z[u]g`: add/remove from dictionary +* `z[u]w`: add/remove from wrong word list ## Formatting diff --git a/xdg-open.md b/xdg-open.md new file mode 100644 index 0000000..a688517 --- /dev/null +++ b/xdg-open.md @@ -0,0 +1,30 @@ +# Opening files with specific programs + +`xdg-open` looks up a file's mimetype, then determines which application to use +to open it. + +The local database for applications to use is in `~/.config/mimeapps.list`. Need +a `.desktop` file, which can be created under `~/.local/share/applications/`. + +## Setting defaults + +Easiest to do with `mimeopen` (from `perl-file-mimeinfo` on Arch): + + mimeopen -d <file> + # will prompt to select a program from a list + +## Default browser + +The relevant mime types are: + + x-scheme-handler/http= + x-scheme-handler/https= + +For qutebrowser, just copied the `.desktop` from [the repo](https://github.com/qutebrowser/qutebrowser/blob/master/misc/org.qutebrowser.qutebrowser.desktop). + +## `ranger` + +`ranger` uses its own launcher, `rifle`. Copy the default config to +`~/.config/ranger/rifle.conf`: + + ranger --copy-config=rifle @@ -7,3 +7,12 @@ ## Turn off second screen xrandr --output HDMI1 --off + +## Profile loading + +Install `autorandr`. + + # Save and name the current setup + autorandr --save <profile name> + # Load a previously saved setup + autorandr --load <profile name> |