27 KiB
Anki: 2021
- Finding devices
$PATH
environment- Testing systemd timestamps
- Enabling desktop integration
- Flatpak permissions
- The basics of Flatpak apps
- Changing user shell
- Printing a list in the shell
- systemd timestamp example
- Type checking in Bash
- Emacs: The overview of buffers
- The basics of Emacs modes
- Emacs: Eagle's eye view of a window
- Emacs: Point and marker
- Interacting with buffers in Elisp
- String comparison in Emacs Lisp
- Using the help system in Emacs
- Emacs: Word manipulation
- Emacs: Line manipulation
- Vim: Jump to previous jump point
- Vim: Enter jump point
- Vim: Go to file path
- Set as a pager
- Vim: Show outline/table of content
- Detect files through Vim filetypes
- Going to keyword definitions in Vim
- Vim modes
- Word wrapping in Vim
- Using the help system
- Pitfalls and illusions of competence
- org-babel
- org-babel modes
- Creating files with Org mode
- Dynamic content with Org mode
- Org mode: Asciidoctor-styled callouts
- Org mode: Timestamps and durations
- Org mode: Deadlines and schedules
- Org mode: Quick file navigation
- Editing source code blocks in Org mode documents
- Practices for studying
- Focused and diffused mode
- Benefits of sleep
- Bash conditional with an unset variable
- Bash conditional with a set variable
- Shell help system
- Basic music notation reading 1
- Basic music notation reading 2
- Basic music notation reading 3
- Watch the logs of a systemd unit
- Restoring a file in Git
- Setting environment variables with systemd environment directive
- Emacs Lisp conditionals
My collection of tips and tricks I collected in 2021.
Enabling desktop integration
Back
Most of the desktop environments and certain applications like Rofi refers to the XDG_DATA_DIRS
environment variable, a list of colon-delimited paths similar to PATH
.
This enables desktop integration with certain tools like Nix and Guix package manager. Here's how to integrate installed Nix packages into the desktop.
XDG_DATA_DIRS=$HOME/.nix-profile/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
Flatpak permissions
Back
By default, they have none. Among the default limitations:
- They can only access their own runtime folder
$HOME/.var/app/${FLATPAK_APP_ID}
. - They cannot access the network.
Some apps are installed with the request to allow the following permissions enabled (e.g., Zotero).
If left with no permissions, you'll see in certain situations like a file browser dialog that the permissions is in effect. Below are some of the examples interacting with the permissions of an app.
# Show the permissions of an app.
flatpak permission-show ${FLATPAK_APP_ID}
# Let the user-installed Flatpak app access the home directory.
flatpak override --user --filesystem=home ${FLATPAK_APP_ID}
The basics of Flatpak apps
Back
A Flatpak package can either be a runtime or a standalone app.
Runtimes are the basic dependencies of an application. Only select packages available as a runtime (e.g., Qt, GTK).
Flatpak has its set of runtimes composed of system libraries to be used with the applications. Thus, it stays out of its way with the operating system's libraries. The developer can also bundle its own set of libraries.
Emacs: The overview of buffers
Back
A buffer is anything that Emacs displays.
It usually display file contents among other examples with butterfly
, doctor
, or the starting buffer when you first open Emacs.
While buffers usually have an associated file path, a buffer doesn't need one. This is one of the concepts that is applied to other text editors (Vim, Atom, Visual Studio Code).
The basics of Emacs modes
Back
A mode is set of behavior quite similar to Vim modes.
Emacs further divides modes into two.
Major modes are Emacs' way of supporting programming languages and file formats.
Programming language support usually comes in major mode — e.g., R-mode
for R files, python-mode
for Python scripts, org-mode
for Org mode documents.
Think of them as an equivalent to Vim's filetype.
Only one major mode can be activated in one buffer at a time and all buffers have a major mode.
Minor modes usually contain little behavioral changes that improve the editing experience. When enabled, some of them are global modes — affecting every buffer in your session. Others are only buffer-local — affecting only the buffer when you activated the mode. Unlike major modes, multiple minor modes can be enabled at any given time.
Emacs: Eagle's eye view of a window
Back
A window is where the buffers are being displayed. One window can display all buffers but only one at a time. To display two buffers at a single time, just add another window.
All windows display the same buffer; if the buffer is modified in one of the window, it will show the changes in all windows.
Emacs: Point and marker
Back
A point is the current location of the cursor in the buffer.
You can get the point with point
function.
Often helpful for interacting with buffers.
A marker is another point in the buffer. It is usually found when interacting with regions when asked for the two points (i.e., the beginning and the ending position). Furthermore, a marker can be used to save locations and jump back to that marker when asked.
Using the help system in Emacs
Back
help-for-help
is the most comprehensive help section (in my opinion).describe-*
series of functions are the next. Among the list of describe functions, you have:describe-key
,describe-function
,describe-variable
, anddescribe-package
. You can just open up the minibuffer and see what else is there.apropos
is similar to Unix apropos command which searches for every symbol in Emacs.
Emacs: Word manipulation
Back
The following functions have multiple variations each for a character ($F-char
), word ($F-word
), region ($F-region
), and region or point ($F-dwim
).
capitalize-*
for making the first of the word in uppercase.downcase-*
for making a region all lowercase.upcase-*
for making a region all uppercase.
evil-mode has a keybinding associated with uppercase and downcase a certain region with evil-upcase
and evil-downcase
, respectively.
Emacs: Line manipulation
Back
- evil-mode has
evil-join
which works the same way Vim's join complete with smart spacing and everything. fill-region
is useful for formatting requirements/preferences like in the Linux kernel where the maximum width of 80 characters. evil-mode has an associated keybinding function withevil-fill
.sort-lines
is pretty useful for the common task of sorting lines. Though, not useful for items that consist of multiple lines.
Detect files through Vim filetypes
Back
Vim guesses the file by assigning filetypes, mainly through the file name and reading the file content. A filetype is how Vim knows what plugins to apply to the current buffer.
Vim has a few built-in filetypes such as shell, manual pages, Markdown, Asciidoc, xmodmap, patch files, and JSON among others (that are in $VIMRUNTIME/filetype.vim
).
For more information, run :help filetype
inside Vim.
Pitfalls and illusions of competence
Back
- The presence of the material itself can cause students to foolishly think they already know about the subject.
- Similarly, studying with solutions can be a trap if you focus on the what and how rather than the why.
- Various common practices such as highlighting, rereading, and mind mapping are not as effective and only applicable in specific situations.
- The einstellung mindset, being invested in an idea that you can't see other solutions.
- Similarly, overlearning can occur if you're aiming for complete mastery when you should move on after understanding the concept.
org-babel
Back
org-babel, the library that enables superpowers for Org mode source code blocks.
Among the list of features, org-babel makes the following things easier for creating lab notebooks.
- Execute the source code block and print results.
- Create files from source code blocks, making it possible to create an entire computational report with a single Org mode document.
- Metaprogramming with noweb-inspired system making dynamic content possible.
- Individual control over source code blocks with sessions, export options, and variables.
- Pass values between different source code blocks even in different programming languages.
org-babel modes
Back
First, configure org-babel to work in functional mode (i.e., :results value
) in a source code block.
With functional mode, it will return values which will be handled by org-babel.
#+name: num
#+begin_src python :results value
return 53
#+end_src
The value cannot be passed unless it has a name that others can reference yet so add a name property to the source code block (i.e., #+name: ${NAME}
).
Now here's a different source code block written in a different language.
To pass a value, you have to configure with :var ${VARNAME}=${NAME}
.
#+begin_src ruby :var num=num :results output
print(num)
#+end_src
Dynamic content with Org mode
Back
Yes!
By attaching a name to a code block and evaluating them, it is possible.
Here's an example of a source code block with a default argument.
#+name: greeting
#+header: :var name="World"
#+begin_src sh
echo "Hello ${name}"
#+end_src
You can then call the function in different ways:
- For calling it inline,
call_${FUNC_NAME}()
. - For creating a block,
#+call: ${FUNC_NAME}()
. - For invoking inside a code block,
<<${FUNC_NAME}()>>
, but you have to enable noweb (e.g.,:noweb yes
).
You can then pass header arguments by appending in square brackets ([]
) before invoking it — e.g., call_greeting[:results replaces]()
, #+call: greeting[:results replace]()
, <<greeting[:results replace]()>>
.
Org mode: Asciidoctor-styled callouts
Front
Are Asciidoctor-style callouts possible in Org mode? If so, how?
Back
Surprisingly, yes! It is just hidden on the documentation. Specifically, on the Literal examples section of the Org mode manual.
Here's an example to do it.
#+begin_src python
print("Hello world") # (ref:hello)
print(2 + 5) # (ref:num)
#+end_src
In [[(hello)][line 1]], we have printed the traditional "Hello world" program.
In [[(num)][the second line]], we've done a simple arithmetic and printed it into the console.
To create Asciidoctor-styled callouts, create a reference inside of the code block and refer to it (i.e., (${ref})
).
Org mode: Quick file navigation
Back
- I don't need to explain what
org-babel-next-src-block
andorg-babel-previous-src-block
does. org-backward-heading-same-level
is the same asorg-forward-heading-same-level
but moves one headline backwards.org-forward-heading-same-level
moves one headline forward in the same level. Useful for navigating sections and subsections.org-goto
creates an interface for showing the outline and it is a great navigation function. Highly recommend to use it with a completion interface (e.g.,counsel-org-goto
,counsel-org-imenu
).org-num-mode
adds a (non-persistent) counter to the document. Very helpful in navigating larger files.org-sort
will sort the entries into your preferred criteria. It also works on a list of items which is very useful if one of the list items has more than one line.
Practices for studying
Back
- Recalling is one of the more effective practices compared to rereading or highlighting. Self-testing is one of the better strategies, overall.
- Prefer spaced repetition over cramming as scientifically, the learning process takes some time to settle.
- Get the key ideas ahead and as you're studying, fill the details. This includes skimming — reading through the chapter, looking at the keywords.
- Practice interleaving your studies — that is, studying other subjects and/or moving to later topics as you understand the topic.
- Focus, understand, and practice. Learning can occur bottom-up (learning the details of a problem) and top-down (learning the bigger picture of a topic). Using both creates context and that's where you put your understanding to the test as you learn when to apply what you've learn.
- Use memory palace technique — that is, to create analogies, narratives, and mnemonics.
- Have efficient amount of sleep. Sleep has certain processes that helps our brain like removing toxins in our brain that accumulate when we're awake, eliminating less relevant neural structures in favor of strengthening stronger ones for tomorrow, and thinking of a solution of the thing you worry about.
Focused and diffused mode
Back
Focused mode is when you are in the middle of a mentally intensive task — e.g., cooking, writing, reading, studying. In this process, you gather all of the information that are immediately required to complete it.
Diffused mode is the state of mental relaxation — e.g., taking a walk, watching a movie, recess and lunchtime. This is when the brain takes the focused task into the background and let random thoughts pass by. This is the reason why we sometimes get a sudden realization (a Eureka! moment).
Shell help system
Back
- help sections (i.e.,
--help
or-h
) - manual pages (i.e.,
man
) - TexInfo (i.e.,
info
) - tldr pages (i.e., with clients like tealdeer)
Setting environment variables with systemd environment directive
Back
Create an environment directive file in the specified directory.
You can find the search paths and the syntax from environment.d.5
manual page.
Basically, it is a shell-like config for setting environment variables. The following shows that.
TERM=alacritty
EDITOR=nvim
BROWSER=brave
MANPAGER="nvim +Man!"
PATH=${PATH:+$PATH:}${GUIX_PROFILE:-$HOME/.guix-profile}/bin
XDG_DATA_DIRS=${GUIX_PROFILE:-$HOME/.guix-profile}/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
Compared to exporting values with the user shell (e.g., .bashrc
, .zshrc
) where they are only applied when the shell is called, environment variables generated from the directive can be recognized from applications that called non-interactively (e.g., GNOME desktop search, Rofi).
You can also view the resulting environment with systemctl show-environment
.