Toolbox

Table of Contents

Table of Contents

Hello

This is a Collection of Notes and Links

This is work in Progress, use at your own Risk

This part is the Main page if exported to Hugo markdown.

Read more about Hugo and Org-mode here

The Hugo Version will be linked here once done.

Source files for this page

TODO

  • remove dependencies
  • TOC should expand while scrolling

GNU/Linux

Debugging

$coredumpctl list

$coredumpctl debug sway

Gnome

  • stuck in "software catalog is being loaded"

$ killall gnome-software $ rm -rf ~/.cache/gnome-software

  • "updates available"

$ settings set org.gnome.software download-updates false

Sway

  • GNOME Keyring integration

    https://wiki.archlinux.org/index.php/GNOME/Keyring#PAM_method

    /etc/pam.d/login

    #%PAM-1.0
    auth       required     pam_securetty.so
    auth       requisite    pam_nologin.so
    auth       include      system-local-login
    auth       optional     pam_gnome_keyring.so
    account    include      system-local-login
    session    include      system-local-login
    session    optional     pam_gnome_keyring.so auto_start
    
  • misc

    circumflex ^ = asciicircum

yay

<2019-10-25 Fr>

~/yay git rebuild

$ makepkg -si

Pacman

Pacman tools

  • Pamac GUI for pacman:

https://gitlab.manjaro.org/applications/pamac

  • Yet another Yogurt - An AUR Helper written in Go:

https://github.com/Jguer/yay

  • This repository contains contributed scripts to pacman.

https://www.archlinux.org/packages/?name=pacman-contrib

Maintenance

$sudo reflector --country France --country Germany --age 24 --latest 200 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
  • $flatpak uninstall --unused

    $journalctl --vacuum-size=128M

  • limit log file size: /etc/systemd/journald.conf

    SystemMaxUse=128M log file size

    $journalctl --verify


Python

Python Notes

"
list
.append, .count, .index, .insert, .pop, .remove, .reverse, .sort
"

SUPPLIES = ['pens', 'staplers', 'flamethrower']

"
don't
for i in range(len(SUPPLIES)):
print('indext' + str(i) + ' in supplies is: ' + supplies[i])
better:
"

for i, e in enumerate(SUPPLIES):
    print(f'index {i} in supplies is: {e}')
print('-------------------')

print(list(enumerate(SUPPLIES)))
print('-------------------')

for num, name in enumerate(SUPPLIES):
    print(num, name)
print('-------------------')

print(SUPPLIES.index('pens'))

"
Unpacking, * everything / *_ ignores the rest
"

    a, b, *c, d = (1, 2, 3, 4, 5, 6, 7)
    print(a)
    print(b)
    print(c)
    print(d)
KEYANDVALUE = {
            'heaven:'blue,
            'fire:'red}
for key, value in KEYANDVALUE.items():
    print(f'key {key} has value {value}')
print('hello')

-list slicing https://github.com/ostwalprasad/PythonListSlicingCheatsheet


Lisp

(print "hello")

Web

HTML

  • Template
    <!DOCTYPE html>
    <html>
    <head>
    <title>Template</title>
    </head>
    <body>
    </body>
    </html> 
    

CSS

  • auto grid
    .auto-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill,
                                minmax(16rem, 1fr));
        grid-gap: 1rem;
    }
    
    #fallback
    
    .auto-grid > * {
      max-width: 25rem;
      margin-left: auto;
      margin-right: auto;
    }
    
    .auto-grid > * + * {
      margin-top: 1rem;
    }
    
    #revert for grid supported
    
    @supports (display: grid) {
      .auto-grid > * {
      max-width: unset;
      margin: 0
      }
    }
    
    

Flask

if:

OSError: [Errno 98] Address already in use

ps -fA | grep python

kill -9 pid

Quart
https://gitlab.com/pgjones/quart

Quart is a Python ASGI web microframework

sudo pip install flask

setup debug flask server in virtual environment:

$virtualenv venv

$source venv/bin/activate

$export FLASK_DEBUG=1

$flask run

  • pips
    • Forms:

    $pip install Flask-WTF

    • Debug:

    $pip install flask-debugtoolbar

    • urlib2 alternative: Requests

Hugo

Django

$sudo pacman -S python-virtualenvwrapper

$sudo pacman -S python-django

$virtualenv venv

$source venv/bin/activate

$django-admin startproject mytestsite

$python3 manage.py runserver


Editing

[ S P A C E M A C S ]

  • EMAIL
    mbsync
    mailbox syncronizer
  • restart/reload/regenerate

    spc f e C-e recreates .env variable files

    spc f e r files - emacs - reload

    spc q r quit, restart

    spc f e r emacsdotfile reload

  • spacemacs config:

    spc f e d open the spacemacs config

    pacman -S aspell-en

  • buffer navigation

    spc b b shows all buffers

  • help

    , h h shows information relative to current cursor position

    , g u reference of the current function

    , g a findes assignment

  • python shell

    spc m s i major - start - inferior

    spc m s b major - send - runs buffer in inferior shell

    spc m s f major - send - function

    spc m l major - live

    spc m c c executes in comint shell: major execute c-c

    spc spc k kill-buffer

Org mode

  • Export to Hugo   hugo

    Using org + ox-hugo to export orgfiles into structured hugo markdown.

    At the head of the org document we set things like title, author, contact, setupfiles and other settings:

    #+TITLE: Toolbox
    #+HTML_LINK_HOME:
    #+LINK_UP: index.html
    #+OPTIONS:    H:4 num:nil toc:n \n:nil ::t |:t ^:t -:t f:t *:t tex:t d:(HIDE) tags:not-in-toc
    #+STARTUP:    align fold nodlcheck hidestars oddeven lognotestate
    

    Sections for export need properties at the beginning:

    :PROPERTIES:
    :EXPORT_HUGO_SECTION: /
    :EXPORT_FILE_NAME: index
    :END:
    

    this creates index.md in the root

    in .spacemacs:

    (defun dotspacemacs/user-config ()
      (use-package ox-hugo
        :ensure t          ;Auto-install the package from Melpa (optional)
        :after ox))
    
    don't
    org-hugo-export-to-md
    do
    C-c C-e HA
    • Structure created trough ox-hugo
      :PROPERTIES:
      :EXPORT_HUGO_SECTION: linux
      :EXPORT_FILE_NAME: linux
      :END:
      

      to inherit the export path from higher level heading EXPORT_HUGO_SECTION*:

  • Export to HTML with style
    • get a theme

      this page is build with

      https://github.com/fniessen/org-html-themes

      and the reference card:

      https://github.com/fniessen/refcard-org-mode

      Changes to the theme are made in separate branch from the forked repo.

      Create folders and place theme dependencies corresponding to the setupfile

    • In the Org file set path to setupfile, title and more

      #+SETUPFILE: styles/theme-readtheorg-local.setup
      #+TITLE: Toolbox
      

      Using C-c C-e h h we export org to html.

      After everything is done we sync with rclone:

      $rclone config

      rclone sync ~/Projects/Toolbox/ wtf:/pub/c.haas.wtf
      
  • Text and Files
    • Text
      • bullet
      • bullet
        • another bullet
      • and done

    code

    bold

    italic

    strike trough

    underline

    verbose

    • Images and Links

    city-q-c-640-480-2.jpg

    Figure 1: caption for 300px wide image

    #+caption: caption for 300px wide image
    #+name: city
    #+attr_html: :width 300px
    [[file:images/city-q-c-640-480-2.jpg]]
    

    using the name attribute to link a existing reference:

    description

    [[city][description]]
    

    and just a image as file:

    nature-q-c-640-480-4.jpg

    [[file:images/nature-q-c-640-480-4.jpg]]
    
  • Source blocks

    spc m i b s

  • LaTex
    \begin{equation} f(x) = x^2 \end{equation}
  • Flowcharts
    • PlantUML

      https://plantuml.com/

      We install plantuml with pacman:

      $pacman -S plantuml

      execution path looks like:

      exec /usr/bin/java -jar '/usr/share/java/plantuml/plantuml.jar' "$@"

      With this path we can evaluate this:

      (setq org-plantuml-jar-path (expand-file-name "/usr/share/java/plantuml/plantuml.jar"))
      (add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
      (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t)))
      

      And write the flowchart:

      start
      repeat :foo as starting label;
        :read data;
        :generate diagrams;
      backward:This is backward;
      repeat while (more data?)
      stop      
      

      plantumldiagram.png

    • ditaa

      possible alternative

    • mermaid

      possible alternative


  • SCAD

    This should not work

    cylinder(h = 31, r = 10);
    
  • GNUPlot

    Requirements: gnu-plot

    ;; active Babel languages
    (org-babel-do-load-languages
    'org-babel-load-languages
    '((gnuplot . t)))
    ;; add additional languages with '((language . t)))
    
    reset
    
    set title "Putting it All Together"
    
    set xlabel "X"
    set xrange [-8:8]
    set xtics -8,2,8
    
    
    set ylabel "Y"
    set yrange [-20:70]
    set ytics -20,10,70
    
    f(x) = x**2
    g(x) = x**3
    h(x) = 10*sqrt(abs(x))
    
    plot f(x) w lp lw 1, g(x) w p lw 2, h(x) w l lw 3
    

    file.png

Vim

vii indent block

vII indent block including first line

Pandoc

pandoc document.org -f org -t html -s -o website.html --metadata pagetitle="test"

Git gud

Work with a remote repository

This should cover most operations. Everything else is done with magit.

The original repository is upstream, we fork that project and create a new branch for our changes.

A fork is feature of the hosting site, not a git feature.

Get you fork:

$git pull

Create a new branch:

$git checkout -b <branchname>

And push it to the remote:

$git push origin <branchname>

Or get a existing branch:

$git checkout <branch>

List the existing branches:

$git branch -a

Change to the new branch:

$git switch <branch>

Set the location for upstream:

$git remote add upstream <https://>

List the remotes:

$git remote -v

Update the local fork from the upstream:

$git fetch upstream

$git merge upstream/master

Push the updated to your remote:

$git push

If there are changes in upstream while we edit our fork, update again.

After a successful pull request we can delete the branch:

remote:

$git switch <branch>

$git push -d origin <branch>

and local:

$git branch -d <branch>

Or we merge a testing branch:

$git merge testing/master

New repo

$touch README.md

$git init

$git add README.md

$git commit -m "first commit

$git remote add origin git@git...com:User/project.git

$git push -u origin master

Git credentials in PLAIN TEXT:

~/.netrc

machine github.com

login <user>

password <pwd>

Software

rclone
like rsync for files and folder on different clouds https://rclone.org/
wav
wayland event viewer https://git.sr.ht/~sircmpwn/wev
dhall
programmable configuration language, like yaml https://dhall-lang.org/
buku
bookmark manager https://github.com/jarun/buku
Zathura
minimalistic PDF viewer
qutebrowser
minimalistic web browser
ripgrep
faster than grep
ranger
file browser with vim support
podman
container engine
hastebin
pastebin from cli
firefox

– fullscreen to window size: about:config full-screen-api.ignore-widgets

– firefox wayland about:support window protocol: x11 / wayland $echo "MOZ_ENABLE_WAYLAND=1" > ~/.config/environment.d/firefox.conf

thunderbird
$echo "MOZ_ENABLE_WAYLAND=1" > ~/.config/environment.d/thunderbird.conf
lf
cli file browser https://github.com/gokcehan/lf
PASS
linux replacement for keepass https://www.passwordstore.org/
Sway Pass script
https://git.reekynet.com/ReekyMarko/fzf-pass
firmware for fritzbox and fritzrepeater
https://openwrt.org/ https://freetz.github.io/
Freetube
youtubeviewer with subscription and browser extension (beta) https://github.com/FreeTubeApp/FreeTube

GNU Stow, for dotfile tracking and version history

A stow directory:

mkdir /usr/local/stow

A new package for emacs:

/usr/local/stow/emacs

We put .spacemacs in the stow directory and create the simlinks with stow:

$sudo stow emacs

Run git init, add the files and configure your repo.

Games

Network

FTP

? Access the help screen.
append Append text to a local file.
ascii Switch to ASCII transfer mode.
bell Turns bell mode on or off.
binary Switches to binary transfer mode.
bye Exits from FTP.
cd Changes directory.
close Exits from FTP.
delete Deletes a file.
debug Sets debugging on or off.
dir Lists files if connected.
   
dir -C will list the files in wide format.
dir -1 lists the files in bare format in alphabetic order
dir -r lists directory in reverse alphabetic order.
dir -R lists all files in current directory and subdirectories.
dir -S lists files in bare format in alphabetic order.
disconnect Exits from FTP.
get Grabs file from the computer to which you are connected.
glob Sets globbing on or off. When turned off the file name in the put and get commands is taken literally and wildcards are not used.
hash Sets hash mark printing on or off. When turned on, for each 1024 bytes of data received, a hash mark (#) is displayed.
help Access the help screen and displays information about command if command typed after help.
lcd Displays local directory if typed alone, or if path typed after lcd, changes local directory.
literal Sends a literal command to the connected computer with an expected one line response.
ls Lists files of the remotely connected computer.
mdelete Multiple delete.
mdir Lists contents of multiple remote directories.
mget Get multiple files.
mkdir Make directory.
mls Lists contents of multiple remote directories.
mput Sent multiple files
open Opens address.
prompt Enables or disables the prompt.
put Send one file.
pwd Print working directory.
quit Exits from FTP.
quote Same as the literal command.
recv Receive file.
remotehelp Get help from remote server.
rename Renames a file.
rmdir Removes a directory on the remote computer.
send Send single file.
status Shows status of currently enabled and disabled options.
trace Toggles packet tracing.
Type Set file transfer type.
user Send new user information.
verbose Sets verbose on or off.

Create password protected directory

$mkdir folder

$local working directory

$lcd [directory]

$put filename

create password file:

/path/to/htpasswd -c /etc/htpasswd/.htpasswd user1

/path/to/htpasswd /etc/htpasswd/.htpasswd user2


Mobile

Python to Android

Temp stuff

this - now

scratch

for future reference

  • Auto-mounting of drives is done by udisks2 and gvfs. With that in place, most file managers will do. PCManFM, SpaceFM, Thunar, GNOME Files (Nautilus), etc
  • I use "bluetoothctl – connect 01:23:45:67:89:AB"
  • emacswebb(w)rowser
  • learn the power of the emacs undo-tree

Laptop

Arch BIOSboot with grub2

Troubleshooting:

$wipefs --all /dev/sdaX remove filesystem

$mount lists mounting points

$umount -R /mnt unmounts recursive

Live USB stick:

$dd bs=4M if=path/to/archlinux.iso of=/dev/sdx status=progress oflag=sync

In live boot

Settings

$loadkeys de

$wifi-menu -o

$timedatectl set-ntp true

Partitions

$fdisk /dev/sdx

  • boot, 1M (fdisk 04)
  • 32G linux, bootable (fdisk 22)
  • 2G swap (fdisk 19)
  • User (fdisk 28)

No filesystem for boot or swap

$mkfs.ext4 /dev/sdX1

$mkswap /dev/sdX2

$swapon /dev/sdX2

Mount, strap and tab

mount /, /usr, /boot. create folders is necessary

$mount /dev/sdX1 /mnt

$pacstrap /mnt base base-devel linux linux-firmware

$genfstab -U /mnt >> /mnt/etc/fstab

Setup installed system

Bootloader

$arch-chroot /mnt

$pacman -S grub

$grub-install --target=i386-pc /dev/sdX

$grub-mkconfig -o /boot/grub/grub.cfg

Local and user settings

$ln -sf /usr/share/zoneinfo/Region/City /etc/localtime

$pacman -S vim

$vim /etc/locale.gen

For now only en_DK ISO-8859-1


f

Created: 2020-03-27 Fr 11:14

Validate