diff --git a/2020-04-12-11-20-53.org b/2020-04-12-11-20-53.org index 6e31417..211f607 100644 --- a/2020-04-12-11-20-53.org +++ b/2020-04-12-11-20-53.org @@ -3,10 +3,11 @@ :END: #+title: Reproducible research #+date: "2020-04-12 11:20:53 +08:00" -#+date_modified: "2021-05-04 20:51:31 +08:00" +#+date_modified: "2021-05-19 19:01:34 +08:00" #+language: en +# TODO: Improve this note. Creating your research reproducible can create the following benefits: - Easy to verify by others. diff --git a/2020-04-15-14-35-55.org b/2020-04-15-14-35-55.org index 0d34791..1cad641 100644 --- a/2020-04-15-14-35-55.org +++ b/2020-04-15-14-35-55.org @@ -3,7 +3,7 @@ :END: #+title: Note-taking #+date: "2020-04-15 14:35:55 +08:00" -#+date_modified: "2021-05-17 08:28:46 +08:00" +#+date_modified: "2021-05-19 21:09:35 +08:00" #+language: en @@ -21,3 +21,6 @@ One could start to [[id:d024516b-35ea-40ae-9433-ceacea695073][Write paragraphs l Not all note-taking is the formal method of paraphrasing our observations and thoughts, this can also be a method of merely writing our thoughts down. We can [[id:810dc8b6-db64-4c80-a0aa-f9e6d5fa4acf][Create an inbox to store your thoughts]], create [[id:3d1c0313-fa3d-4b18-b435-51d3837e3e2c][Fleeting notes]] as a mental scratchpad. + +That said, not all practices are meant to be taken seriously. +The most subtle and most important tip to keep in mind is [[id:c6cd9441-104f-447f-9d2c-9aaead388c22][When note-taking, don't satisfy your ego]]. diff --git a/2020-04-17-21-41-30.org b/2020-04-17-21-41-30.org index dcc7ce8..96b3b02 100644 --- a/2020-04-17-21-41-30.org +++ b/2020-04-17-21-41-30.org @@ -3,148 +3,22 @@ :END: #+title: Org mode: Babel #+date: "2020-04-17 21:41:30 +08:00" -#+date_modified: "2021-05-06 00:13:13 +08:00" +#+date_modified: "2021-05-19 20:37:16 +08:00" #+language: en #+tags: research.reproducibility Babel is the framework that enables [[id:c422175a-5b65-4311-8cc6-11efd55364e8][Org mode]] to be a [[id:6eeb7a24-b662-46d6-9ece-00a5028ff4d8][Reproducible research]] tool. -It is what makes Org mode [[https://orgmode.org/manual/Working-with-Source-Code.html][works with source code blocks]]. -As of 2021-04-22, [[https://orgmode.org/worg/org-contrib/babel/languages/index.html][Babel supports more than 50 languages]] with the ability to support unsupported languages. -Though, it does have its quirks with different languages. -Your mileage may vary. +It is comparable to Jupyter and R Markdown that other computational scientists use it. +Among other features, it can do the following. +- Prints the results from code blocks. +- Create files from a single document, making it possible to create entire computational reports. +- Pass values from one code block to another, even with different programming languages. +- Create graphics similarly to Jupyter and R Markdown notebooks. +- Call code blocks either inline, as a block, or inside of another code block, thereby enabling metaprogramming and dynamic contents. +The unfortunate thing is most of these features are only available when using with [[roam:GNU Emacs]]. -* Functional and scripting mode - -Babel works in two modes: functional and scripting mode. - -- Functional mode returns a value either from the last statement or the return statement. - The value can then be used in other source code blocks and appropriately converted into Org mode equivalents. - If the return value is a vector type, it will be printed as tables in Org mode which will then be rendered as a vector when used in another source code block. - -- Scripting mode simply prints the output. - Do keep in mind different languages have different ways of capturing the output. - [fn:: Most of them involves capturing the stdout.] - -The default mode is in functional mode but you can change it by setting ~:results~ header argument with the values from the [[https://orgmode.org/manual/Results-of-Evaluation.html][collection class]]. - - - - -* Functional mode values and passing them around - -With functional mode, the value return will appear as an appropriate element in the Org mode buffer. -The following examples are in [[https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-python.html][Python]]. - -Scalar values appear as strings... - -#+begin_src python :results value -return "The quick brown fox jumps over the lazy dog." -#+end_src - -#+results: -: The quick brown fox jumps over the lazy dog. - -...and vector values print as tables. - -#+name: data -#+begin_src python :results value -return [ - ["Monty", 45], - ["Soup", 54], - ["Cabbages", 63] -] -#+end_src - -#+results: data -| Monty | 45 | -| Soup | 54 | -| Cabbages | 63 | - -To pass values between different code blocks, you have to give the blocks a name. -The previous code block was given a name ~data~ and passed it to the next block. - -#+begin_src python :results value :var o=data -return o[0] -#+end_src - -#+results: -| Monty | 45 | - - - - -* Creating dynamic content with meta-programming - -With [[https://orgmode.org/worg/org-contrib/babel/intro.html][Babel]], you can call named code blocks anywhere from blocks to inline. -This creates a "function" with Babel using different languages. -The following block creates ~init~ function with a default value for its argument. - -#+name: init -#+header: :var name="world" -#+begin_src python :results value silent :exports code -return f"Hello {name}" -#+end_src - -You can then call the ~init~ function inline with ~call_init[${HEADER_ARGS}](${ARGS})~ which should contain "call_init[:results raw]() Hello world". -For blocks, you can use the ~#+call~ block with a similar syntax to inline functions — i.e., ~#+call: init[${HEADER_ARGS}](${ARGS})~. - -#+call: init[:results replace]() - -#+results: -: Hello world - -You can also use it inside of code blocks with ~<>~ which makes it perfect for code blocks templates like configuring paper output for Lilypond blocks. -Though, you have to set ~:noweb yes~ in the header arguments or configure it in ~org-babel-default-header-args~ as one of the default. - -#+name: example -#+begin_src shell -echo -n <> -#+end_src - -#+results: example -: Hello Canavan - -Babel functions are commonly used for inserting dynamic values. -Very helpful in reducing places you need to edit (not to mention less prone to errors). - - - - -* Executing code blocks in the same session - -Each of the source code block runs on an individual session. -However, you can connect source code blocks in the same session with ~:session ~. -This allows you to cut code blocks and add more detailed explanations for them. - -Let's start with a simple example where we want to demonstrate some Python shenanigans. -Here's one Python code block. - -#+begin_src python :session python-example -x = 30 -print(x) -#+end_src - -#+results: -: 30 - -Then here's another code block in the same session. - -#+begin_src python :session python-example -for i in range(5): - x += 5 - print(x) -#+end_src - -#+results: -: 35 -: 40 -: 45 -: 50 -: 55 - -In certain code where the output can still change (for example, try executing the previous code block again), this may not be the desired behavior. -To correct this, simply execute ~org-babel-execute-buffer~. +For more details, you can see [[id:4abb9be8-4414-4045-8827-5a68632fd2a4][The basics of org-babel]]. diff --git a/2020-04-20-16-51-40.org b/2020-04-20-16-51-40.org index ebb4426..8f7b7ff 100644 --- a/2020-04-20-16-51-40.org +++ b/2020-04-20-16-51-40.org @@ -3,7 +3,7 @@ :END: #+title: Org mode #+date: "2020-04-20 16:51:40 +08:00" -#+date_modified: "2021-05-07 13:01:26 +08:00" +#+date_modified: "2021-05-19 18:33:15 +08:00" #+language: en #+tags: tools writing @@ -14,4 +14,4 @@ With these features, Org-mode is known as one of the many tools for [[id:6eeb7a2 Unfortunately, a lot of the famous powers of the format is tied with [[roam:GNU Emacs][roam:GNU Emacs]]. While there is an ecosystem flourishing outside of the text editor (e.g., [[https://github.com/niklasfasching/go-org][go-org]], [[https://github.com/orgapp/orgajs][orgajs]], [[https://pandoc.org/org.html][Org mode support in Pandoc]]), the plugins inside of Emacs simply cannot be ignored. -Among other Org mode plugins inside of the Emacs ecosystem, we have [[roam:org-roam][org-roam]], [[https://github.com/jkitchin/org-ref][org-ref]], [[https://github.com/weirdNox/org-noter][org-noter]], [[https://orgmode.org/worg/exporters/index.html][a number of exporters]], and [[https://orgmode.org/worg/org-contrib/babel/languages/index.html][org-babel language plugins]] (see [[id:5569a49f-c387-4da2-8f68-d8452e35ee5b][Org mode: Babel]]) that extends to more workflows. +Among other Org mode plugins inside of the Emacs ecosystem, we have [[roam:org-roam][org-roam]], [[https://github.com/jkitchin/org-ref][org-ref]], [[https://github.com/weirdNox/org-noter][org-noter]], [[https://orgmode.org/worg/exporters/index.html][a number of exporters]], and [[https://orgmode.org/worg/org-contrib/babel/languages/index.html][org-babel language plugins]] that extends to more workflows. diff --git a/2020-07-01-23-19-07.org b/2020-07-01-23-19-07.org index d4c0ebd..3f5c54c 100644 --- a/2020-07-01-23-19-07.org +++ b/2020-07-01-23-19-07.org @@ -3,15 +3,14 @@ :END: #+title: Information literacy #+date: "2020-07-01 23:19:07 +08:00" -#+date_modified: "2021-05-09 18:02:12 +08:00" +#+date_modified: "2021-05-20 00:00:49 +08:00" #+language: en #+tags: personal-info-management The ability to search information, sort the results, verify for legitimacy, and share the information effectively. -A very useful skill nowadays with the torrential amount of information. - -There are many ways to improve our information literacy including usage of various effective online searching, capture relevant output, and finally evaluating your search results. +A very useful skill nowadays with the torrential amount of information available from a few keystrokes away. +This includes making effective narrow searches, filtering through search results, knowing the bad from the good, and recording it somewhere in our library. Having a sharp information literacy does not only mainly seen in technical fields like in research and academia (e.g., literature reviews, peer reviews) but also on everyday life as well. In fact, all of us practice it in some way. diff --git a/2020-07-06-03-47-52.org b/2020-07-06-03-47-52.org index ccbe0be..7b52cef 100644 --- a/2020-07-06-03-47-52.org +++ b/2020-07-06-03-47-52.org @@ -3,7 +3,7 @@ :END: #+title: Refer to advanced resources when skill-building for a solid short-term goal #+date: "2020-07-06 03:47:52 +08:00" -#+date_modified: "2021-05-05 23:40:29 +08:00" +#+date_modified: "2021-05-20 00:02:52 +08:00" #+language: en @@ -15,9 +15,8 @@ You can then store the expert resources and [[id:66337935-420c-40e6-81a6-f74ab09 The purpose of this is twofold: to serve as a solid short-term goal (as indicated by the title) and to create inspirations for your future projects. Another purpose of this is to [[id:fdf9e3eb-02c5-47a6-b586-e71a5c92d01a][Look for live sessions as another form of examples]]. -Of course, this does not entirely replace looking out for beginner-friendly resources and communities as an entryway (see [[id:f0d0198c-b523-4d71-a13c-0c578dfac3ef][Information literacy]]). -In fact, it is a bad idea to start learning with the advanced resources, just take it easy. -On the other hand, this gets you out of tutorial purgatory. +Of course, this does not entirely replace looking out for beginner-friendly resources and communities as an entryway. +In fact, it is a bad idea to start learning with the advanced resources. Also this could lead into actively consuming just the resources without the practice. [[id:92a10fe2-f4d1-4e5e-b5f4-3779db13a2e5][Create roadmaps to stay on track]]. diff --git a/2020-07-10-23-30-27.org b/2020-07-10-23-30-27.org index 4d26434..629d21a 100644 --- a/2020-07-10-23-30-27.org +++ b/2020-07-10-23-30-27.org @@ -3,12 +3,10 @@ :END: #+title: Endianness #+date: "2020-07-10 23:30:27 +08:00" -#+date_modified: "2021-05-04 20:52:06 +08:00" +#+date_modified: "2021-05-19 17:37:14 +08:00" #+language: en -- Tags :: [[id:af4a2867-dfa6-4241-950d-2fdb9cf3016c][Computational processes]] - Endianness refers to how bits are read and this depends on the underlying hardware architecture. [fn:: You can enforce endianness in software but oftentimes, it is not a good idea.] diff --git a/2021-04-06-22-25-17.org b/2021-04-06-22-25-17.org index 6c47ee7..eb11199 100644 --- a/2021-04-06-22-25-17.org +++ b/2021-04-06-22-25-17.org @@ -3,14 +3,14 @@ :END: #+title: Prefer referencing over remembering #+date: "2021-04-06 22:25:17 +08:00" -#+date_modified: "2021-05-09 18:08:32 +08:00" +#+date_modified: "2021-05-19 21:55:29 +08:00" #+language: en #+tags: personal-info-management It makes for less cognitive overhead. This is especially true in the age of internet where information is widely distributed. -Even without the internet, however, it is still useful to find ways to refer to things. +Even without the internet, however, it is still useful to find ways to refer to things or store them locally whether by archiving or creating related notes. This doesn't mean that you should avert remembering, that would be silly as little remembering is still required. You're still trying to understand a concept, after all. @@ -24,7 +24,7 @@ Examples: - [[https://www.gnu.org/software/texinfo/][Texinfo]] and [[https://github.com/tldr-pages/tldr][tldr pages]]. -- [[roam:Emacs][GNU Emacs]] has a great built-in help system. +- [[roam:GNU Emacs]] has a great built-in help system. (See [[id:0efb9c51-3a12-4e5a-9e9b-d48cf4bd53ce][Using the built-in help system of Emacs]] for more details.) If the system has a way of referencing something (other than the internet), use it to your advantage as you may find something valuable. diff --git a/2021-04-22-14-00-50.org b/2021-04-22-14-00-50.org index c74fbcf..67f06c9 100644 --- a/2021-04-22-14-00-50.org +++ b/2021-04-22-14-00-50.org @@ -3,14 +3,14 @@ :END: #+title: Zettelkasten #+date: "2021-04-22 14:00:50 +08:00" -#+date_modified: "2021-05-07 11:03:37 +08:00" +#+date_modified: "2021-05-19 21:56:15 +08:00" #+language: en Zettelkasten is a note-taking method popularized by Niklas Luhmann known for his prolific writings from 400 academic articles to 70 books in a lifetime. This system, manifested as a shelf of 60,000 notes, was credited as his writing partner. -The main idea of this system is creating a global cloud of [[roam:Non-linear notes]], individually called as zettels, without any hierarchy or separation. +The main idea of this system is creating a global cloud of [[id:2713f862-6664-4f36-9a2a-b4ddadfe4c8b][Non-linear notes]], individually called as zettels, without any hierarchy or separation. This non-linear system encourages freely linking between each ideas making it easier for gaining new ideas similar to neurons in your brain. While the absence of hierarchy is good for free-linking and filling gaps between wildly different topics, those ideas have to start from somewhere. diff --git a/2021-04-26-18-59-30.org b/2021-04-26-18-59-30.org index c87f3c9..4eb9681 100644 --- a/2021-04-26-18-59-30.org +++ b/2021-04-26-18-59-30.org @@ -3,16 +3,25 @@ :END: #+title: When note-taking, don't satisfy your ego #+date: "2021-04-26 18:59:30 +08:00" -#+date_modified: "2021-05-04 20:52:10 +08:00" +#+date_modified: "2021-05-19 21:15:35 +08:00" #+language: en +Note-taking are meant as a mental scratchpad, not some sort of creative writing. +(That said, you can [[id:d024516b-35ea-40ae-9433-ceacea695073][Write paragraphs like music]].) +The time you spent making things align as if you have OCD could be spent editing and improving other notes. + +Personal notes, no matter how poorly written or unmaintained, are still valuable. +So if you have tendencies like this, just relax and correct them. :) +Trashing notes should be taken as a last resort if you're sure it is not relevant to you in the present and in the near future. +Still, you should keep in mind that [[id:3994e8d7-8d77-4f52-9650-330369e82143][Future-proofing your notes is only worth if the future is relevant]]. + Found some inconsistent titles? Improper metadata? Incorrect datetime format? Just correct them as you stumble upon them. -Similar dilemma that I've encountered include: +Other examples include: - Satisfying my obsessiveness over the little things such as sorting lines for the note metadata in alphanumerical order. - Finding the perfect note system and constantly shopping for better tools. @@ -24,7 +33,3 @@ I've written a script and as I'm not experienced in text processing, I spent mos I did learned something with the tools but I've realized it's a big waste of time especially if my notes have grown. If I found another hip and new note-taking method and it doesn't conform to the new ideal notes in my mind, then I should relax and try it out. If it's good and I integrated it, I'll simply link it to my old notes. - -My personal notes, no matter how poorly written or unmaintained, are still valuable. -So if you have tendencies like this, just relax and correct them. :) -Trashing notes should be taken as a last resort if you're sure it is not relevant to you in the present and in the near future (see [[id:3994e8d7-8d77-4f52-9650-330369e82143][Future-proofing your notes is only worth if the future is relevant]]). diff --git a/2021-05-02-23-05-42.org b/2021-05-02-23-05-42.org index d85dccc..6119764 100644 --- a/2021-05-02-23-05-42.org +++ b/2021-05-02-23-05-42.org @@ -3,7 +3,7 @@ :END: #+title: The basics of memory #+date: "2021-05-02 23:05:42 +08:00" -#+date_modified: "2021-05-14 12:58:38 +08:00" +#+date_modified: "2021-05-19 21:59:23 +08:00" #+language: en @@ -13,7 +13,7 @@ As for this note, we'll talk about the basics of memory neuroscientifically. Remebering from our basic biology lessons, we know that the brain contains *neurons that store information*. These information can be connected together with *synapses that represents a web of thoughts*. It shows why [[id:9f1f35dd-7cf9-4f47-a9a9-b647e5daa2af][We are more associative than structured]]; -indeed, we are very skilled in jumping and associating ideas. +indeed, we are very skilled in linking and jumping between ideas. You may have moments of suddenly remembering that you forgot to bring something while in the middle of your nap or a Eureka! moment where you suddenly understand why the quadratic formula makes sense. The memory can be compared to the muscles as it strengthens the more you use and decays the more you neglect. diff --git a/2021-05-07-09-22-06.org b/2021-05-07-09-22-06.org index 99d97a6..92160ac 100644 --- a/2021-05-07-09-22-06.org +++ b/2021-05-07-09-22-06.org @@ -3,7 +3,7 @@ :END: #+title: Types of notes #+date: "2021-05-07 09:22:06 +08:00" -#+date_modified: "2021-05-07 23:29:33 +08:00" +#+date_modified: "2021-05-19 21:58:25 +08:00" #+language: en @@ -36,7 +36,8 @@ The solution: free the hierarchy. Non-linear notes free you the worrying where to put the note by removing the structure. This allows to freely make notes and extend in any direction. +However, this makes it difficult if you have no idea how to get started. +Otherwise, it can take advantage that [[id:9f1f35dd-7cf9-4f47-a9a9-b647e5daa2af][We are more associative than structured]]. One of the notable features of non-linear notes is the freedom to link different topics. This is where non-linear notes like the ones found in [[id:4259636e-e0e8-49e4-8210-758ec59728a3][Zettelkasten]] or [[id:24b5e144-dda4-482c-9684-958a00d6c986][Roam Research]] tend to shine because of freedom from hierarchy. -Oftentimes, they are made to be associative but not all of them (e.g., flashcards, concept maps). diff --git a/2021-05-08-23-12-29.org b/2021-05-08-23-12-29.org index 3aff4d9..1cceb91 100644 --- a/2021-05-08-23-12-29.org +++ b/2021-05-08-23-12-29.org @@ -3,7 +3,7 @@ :END: #+title: We are more associative than structured #+date: "2021-05-08 23:12:29 +08:00" -#+date_modified: "2021-05-09 00:21:04 +08:00" +#+date_modified: "2021-05-19 22:33:08 +08:00" #+language: en @@ -11,12 +11,13 @@ Knowing [[id:25fb4ebf-2cc4-40fe-93ad-37a79aedfb41][The basics of memory]], our n Innovation often comes from combining aspects from a network of ideas. Our brain is good at relating each topic with something else. -This is subtly present in daily life mostly filled with comparisons. +This is subtly present in daily life mostly filled with links from one thing to another. -- Most conversations — e.g., "X is just Y but better", "Cuphead is the Dark Souls of run-and-gun", "Markdown is simplified HTML". -- In marketing — e.g., "This is just Y but cheaper", often features comparison with other products, our tendency to equate price to quality. +- Most conversations — e.g., "X is just Y but better", "Cuphead is the Dark Souls of run-and-gun", "Markdown is simplified HTML", "Lenen is Touhou but harder". +- In marketing — e.g., "This is just Y but cheaper", use cases presented as a narrative, comparison with other products, our tendency to equate price to quality. - In learning — e.g., "FANBOYS" to describe the English conjunction words, "Every good boy does fine" to describe the notes placed in the lines of the music sheet. +- Nostalgia — e.g., whenever we walked into an old place, we may remember the olden days. When knowing a new topic, we strive to compare between the new and the familiar things. -This tendency also stems to nostalgia. -Whenever we walked into an old place, we associate the olden days with it. +[[id:c0e4fb0e-68f2-4db4-8c3e-f5a7845738c3][Understanding comes first from memory]] including the things we already know. +We are desperate to create a hook between the new and the old as we have an inherent understanding that newer ideas are built on top of other ideas. diff --git a/2021-05-13-11-43-13.org b/2021-05-13-11-43-13.org index fae27e1..01151a7 100644 --- a/2021-05-13-11-43-13.org +++ b/2021-05-13-11-43-13.org @@ -3,11 +3,10 @@ :END: #+title: Recoll #+date: "2021-05-13 11:43:13 +08:00" -#+date_modified: "2021-05-13 15:10:56 +08:00" +#+date_modified: "2021-05-19 21:40:14 +08:00" #+language: en - A [[https://www.lesbonscomptes.com/recoll/][cross-platform desktop search engine]] that can search through [[id:ccb3bc14-a801-4ed0-b066-50b1bcd853aa][File metadata]] from various formats including HTML, text files, PDF, and more. It can be automated easily with the command line and it has a GUI available as well as various third-party frontends. Moreover, it has a Python 3 API that can extend Recoll for support to additional file formats, for example. @@ -15,5 +14,6 @@ Moreover, it has a Python 3 API that can extend Recoll for support to additional Like most web search engines, it searches through an index which has to be generated first (i.e., ~recollindex~). With the file changes, the index has to be regenerated. -Recoll is an example of a well-made application that is developer-oriented and trying to be user-friendly with the GUI. +Recoll is an example of a developer-oriented application. It has extensive user documentation that lets you extend Recoll through your own. +It features both a command line program and a graphical interface for a user-friendly option or a different way of navigation. diff --git a/2021-05-14-12-37-18.org b/2021-05-14-12-37-18.org index 31b9b3b..ab26297 100644 --- a/2021-05-14-12-37-18.org +++ b/2021-05-14-12-37-18.org @@ -3,7 +3,7 @@ :END: #+title: Learning process #+date: "2021-05-14 12:37:18 +08:00" -#+date_modified: "2021-05-14 12:55:45 +08:00" +#+date_modified: "2021-05-14 13:35:25 +08:00" #+language: en @@ -15,6 +15,8 @@ + [[id:063dfd73-dbf5-437b-b6f1-d7aeca196f31][Spaced repetition]] is often considered to be a better method of memorization. + Know how [[id:cb995494-302f-4666-b56f-ea20a8adea10][Memory palace]] is helpful in learning newer concepts. +- With the techniques considered, take a look at the common [[roam:Pitfalls and illusions of competence]]. + - After you understood the concepts, you start to see things in your own perspective. Know that [[id:114b7874-6a20-49c8-be2c-46970c7110dc][Information is only acquired when you try to make sense of it]]. [[id:d885e93b-f919-4338-a6b9-3438538e18c0][Every copy of the techniques is personalized]]. diff --git a/2021-05-17-08-47-37.org b/2021-05-17-08-47-37.org index 3b65902..904baf2 100644 --- a/2021-05-17-08-47-37.org +++ b/2021-05-17-08-47-37.org @@ -3,10 +3,11 @@ :END: #+title: We know more compared to what we understood #+date: "2021-05-17 08:47:37 +08:00" -#+date_modified: "2021-05-17 08:55:57 +08:00" +#+date_modified: "2021-05-17 08:59:18 +08:00" #+language: en +# TODO: Improve note While [[id:114b7874-6a20-49c8-be2c-46970c7110dc][Information is only acquired when you try to make sense of it]], we just know more compared to what we understood. It doesn't mean it's a bad thing as [[id:c0e4fb0e-68f2-4db4-8c3e-f5a7845738c3][Understanding comes first from memory]]. The amount of things is too great that deserve our limited attention. diff --git a/2021-04-21-16-26-50.org b/structured/editor.emacs.help-system.org similarity index 100% rename from 2021-04-21-16-26-50.org rename to structured/editor.emacs.help-system.org diff --git a/structured/text.org-mode.babel.org b/structured/text.org-mode.babel.org new file mode 100644 index 0000000..e3b1506 --- /dev/null +++ b/structured/text.org-mode.babel.org @@ -0,0 +1,147 @@ +:PROPERTIES: +:ID: 4abb9be8-4414-4045-8827-5a68632fd2a4 +:END: +#+title: The basics of org-babel +#+date: "2021-05-19 18:54:37 +08:00" +#+date_modified: "2021-05-19 21:06:37 +08:00" +#+language: en + + + +org-babel (see [[id:5569a49f-c387-4da2-8f68-d8452e35ee5b][Org mode: Babel]]) is the framework that enables Org mode features for reproducible research. +It has a variety of applications that Org mode can do in this field so let's enumerate them. + + + + +* Functional and scripting mode + +Babel works in two modes: functional and scripting mode. + +- Functional mode returns a value either from the last statement or the return statement. + The value can then be used in other source code blocks and appropriately converted into Org mode equivalents. + If the return value is a vector type, it will be printed as tables in Org mode which will then be rendered as a vector when used in another source code block. + +- Scripting mode simply prints the output. + Do keep in mind different languages have different ways of capturing the output. + [fn:: Most of them involves capturing the stdout.] + +The default mode is in functional mode but you can change it by setting ~:results~ header argument with the values from the [[https://orgmode.org/manual/Results-of-Evaluation.html][collection class]]. + + + + +* Functional mode values and passing them around + +With functional mode, the value return will appear as an appropriate element in the Org mode buffer. +The following examples are in [[https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-python.html][Python]]. + +Scalar values appear as strings... + +#+begin_src python :results value +return "The quick brown fox jumps over the lazy dog." +#+end_src + +#+results: +: The quick brown fox jumps over the lazy dog. + +...and vector values print as tables. + +#+name: data +#+begin_src python :results value +return [ + ["Monty", 45], + ["Soup", 54], + ["Cabbages", 63] +] +#+end_src + +#+results: data +| Monty | 45 | +| Soup | 54 | +| Cabbages | 63 | + +To pass values between different code blocks, you have to give the blocks a name. +The previous code block was given a name ~data~ and passed it to the next block. + +#+begin_src python :results value :var o=data +return o[0] +#+end_src + +#+results: +| Monty | 45 | + + + + +* Creating dynamic content with meta-programming + +With [[https://orgmode.org/worg/org-contrib/babel/intro.html][Babel]], you can call named code blocks anywhere from blocks to inline. +This creates a "function" with Babel using different languages. +The following block creates ~init~ function with a default value for its argument. + +#+name: init +#+header: :var name="world" +#+begin_src python :results value silent :exports code +return f"Hello {name}" +#+end_src + +You can then call the ~init~ function inline with ~call_init[${HEADER_ARGS}](${ARGS})~ which should contain "call_init[:results raw]() Hello world". +For blocks, you can use the ~#+call~ block with a similar syntax to inline functions — i.e., ~#+call: init[${HEADER_ARGS}](${ARGS})~. + +#+call: init[:results replace]() + +#+results: +: Hello world + +You can also use it inside of code blocks with ~<>~ which makes it perfect for code blocks templates like configuring paper output for Lilypond blocks. +Though, you have to set ~:noweb yes~ in the header arguments or configure it in ~org-babel-default-header-args~ as one of the default. + +#+name: example +#+begin_src shell +echo -n <> +#+end_src + +#+results: example +: Hello Canavan + +Babel functions are commonly used for inserting dynamic values. +Very helpful in reducing places you need to edit (not to mention less prone to errors). + + + + +* Executing code blocks in the same session + +Each of the source code block runs on an individual session. +However, you can connect source code blocks in the same session with ~:session ~. +This allows you to cut code blocks and add more detailed explanations for them. + +Let's start with a simple example where we want to demonstrate some Python shenanigans. +Here's one Python code block. + +#+begin_src python :session python-example +x = 30 +print(x) +#+end_src + +#+results: +: 30 + +Then here's another code block in the same session. + +#+begin_src python :session python-example +for i in range(5): + x += 5 + print(x) +#+end_src + +#+results: +: 35 +: 40 +: 45 +: 50 +: 55 + +In certain code where the output can still change (for example, try executing the previous code block again), this may not be the desired behavior. +To correct this, simply execute ~org-babel-execute-buffer~.