My collection of tips and tricks I collected in 2021.
* Finding devices
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620896949865
:END:
** Front
How to list devices information?
(I mean all sorts of devices.)
** Back
- ~lspci~ lists PCI devices.
- ~lsusb~ list USB-connected devices.
- ~lsblk~ list the block devices which usually includes storage drives and such.
* ~$PATH~ environment
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620896950086
:END:
** Front
How does a shell find the binaries?
** Back
Most shell searches through the ~$PATH~ variable, a colon-delimited list of paths containing the binaries.
* Testing systemd timestamps
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620896950299
:END:
** Front
How to test out systemd timestamps?
** Back
~systemd-analyze {calendar,timestamp,timespan}~
To know how the format (i.e., calendar, timestamp, and timespan) looks like, you can refer to ~man systemd.time.5~.
* Enabling desktop integration
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620896951550
:END:
** Front
How to make desktop environments recognize the desktop files?
** 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 [[https://nixos.org/][Nix]] and [[https://guix.gnu.org/][Guix]] package manager.
Here's how to integrate installed Nix packages into the desktop.
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
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897004139
:END:
** Front
What is a mode in Emacs?
** 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
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897004490
:END:
** Front
What is considered window in Emacs?
** 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
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897004696
:END:
** Front
What is a point and a marker in Emacs?
** 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.
* Interacting with buffers in Elisp
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897006160
:END:
** Front
Give a rough example on how to do the following in Emacs Lisp:
Create a temporary buffer named "hello" containing an Org mode document with a "Hello world" entry.
** Back
#+begin_src elisp :exports code
(with-temp-buffer
(insert "* Hello world")
(rename-buffer "hello")
(org-mode))
#+end_src
* String comparison in Emacs Lisp
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897007536
:END:
** Front
How to compare two strings in Emacs Lisp?
** Back
~(string= STR1 STR2)~
#+begin_src elisp :exports both
(print (string= "WHOA" "whoa"))
(print (string= "WHOA" (upcase "whoa")))
(print (string= "Hello world" "HeLL0 World"))
#+end_src
#+results:
:
: nil
:
: t
:
: nil
* Using the help system in Emacs
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897007813
:END:
** Front
Name different ways to use the help system inside 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~, and ~describe-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
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897008268
:END:
** Front
Give some functions on word manipulations inside Emacs.
** 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
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897008638
:END:
** Front
Give some functions on manipulating lines while in Emacs.
** 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 with ~evil-fill~.
- ~sort-lines~ is pretty useful for the common task of sorting lines.
Though, not useful for items that consist of multiple lines.
* Vim: Jump to previous jump point
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897030216
:END:
** Front
In Vim, how to get back in previous jump point?
** Back
=Ctrl + O=
Remember it as getting *out* of the current jump point and back to the previous one.
* Vim: Enter jump point
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897030696
:END:
** Front
How to jump into a keyword with Vim?
** Back
- =Ctrl + ]= will enter into the definition block of a keyword.
- =K= also has the same effect.
* Vim: Go to file path
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897031016
:END:
** Front
In Vim, how to go to the file path at point?
** Back
=gf= (in normal mode) as in *goto file*.
* Set as a pager
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897031838
:END:
** Front
How to set Vim as a manpager?
** Back
~MANPAGER="nvim +Man!"~
~+Man!~ is a command invocation (as if entering ~:Man~ inside Vim).
It can also be written as ~-c Man!~.
The ~:Man!~ command displays the current buffer as a manual page.
* Vim: Show outline/table of content
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897032249
:END:
** Front
How to show the table of contents of a document in Vim?
** Back
=gO=, although the results are filetype-specific (and some don't have any).
Helpful examples include for manual pages and help pages (from =:help=).
* Detect files through Vim filetypes
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897033214
:END:
** Front
How does Vim detect the files?
** 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.
* Going to keyword definitions in Vim
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897033626
:END:
** Front
How to go to the keyword definition in Vim?
** Back
=gd= as in *go to definition*.
Though, not all the time it will do what its supposed to do.
For better effect, you can generate a Ctags file which Vim has a built-in integration (see ~:h ctags~).
* Vim modes
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897034389
:END:
** Front
What is a mode (in Vim)?
** Back
A Vim mode is a set of behavior and actions.
In this case, it considers editing and navigation (among other modes) to be separate.
Thus, you need to switch between them to do those things.
Vim has built-in modes which you can see with ~:h vim-modes~.
* Word wrapping in Vim
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897034688
:END:
** Front
How to do word wrapping (in Vim)?
** Back
=gw= as in *go format the words*.
By default, it simply line wraps the lines with the 80-character limitation.
* Using the help system
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897035960
:END:
** Front
How to effectively make use of the help system of Vim?
** Back
The usual way is to execute ~:h~ or ~:help~.
You can view what does a keybinding do with ~:h ${KEYBINDING}~ — e.g., ~:h gw~ to know what =gw= does, ~:h V~ for viewing visual line mode.
For keybindings in visual and command line mode, prepend them with ~v_~ and ~c_~, respectively.
* Pitfalls and illusions of competence
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620899217785
:END:
** Front
Give various pitfalls and illusions of competence to look out when learning.
** 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.
What makes Org mode popular for reproducible research?
** 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 [[https://orgmode.org/manual/Noweb-Reference-Syntax.html][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
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897023961
:END:
** Front
How to make org-babel pass values between different source code blocks?
** 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.
#+begin_src org
,#+name: num
,#+begin_src python :results value
return 53
,#+end_src
#+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 org
,#+begin_src ruby :var num=num :results output
print(num)
,#+end_src
#+end_src
* Creating files with Org mode
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897024413
:END:
** Front
How to create files with Org mode source code blocks?
** Back
The ~:tangle~ option enables extracting code blocks into files.
Accepted values include =yes=, =no=, or a relative path to the Org document where the file will be written.
By attaching a name to a code block and [[https://orgmode.org/manual/Evaluating-Code-Blocks.html#Evaluating-Code-Blocks][evaluating]] them, it is possible.
Here's an example of a source code block with a default argument.
#+begin_src org
,#+name: greeting
,#+header: :var name="World"
,#+begin_src sh
echo "Hello ${name}"
,#+end_src
#+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]()>>~.
Just prepend the keywords =DEADLINE= and =SCHEDULED=, respectively.
#+begin_src org
DEADLINE: <2021-06-30 Wed>
SCHEDULED: <2021-06-29 Tue>
#+end_src
* Org mode: Quick file navigation
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897029442
:END:
** Front
Give some ways how to navigate Org mode documents quickly.
** Back
- I don't need to explain what ~org-babel-next-src-block~ and ~org-babel-previous-src-block~ does.
- ~org-backward-heading-same-level~ is the same as ~org-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.
* Editing source code blocks in Org mode documents
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620897029913
:END:
** Front
What function creates a buffer for certain elements in org-mode but it is especially useful for editing source code blocks where it will open with the correct major mode?
** Back
~org-edit-special~
* Practices for studying
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1620899219164
:END:
** Front
Give various practices for studying effectively.
** 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.
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~.
* Emacs Lisp conditionals
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1621570142444
:END:
** Front
Give some functions for creating a conditional in Emacs Lisp.
** Back
Below are the common way to control the flow with Elisp.
* Factors to consider when choosing an architecture for cloud applications
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1623240125201
:END:
** Front
Give the factors to consider how a cloud application should be made of.
** Back
- Scalability
- Development complexity
- Time to deploy
- Flexibility
- Reliability
- Operational costs
For easier memorization, just use the mnemonic "Slide down to Freedom Ravine, Olsen."
Take note that however you compose an application whether with a monolistic or composable approach, there are tradeoffs to consider.
For example, with reliability that describes the ability to recover from a failure, a monolith application would have to retrieved with its entire stack.
Composable services only require the faulty service to be examined.
* Monolith and microservices
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1623240125447
:END:
** Front
What are monolith and microservices?
** Back
*A monolithic application store all of its components in one repository.*
It is usually done in one programming language to tie everything together.
While it is nice to have it bundled in one package, a monolith can easily reach limit and scale slower.
Furthermore, for debugging, it would take a reproduction of the whole stack to get an idea of what is happening.
*On the other hand, an application built with microservices is just a bundle of individual services.*
Each component can be developed in parallel and made up of wildly different tools and languages appropriate for their purpose.
Since components are individualized, you can just inspect one of the components.
* Duckduckgo bangs
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1623240125883
:END:
** Front
List some Duckduckgo bangs you often use.
** Back
As of 2021-06-09, here are some of the bangs I use.
- =wikipedia= or =w=
- =google= or =g=
- =twitter= or =tw=
- =github= or =gh=
- =youtube= or =yt=
- =twitch= or =ttv=
- =archwiki= or =aw=
- =researchgate= or =rgate=
- =arxiv= or =arx=
- =orcid=
* Best application development practices
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1623400715411
:END:
** Front
Give the list of practices and their summary from the SUSE Cloud native fundamentals scholarship program.
** Back
- *Health checks provide a way to check if a component is active.*
- *Metrics provides quick feedback such as the number of active users, number of logins for today, and how many users know a certain feature (or clicked the button).*
- *Logs records what happened on your application** thus making debugging easier.
A recommended practice for logging is creating log levels to indicate the severity of the problem and attaching a timestamp.
- *Tracing lets you recreate how a request is done*, often through multiple services.
Oftentimes, this is done on application-level.
- *Knowing the resource consumption is good for assessing whether the application is ready.*
Examples include monitoring the CPU and memory consumption during a service and creating benchmarks.
If you're deploying a web application, for example, you may assign certain routes for some of the above practices — e.g., =/status/= for health checks, =/metrics/= to create a metrics dashboard.
* Cloud Native Computing Foundation
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1623400715709
:END:
** Front
What is the Cloud Native Computing Foundation (CNCF) do and how do they contribute?
** Back
CNCF is an organization that spearheads the development of cloud computing.
It hosts and manages a [[https://www.cncf.io/projects/][plethora of cloud-related projects]] representing a whole suite of tools needed for cloud computing management.
As of 2021-06-09, CNCF managed some of the popular cloud-related tools of today like Prometheus (metrics), Kubernetes (orchestration), containerd (container runtime), Jaeger (tracing), among others.
* Container workflow
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1623986971249
:END:
** Front
Summarize the workflow of using containers with a container engine (e.g., Docker, Podman).
** Back
- Create a file containing instructions how to build an image.
- Build the actual image with the container engine (e.g., Docker, Podman) and the instruction file (e.g., Dockerfile, Buildpack).
- Create a container from the image running the application.
- If successfully created one, you can publish the image in a registry (e.g., docker.io).
* Kubernetes resources
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1623986971597
:END:
** Front
List the resources Kubernetes manages in a cluster.
** Back
- *Pod is a group of containers* that run on nodes.
- *Node is a representation of a computer.*
This may be a physical or a virtual computer to run multiple pods at a time.
- *Deployment contains the state of the pods.*
- *Replica set ensures the pod is running at any given time by creating a set of identical pod.*
- *Service creates a single point for pods.*
- *Ingress lets an external user access to the cluster*, typically using HTTP.
- *ConfigMap manages the secrets of a cluster.*
- *Namespaces create separation between applications.*
For easier memorizing, think of the name "DR SICPNN".
Take note it is not an exhaustive list as it usually manages more than 10 resources.
You can see what Kubernetes handle with the =api-resource= subcommand.
* Kubernetes external user access
:PROPERTIES:
:ANKI_NOTE_TYPE: Styled cards
:ANKI_NOTE_ID: 1623986971836
:END:
** Front
Since nodes in a Kubernetes cluster are normally accessed only within, is third-party access possible?
** Back
[[https://kubernetes.io/docs/concepts/services-networking/ingress/][Kubernetes ingress]] is exactly built for that purpose.
It mainly does the job by exposing a resource through HTTP.
For example, if you have an application that is normally opens an HTTP server at port 5000, you can expose the application with the following command.
Assuming the application came from an image and deployed through Kubernetes (with the deployment name =hello-ports=).