<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Richard's Posts</title>
    <link>https://richardwong.io/</link>
    <description>Recent blog posts by Richard Wong</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <copyright>Copyright © 2024, Richard; all rights reserved.</copyright>
    <lastBuildDate>Mon, 14 Sep 2026 22:00:00 +0800</lastBuildDate><atom:link href="https://richardwong.io/feed.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>MacBook air</title>
      <link>https://richardwong.io/post/hardware/2026-09-14-macbook-air/</link>
      <pubDate>Mon, 14 Sep 2026 22:00:00 +0800</pubDate>
      
      <guid>https://richardwong.io/post/hardware/2026-09-14-macbook-air/</guid>
      <description>&lt;p&gt;Through my undergrad and masters, I used the T480 with a Linux distro. I was
very comfortable living in a window manager, and really only used the following programs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Browser: Firefox&lt;/li&gt;
&lt;li&gt;Terminal: Foot + tmux&lt;/li&gt;
&lt;li&gt;Code Editor: VSCode&lt;/li&gt;
&lt;li&gt;PIM Text Editor: Emacs&lt;/li&gt;
&lt;li&gt;Music Player: Spotify&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Believe it or not, this was a peak grad student setup.&lt;/p&gt;
&lt;p&gt;But the T480 with an intel i5-8250u was nearly a decade old by the time of
writing this article. And it shows: large web-pages struggle, battery life is
too short, and as much as I like the tank-like build, its actually a little
heavy.&lt;/p&gt;
&lt;p&gt;Right after my masters, I went for the M4 macbook air. I really wanted to get a
new machine with one of these M-series chips. And so I got myself a 13-inch
16GB RAM variant for my personal use. Verdict? It was incredible. Everything
was smooth and fast. I admit I&amp;rsquo;m not really a super power user. I don&amp;rsquo;t edit
photos or videos. I don&amp;rsquo;t build massive applications. I just do what I did on
my T480 here on this brand new machine. And it largely stayed the same:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Browser: Firefox&lt;/li&gt;
&lt;li&gt;Terminal: cmux&lt;/li&gt;
&lt;li&gt;Code Editor: zed&lt;/li&gt;
&lt;li&gt;PIM Text Editor: Obsidian&lt;/li&gt;
&lt;li&gt;Music Player: Spotify&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I decided to shift to a more modern set of tools. Emacs and Org-mode is
amazing, but I realized that I want an easier
batteries-included experience. I don&amp;rsquo;t want to spend a few days setting up a
single editor. And obsidian being already in markdown makes it easy to share
notes.&lt;/p&gt;
&lt;p&gt;And more recently, I&amp;rsquo;ve begun using terminal coding agents on my personal
machine (I was already using Claude heavily at work). I installed Pi agent in a
minimal configuration and paired it with OpenRouter to use low-cost chinese
LLMs, and its been awesome. I could git-clone things I wouldn&amp;rsquo;t have dreamed of
trying and use Pi to read and write markdowns for me to understand new
projects. One really cool thing is trying to run some Metal shader programs to
get a sense of graphics programming for the first time. My workflows therefore
exist more in the terminal these days as I use Pi + neovim for most development
work. I hardly open the editor except to have an easy place to read the
changes.&lt;/p&gt;
&lt;p&gt;The other thing that I was concerned about was the keyboard. Considering how
thin the machine is, and how much key travel the ThinkPad has, I was a little
worried that this is one area where the experience would suffer. But its been
fine. But the trackpad&amp;hellip; It wasn&amp;rsquo;t clear to me initially, until I returned to
my ThinkPad and it was such a big downgrade. Apple got the physics and feel
right without much tweaking, and that&amp;rsquo;s amazing to me.&lt;/p&gt;
&lt;p&gt;I was able to get most of the workflow / use-cases from my old machine to the
Mac with not too many changes. I think its unix base helped a lot with helping
to bring a lot of linux-isms to the Mac. I use a combination of nix-darwin and
brew to install packages and software. In some sense its more advanced than
some linux systems. But in the areas of Docker and containers, it definitely
has some downsides. Macs need a VM to run linux containers. I use Colima, which
is one of the lighter options. But it needs to provision a part of your memory
to run the VM. But otherwise, its been feeling almost like native. I think
having a linux machine that is always on (a server) and using that for docker
work is a better option since most applications need to talk through network
interfaces and ports anyway. A native linux deployment is better if its
accessible.&lt;/p&gt;
&lt;p&gt;The battery life. The M4 chip truly lived up to its reputation. It sips very
little power for my regular tasks. It feels like Apple has solved the issue of
battery anxiety. Also, I realized that if I set it to low-power mode, I hardly
notice any changes to performance and I can stretch the power even further.
Having the memory situated so close to the SoC works wonders for power as the
electrons don&amp;rsquo;t need to travel as much (if you do not know, most of the power
in ICs today is spent on moving electrons from point A to point B rather than
actual computation).&lt;/p&gt;
&lt;p&gt;The MacBook air has been a great purchase and works very well as my personal
casual-use machine. I&amp;rsquo;m so glad that things just work and I don&amp;rsquo;t have to spend
too much time fiddling with things that are breaking. I also use a MacBook Pro
(M4 Pro) for work, but I&amp;rsquo;ll talk about that on another day.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>An Overview of the projects in my Master&#39;s Course</title>
      <link>https://richardwong.io/post/research/2025-04-22-tue-an-overview-of-the-projects-in-my-masters-course/</link>
      <pubDate>Tue, 22 Apr 2025 20:49:00 +0800</pubDate>
      
      <guid>https://richardwong.io/post/research/2025-04-22-tue-an-overview-of-the-projects-in-my-masters-course/</guid>
      <description>&lt;p&gt;I have graduated from my master&amp;rsquo;s course back in February 2025. It had been an
incredibly busy and intense 2 years. I would like to share about my experience
from the past 2 years, from the beginning to the end.&lt;/p&gt;
&lt;h2 id=&#34;the-very-beginning&#34;&gt;The Very Beginning&lt;/h2&gt;
&lt;p&gt;In the very first semester, I decided to take things slow. At that time, I had
only been in Korea for 6 months. If I had the choice, I would have delayed my
entry into the master&amp;rsquo;s. Korea was still quite new to me, and my command of the
Korean language was still not particularly good. I had only finished what was
the equivalent of TOPIK level 2 in the university&amp;rsquo;s Korean course. I was at the
level at which I &lt;em&gt;could&lt;/em&gt; survive, but it was not optimal.&lt;/p&gt;
&lt;p&gt;On the very first day of entering the lab, I recall the Professor being a little
disappointed that I could not speak fluently. Also, I was essentially a Stats
guy finding myself in a CS lab. I was a little worried if it might just be a
little too much for me to chew.&lt;/p&gt;
&lt;h2 id=&#34;quantum-computing&#34;&gt;Quantum Computing?&lt;/h2&gt;
&lt;p&gt;The very first project that I was tasked with was to study quantum computing. It
was quite jarring initially as no one in the lab had any experience with it. I
had only 1 job: to study quantum computing and report on what I learned. I
studied from a book titled &amp;ldquo;Quantum Computation and Quantum Information&amp;rdquo; &lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
and slowly worked through the chapters. It was quite an odd feeling as I found
out quickly that understanding about quantum states from the perspective of a
continuous probability state was much better than trying to think about the
weirdness of quantum properties. If I treat it as a purely mathematical
construct with clearly defined properties (like all states summing to 1), I
could start to reason with it and slowly work out simple quantum computing
operations. But this book was entirely theoretical, and my Professor wanted me
to start flying when I had just learned how to crawl.&lt;/p&gt;
&lt;p&gt;To put things into practice, I started to learn the Qiskit &lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt; python quantum
computing library. Everything was simulated on my &amp;ldquo;classical&amp;rdquo; computer. The
library allowed me to play with a handful of qubits (7?) and to construct
quantum circuits with simple gates to encode information and put qubits into
superposition. Before long, the Professor wanted my team to come up with a
research proposal. It was crazy, but we tried to produce something,
anything. The idea was to use study the use of quantum kernels as a layer within
a neural network. We actually wrote a differentiable parameterized quantum
circuit! But it was clear that with &amp;lt; 10 qubits this network is not going to do
anything useful. And so the project came to an end.&lt;/p&gt;
&lt;h2 id=&#34;graph-drawing&#34;&gt;Graph Drawing&lt;/h2&gt;
&lt;p&gt;Right after ending the quantum machine learning project, we received a new
project: produce a program to output any graph as an &amp;ldquo;aesthetic&amp;rdquo; graph. For the
first 2 weeks, we could not even define the actual requirements. We didn&amp;rsquo;t even
know what &amp;ldquo;aesthetic&amp;rdquo; meant. The only thing that the team lead said was it
needed to be straight lines that bend at 90 degrees. Everything else was up to
us. We tried to google and use the then brand new GPT3 to better define this
problem but it always came up short.&lt;/p&gt;
&lt;p&gt;The first breakthrough came when I found the GraphViz &lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt; library. Using its
python version PyGraphViz &lt;sup id=&#34;fnref:4&#34;&gt;&lt;a href=&#34;#fn:4&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;4&lt;/a&gt;&lt;/sup&gt;, I was able to produce hierarchical drawings of
directed graphs with 90 degree bends. It looked great and it seemed like it
solved the problem. But a few discussions later, they wanted orthogonal graphs,
not hierarchical graphs.&lt;/p&gt;
&lt;p&gt;The second breakthrough came when I found the Open Graph algorithms and Data
structures Framework (OGDF) &lt;sup id=&#34;fnref:5&#34;&gt;&lt;a href=&#34;#fn:5&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;5&lt;/a&gt;&lt;/sup&gt;. It had exactly what we needed: orthogonal
graphs. And it delivered the exact results we needed. However, the higher-ups
will not be satisfied with what amounts to an off-the-shelf solution from an
open-source project. They wanted to know how it works, and so I had to study
deeply the process of how an orthogonal graph is produced. Frankly, it still
seems like black magic to me as the field of graph visualization seems to be
locked behind an endless sea of theorems. But I could give a rough explanation
for what the code is doing. It was really painful as the resources were mainly
past conference papers that assumed a high-degree of domain knowledge. But we
managed to deliver a product that could draw orthogonal graphs when given graph
definition.&lt;/p&gt;
&lt;h2 id=&#34;battery-anomaly-detection&#34;&gt;Battery Anomaly Detection&lt;/h2&gt;
&lt;p&gt;By this point there is a trend: upon ending a project, another project will
begin. This new project&amp;rsquo;s problem statement is as follows: given the time series
of an industrial battery unit, identify anomalies, any anomalies. This project
started in a very painful manner as I was only given a zip file with limited
documentation (a single .txt file). It turns out that it was an Influxdb data
store, and I had to load the time series data from that store. But the power of
Arch Linux came in clutch, as I installed Influxdb from the AUR and ran a local
instance of the Influxdb server with some help from the Influxdb documentation
and extracted the data into CSV&amp;rsquo;s for my team to access the data.&lt;/p&gt;
&lt;p&gt;This is the first time I finally encountered a dataset that was nearly unusable
because of how messy it was. There were NA&amp;rsquo;s everywhere and values that exceeded
the sensor ranges according to the documentation (because the logging machine
would log erroneous values when the battery state is undefined). We spent a lot
of time trying to cleanup the data and to extract any signal from the data. The
data was simply too big to eyeball for features, and so I relied on a technique
that used LSTM&amp;rsquo;s to reconstruct time series. Any time the reconstruction error
goes above a threshold, the code would flag an anomaly. And&amp;hellip; it was still
inconclusive. The data was practically useless.&lt;/p&gt;
&lt;p&gt;And one day I decided to read through the manufacturer&amp;rsquo;s battery guide carefully
and saw that the battery already had a dedicated anomaly logging functionality
which they just didn&amp;rsquo;t log into the Influxdb store. After discussing with the
higher-ups, we were simply not needed anymore after that. And just like that the
project ended.&lt;/p&gt;
&lt;h2 id=&#34;battery-lifetime-simulation&#34;&gt;Battery Lifetime Simulation&lt;/h2&gt;
&lt;p&gt;But since our project contract lasted longer, we were tasked to contribute
anything to this battery project. I then proposed that we can perform
predictions on the lifetime of the battery unit based on known usage patterns of
the battery. This is when it became frankly a bit crazy. Firstly, we had to
reverse engineer the specifications of the unit, from the arrangements of the
cells, down to the exact make and model of the cell. We then tried to study the
usage patterns of the battery, and created a poisson process model to run the
battery with variable patterns that over a period of time average out to a mean
that we set in the model. We used a physics-based battery simulation library,
BLAST &lt;sup id=&#34;fnref:6&#34;&gt;&lt;a href=&#34;#fn:6&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;6&lt;/a&gt;&lt;/sup&gt;. And&amp;hellip; the results were again inconclusive. Simulating things is
hard! We could not predict the knee-point (the point of rapid deterioration) of
the battery. The simulation model was too sensitive to certain parameters, and
tweaking the parameters would either cause the cell to last forever or last only
a few days. We had to shelve the project.&lt;/p&gt;
&lt;h2 id=&#34;graph-planarization&#34;&gt;Graph Planarization&lt;/h2&gt;
&lt;p&gt;By the start of 2024, I felt like I had not rested and was just slinging myself
from one project to the next. But in order to graduate, I had to publish a paper
in either a journal or a conference. I decided to focus on writing a conference
paper as it seemed like the requirements were a little easier, and the
turn-around time was faster than a journal. The project that intrigued me was
oddly from the graph drawing project. I decided to focus on a sub-problem, graph
planarization. And so I got started with testing some ideas that I had. I tried
to benchmark my methods against a reference implementation and my methods would
always lose to the reference implementation. But as time went by, I kept writing
in new optimizations to make my implementation faster and faster. By the end of
March, I found that across a test dataset, my method would start to win in many
of the cases. I was confident that this method would be a good paper, and so I
wrote a paper to submit for the 2024 Graph Drawing Conference. By the end of
May, I submitted by conference paper and eagerly waited for the result on 20
July.&lt;/p&gt;
&lt;p&gt;After I submitted by paper, I finally had some time to rest in June of 2024. I
took plenty of rest and tried not to open my laptop. I was quite anxious waiting
for the result of my conference paper, but I just tried to focus on the other
aspects of my life. Finally, when 20 July came, I did not receive any news. I
started to have a bad feeling, and on the morning of the 21st, I received the
email &amp;ldquo;We regret to inform you that&amp;hellip;&amp;rdquo; I was utterly distraught. Not only have
I wasted the past half a year, but with only 1 semester left, I urgently needed
to produce a publication.&lt;/p&gt;
&lt;h2 id=&#34;silicon-etching-arcing-anomaly-detection&#34;&gt;Silicon Etching Arcing Anomaly Detection&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s wind back time to March 2024. I started working on a time series anomaly
detection problem from a Korean semiconductor company. They had a very specific
problem of wanting us to create a method to detect anomalies within their
machine data. I applied the same code from the earlier battery anomaly detection
project on this problem and found again that the model doesn&amp;rsquo;t work well on the
given data. It would predict too many false positives, making it almost
useless. Scaling the threshold to be less sensitive would make it miss all the
actual anomalies.&lt;/p&gt;
&lt;p&gt;We did not make any progress for months, but sometime in May, the company
contact suggested that we try to convert the time series data into images via
Gramian Angular Fields (GAF). I didn&amp;rsquo;t think that it would help much as I was
too fixated on using the method of LSTM time series reconstruction. But my lab
partner Daniel urged me to think about it carefully. Almost by chance, I was
working on unsupervised image learning in December of 2023 for a class. I
decided to apply the unsupervised objective to train an image embedding model on
the image-transforms of the time series data. The resultant embeddings were a
great success as the images containing the anomalies produced embeddings that
could be flagged as anomalies when combined with K-means clustering.&lt;/p&gt;
&lt;p&gt;Coming back to the July of 2024, I was faced with the choice of
either 1. continuing with my just rejected paper, 2. write a new paper using my
previous project. I opted to write a new short paper for a local conference
using the unsupervised anomaly detection method on GAF images. I removed the
company data and replaced it with the UCR time series classification
archive &lt;sup id=&#34;fnref:7&#34;&gt;&lt;a href=&#34;#fn:7&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;7&lt;/a&gt;&lt;/sup&gt; and retrained all the models. The results were good enough for me
to write a paper, and by September, my paper was accepted. I could finally graduate.&lt;/p&gt;
&lt;h2 id=&#34;hyundai-data-standardization&#34;&gt;Hyundai Data Standardization&lt;/h2&gt;
&lt;p&gt;Again let&amp;rsquo;s wind back to the start of 2024. (This makes it project no. 3 in the
same time frame). I was introduced to a project from Hyundai which required me
to map variable item names to standardized item names. Because of the ML hype,
one of the requirements of the project was that it must use a language model to
solve the data standardization problem. Before this, I had only dabbled in LSTMs
and ResNets. It would be the first time I would use Transformers, though I had
learned about it conceptually in class. The HuggingFace NLP/LLM course &lt;sup id=&#34;fnref:8&#34;&gt;&lt;a href=&#34;#fn:8&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;8&lt;/a&gt;&lt;/sup&gt;
was incredibly helpful in helping me be able to go from 0 to 100 in a matter of
weeks. I could quickly give a demo of a fine-tuned T5 seq-to-seq model that
could give ~90% accuracy for the data standardization task.&lt;/p&gt;
&lt;p&gt;However, the real challenge then is trying to identify why the remaining 10%
could not be solved by the model. Every week we would try different techniques
to augment the pre-processing to allow the model to learn better e.g. using
special tokens to mark input boundaries.&lt;/p&gt;
&lt;p&gt;This project allowed me to see the trouble of trying to apply a pretrained model
on a new problem domain: ensuring the reliability of predictions for the use
case. We eventually had to use embedding comparisons to try to &amp;ldquo;correct&amp;rdquo; bad
predictions. The idea is that for a given test data, we would find using
embedding vector similarity the top few closest training data inputs. And if we
compare their predictions, there should be an agreement. This seems like a kind
of K-nearest neighbors method that uses embedding cosine similarity to verify
the predictions from the seq-to-seq model. This was able to raise the model
performance from ~90% to ~95%.&lt;/p&gt;
&lt;p&gt;I was able to co-author a paper on this method, and it was published to IEEE
access under the title &amp;ldquo;Enhancing Maritime Data Integration for Platform
Services with Sequence-to-Sequence Models and Statistical
Refinement&amp;rdquo; &lt;sup id=&#34;fnref:9&#34;&gt;&lt;a href=&#34;#fn:9&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;9&lt;/a&gt;&lt;/sup&gt;. I&amp;rsquo;m glad to be able to publish a paper from the time in my
master&amp;rsquo;s.&lt;/p&gt;
&lt;h2 id=&#34;reflection&#34;&gt;Reflection&lt;/h2&gt;
&lt;p&gt;Looking back, I really poured my life into the lab projects. There were many
moments when I had maybe 2-3 concurrent major projects and I would continue to
deliver results each week. I guess a good part of being able to do so was simply
becaues I enjoyed the process. It was fun to come up with new ideas for real
problems, and though most would not work, it was great in the times when it
does.&lt;/p&gt;
&lt;p&gt;But now that I&amp;rsquo;ve graduated, I&amp;rsquo;m consolidating my experience and planning what
to do next. I hope that I can continue exploring and building things.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Nielsen, M. A., &amp;amp; Chuang, I. L. (2010). Quantum Computation and Quantum
Information: 10th Anniversary Edition. Cambridge: Cambridge University Press.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://docs.quantum.ibm.com/guides&#34;&gt;https://docs.quantum.ibm.com/guides&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://graphviz.org&#34;&gt;https://graphviz.org&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:4&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://pygraphviz.github.io/&#34;&gt;https://pygraphviz.github.io/&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:4&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:5&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://www.ogdf.net/&#34;&gt;https://www.ogdf.net/&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:5&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:6&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://www2.nrel.gov/transportation/blast&#34;&gt;https://www2.nrel.gov/transportation/blast&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:6&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:7&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://www.cs.ucr.edu/%7Eeamonn/time_series_data_2018/&#34;&gt;https://www.cs.ucr.edu/%7Eeamonn/time_series_data_2018/&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:7&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:8&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://huggingface.co/learn/llm-course/en/chapter1/1&#34;&gt;https://huggingface.co/learn/llm-course/en/chapter1/1&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:8&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:9&#34;&gt;
&lt;p&gt;H. Hwang, R. Wong, D. Lim, J. Kang and I. Joe, &amp;ldquo;Enhancing Maritime Data
Integration for Platform Services With Sequence-to-Sequence Models and
Statistical Refinement,&amp;rdquo; in IEEE Access, vol. 13, pp. 58636-58648, 2025,
&lt;a href=&#34;https://doi.org/10.1109/ACCESS.2025.3555272&#34;&gt;https://doi.org/10.1109/ACCESS.2025.3555272&lt;/a&gt;.&amp;#160;&lt;a href=&#34;#fnref:9&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Epubs and html</title>
      <link>https://richardwong.io/post/tools/2024-04-28-sun-epubs-and-html/</link>
      <pubDate>Sun, 28 Apr 2024 21:53:00 +0900</pubDate>
      
      <guid>https://richardwong.io/post/tools/2024-04-28-sun-epubs-and-html/</guid>
      <description>&lt;h2 id=&#34;motivation&#34;&gt;Motivation&lt;/h2&gt;
&lt;p&gt;I knew that an epub format is actually a zip file containing a whole bunch of
html files. You can open the individual html files in a browser if you want, and
if you can find the content page, you can jump to any page in the book via table
of contents (toc) links. I actually used this strategy to read some books for a
while, but the fact that I have to hunt for the toc page each time proved to be
annoying.&lt;/p&gt;
&lt;p&gt;There exist plugins that allow you to open and read epubs directly in the
browser. However, this is usually some kind of javascript code that runs an epub
application from within the browser. Though this is convenient, the fact that
the browser itself is a highly performant html rendering machine means that I
can just skip the javascript stuff and open the html files directly with the
browser.&lt;/p&gt;
&lt;p&gt;The solution to this issue is generating a single page html from an epub.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://richardwong.io/post/tools/2024-04-28-sun-epubs-and-html/screenshot_2024-04-28-210513.png&#34;
    alt=&#34;Figure 1: Look at the simplicity of a plain html book!&#34;&gt;&lt;figcaption&gt;
      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 1: &lt;/span&gt;Look at the simplicity of a plain html book!&lt;/p&gt;
    &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id=&#34;using-calibre&#34;&gt;Using Calibre&lt;/h2&gt;
&lt;p&gt;My initial solution was just to use Calibre. Calibre has a &amp;ldquo;Convert Books&amp;rdquo;
functionality where you can set your &lt;code&gt;epub&lt;/code&gt; as the input format and set &lt;code&gt;htmlz&lt;/code&gt; as
the output format. This will create a &lt;code&gt;.htmlz&lt;/code&gt; output, where you can just unzip to
find a single-page html within. This worked surprisingly well on many of my
epubs.&lt;/p&gt;
&lt;p&gt;If you don&amp;rsquo;t want to use the GUI, you can just use the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;$ ebook-convert input.epub output.htmlz
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However there was one epub where the resulting single-page html did not have
working links. I tried to remedy the issue by trying to read the Calibre code,
and wow is it complicated. Take a look at the entry &lt;a href=&#34;https://github.com/kovidgoyal/calibre/blob/d37f436c4cb26f982c66f1ba8605e49d17d0f50a/src/calibre/ebooks/conversion/cli.py#L380C1-L380C25&#34;&gt;main
function&lt;/a&gt;
for the &lt;code&gt;ebook-convert&lt;/code&gt; python program. Because of the plugin system, there is a
lot of indirection and this requires more analysis than a weekend of
reading. The system is actually pretty impressive. You can read more of the
documentation &lt;a href=&#34;https://manual.calibre-ebook.com/conversion.html&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;using-beautifulsoup&#34;&gt;Using BeautifulSoup&lt;/h2&gt;
&lt;p&gt;But I don&amp;rsquo;t need the flexibility to convert between any 2 formats. My goal is
simple: obtain a single-page html. And sometimes reducing your requirements can
simplify the required code greatly.&lt;/p&gt;
&lt;p&gt;The problem isn&amp;rsquo;t merging the html files, as it is trivial to do in the
terminal.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;$ cat a.txt b.txt &amp;gt; c.txt
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The problem is that the hrefs originally pointed to the html files, so if you
just concatenated the files together without adjusting the links, clicking on
the links would lead you nowhere. The hrefs had the following syntax:
&amp;ldquo;part00XX.html#some-random-string&amp;rdquo;. That means that when you clicked on the
links, it did not go to the section with the id of the corresponding string, but
it tries to open a non-existent html document.&lt;/p&gt;
&lt;p&gt;The solution is just to remove the string prior to &amp;lsquo;#&amp;rsquo;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;# strip the .html file name and preserve the id string, prepend with # to tell it is a href
for link in output_doc.find_all(&#39;a&#39;):
    href = link.get(&#39;href&#39;)
    if href and href.startswith(&#39;text&#39;):
        # Update the link to point to the correct section within the merged document
        index = href.find(&#39;#&#39;)
        link[&#39;href&#39;] = f&#39;{href[index:]}&#39;

    if href and href.startswith(&#39;part&#39;):
        # Update the link to point to the correct section within the merged document
        index = href.find(&#39;#&#39;)
        link[&#39;href&#39;] = f&#39;{href[index:]}&#39;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In each of the html files, the format was as such:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-html&#34;&gt;&amp;lt;?xml version=&#39;1.0&#39; encoding=&#39;utf-8&#39;?&amp;gt;
&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot; xmlns:epub=&amp;quot;http://www.idpf.org/2007/ops&amp;quot; lang=&amp;quot;en-US&amp;quot; xml:lang=&amp;quot;en-US&amp;quot;&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;...&amp;lt;/title&amp;gt;
    &amp;lt;link href=&amp;quot;../stylesheet.css&amp;quot; rel=&amp;quot;stylesheet&amp;quot; type=&amp;quot;text/css&amp;quot;/&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body id=&amp;quot;uMbqldEtLexUca2edkuNPBH&amp;quot; class=&amp;quot;calibre&amp;quot;&amp;gt;
  &amp;lt;div class=&amp;quot;some-attribute&amp;quot;&amp;gt;some content&amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice that the id is by itself (there is no prepended html file string). This
is good. That means that if I combined the html files by their body, then I
retain the original id&amp;rsquo;s, which I can refer to using the hrefs. However trying
the following in BeautifulSoup did not work too well:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;for file in html_files: # html_files contain the path names for every html file in directory
    with open(file, &#39;r&#39;) as html_file:
        soup = BeautifulSoup(html_file, &amp;quot;html.parser&amp;quot;)
        body_content = soup.find(&#39;body&#39;)
        output_doc.append(body_content.extract())
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The resulting output file had only 1 body tag. Apparently it forces every body
content into a single body tag. That means the corresponding id of all the body
tags were lost.&lt;/p&gt;
&lt;p&gt;A hack to get around this is to hide the body in a div:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;for file in html_files:
    with open(file, &#39;r&#39;) as html_file:
        soup = BeautifulSoup(html_file, &amp;quot;html.parser&amp;quot;)
        body_content = soup.find(&#39;body&#39;)
        # the trick to preserve the id is to hide the body in a div
        div = output_doc.new_tag(&#39;div&#39;, id=body_content.get(&#39;id&#39;))
        div.append(body_content.extract())
        output_doc.append(div)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Doing so preserves the body tags. I&amp;rsquo;m not sure if using the same id for both the
div and body is harmful, but it gets the job done. Now my document has defined
id&amp;rsquo;s.&lt;/p&gt;
&lt;p&gt;Now the document should contain links that are defined and functional. The code
required to do all the above and more can be found in this
&lt;a href=&#34;https://git.richardwong.io/richard/epub_to_html&#34;&gt;repo&lt;/a&gt;. The nbviewer view of
the notebook can be found
&lt;a href=&#34;https://nbviewer.org/urls/git.richardwong.io/richard/epub_to_html/raw/branch/main/bs4_approach.ipynb&#34;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;styling&#34;&gt;Styling&lt;/h2&gt;
&lt;p&gt;Epubs generally include a style sheet, so its useful if you also add the same
stylesheet to your html document.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;# Create a new head tag
head_tag = output_doc.new_tag(&#39;head&#39;)
# Create a link tag for the stylesheet
link_tag = output_doc.new_tag(&#39;link&#39;, rel=&#39;stylesheet&#39;, type=&#39;text/css&#39;, href=&#39;style.css&#39;)
# Append the link tag to the head tag
head_tag.append(link_tag)
# Insert the head tag into the HTML document
if output_doc.head:
    output_doc.head.insert_before(head_tag)
else:
    output_doc.insert(0, head_tag)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In your stylesheet, you can set the width of your document to 700px so that it
doesn&amp;rsquo;t span the whole screen. I like to also center it by setting auto
margins. For which element to apply the css to, I found that applying it to
&amp;ldquo;body&amp;rdquo; or &amp;ldquo;.calibre&amp;rdquo; for calibre exported epubs works.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-css&#34;&gt;.calibre {
  display: block;
  font-size: 1em;
  margin: auto;
  width: 700px;
  padding-left: 0;
  padding-right: 0;
  text-align: justify;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you want to be even more fancy, you can set the background color to something
like Sepia:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-css&#34;&gt;body {
    background-color: #e4ded3;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or even dark mode:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-css&#34;&gt;body {
  background-color: #000000; /* Black background color */
  color: #FFFFFF; /* White text color */
}
/* Normal link color */
a {
  color: #1E90FF; /* Dodger blue */
}
/* Visited link color */
a:visited {
  color: #8A2BE2; /* Blue violet */
}
/* Hover link color */
a:hover {
  color: #FFD700; /* Gold */
}
/* Active link color */
a:active {
  color: #FFA500; /* Orange */
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The result:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://richardwong.io/post/tools/2024-04-28-sun-epubs-and-html/screenshot_2024-04-28-214759.png&#34;
    alt=&#34;Figure 2: look, dark mode!&#34;&gt;&lt;figcaption&gt;
      &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 2: &lt;/span&gt;look, dark mode!&lt;/p&gt;
    &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id=&#34;concluding-thoughts&#34;&gt;Concluding thoughts&lt;/h2&gt;
&lt;p&gt;I really enjoy reading a lot more now that I have a single page html. It is
really convenient to have the book in a tab that restores when you re-open the
browser. I find myself reading online pages really quickly, so having a book on
standby in one of the tabs means that I can just jump back to reading a book
just as quickly as reading social media posts.&lt;/p&gt;
&lt;p&gt;Also, I really love html. It is probably one of the best portable text formats
there is. Just some simple lines of css and my reading experience is
enhanced. If you haven&amp;rsquo;t tried out this form of reading yet, I highly encourage
you to give it a shot!&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Simple tools in a time of worsening software</title>
      <link>https://richardwong.io/post/ramblings/2024-04-21-sun-simple-tools-in-a-time-of-worsening-software/</link>
      <pubDate>Sun, 21 Apr 2024 23:48:00 +0900</pubDate>
      
      <guid>https://richardwong.io/post/ramblings/2024-04-21-sun-simple-tools-in-a-time-of-worsening-software/</guid>
      <description>&lt;p&gt;A &lt;a href=&#34;https://jmmv.dev/2023/06/fast-machines-slow-machines.html&#34;&gt;post&lt;/a&gt; and the
corresponding &lt;a href=&#34;https://news.ycombinator.com/item?id=36503983&#34;&gt;HN discussion&lt;/a&gt; has
given words to some observations and thoughts that I had recently on the
software that I&amp;rsquo;ve used. The premise is this: computers have gotten much faster,
but our experience of software has gotten worse.&lt;/p&gt;
&lt;p&gt;There are many ways that software can suck. It could be slow, it could be
unintuitive, it could change often, it could be too complex, it could have ads
and so the list goes&amp;hellip; But there is indeed a common solution to the common
gripes of user-facing software: make it really focused on what needs to be done
and keep driving home that one focus.&lt;/p&gt;
&lt;p&gt;One of the best software that I&amp;rsquo;ve ever used on windows was SumatraPDF. It has 1
goal: to let you read PDFs. It opens fast, it scrolls smoothly, it gets the job
done. The very anti-thesis of SumatraPDF is ironically from the creators of the
PDF format, Adobe Reader. It takes an eternity to open, it has too many buttons,
it has locked features, is constantly trying to upsell you to some Adobe
subscription etc. It has many features, but near the bottom of the list of concerns
is letting you read the PDF that you just opened. I feel that many programs are
allowed to become such monstrosities because of misaligned goals and
interests. Adobe will never give you a SumatraPDF simply because it will not get
you to buy a new product. It has to be slow, annoying and possess ads so that
you can be forced to get the next best thing. But who made SumatraPDF? 2
guys. And maybe a couple of maintainers. &lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; Two men made a software that
could beat the product of a multi-billion corporation. And this is the thing
that really makes me excited about software. A man with a focused vision and
some motivation can make all the difference.&lt;/p&gt;
&lt;p&gt;Its been a long time since I last used SumatraPDF, but the same philosophy applies:
can I use software that does one thing really well, in probably the simplest way
to go about it? And in the land of free software, you can find many gems like
SumatraPDF. A counterpart to SumatraPDF in the Linux land is zathura. Open a
file with Zathura and it shows the PDF and thats it. It opens instantly, and you
can jump to any page with Vim navigation keys. If a vista-era computer can open
SumatraPDF, it feels like an embedded processor can run Zathura. Its even more
simple and I love it. I started to challenge myself to see what I can remove
from my system and to adapt my workflow to simpler and simpler tools.&lt;/p&gt;
&lt;p&gt;One of the best applications that I use today is emacs org-mode. My academic
life probably revolves around this text swiss-army knife. The ability to
organize information in its outline system is incredibly powerful and yet so
simple - its just a bunch of nested collapsible notes in a single text file. But
because its just plain text, a file containing notes for years has not yet even
exceeded an MB. (also version controlled by Git to track changes). It hardly
consumes any RAM (I just checked for my current emacs instance with multiple
org-mode buffers: 120MB). From this one lean application I am able to: write
notes, organize information, write reports, write latex papers, make
presentations (latex beamer), write and export my Hugo blog. It basically became
my one-stop shop for information management. Oh, and it also has todo and agenda
planning functionality. But Richard, emacs sounds like the opposite of a simple
tool! But you know what emacs did? It single-handedly obsoleted the following
programs in my life: onenote, google docs, office-suite software, latex editor,
blog-maker software, and an event-planner software. A common text-driven
interface that has millisecond latency, will never change for decades, but with
enough power to do the job of all the software I just mentioned is nothing short
of a miracle. And because of the Lindy effect &lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;, which states that the longer
something exists, the longer its expected to last. I am reasonably sure that
emacs will stand the corruption of time, and with it, my workflow is secure and
unlikely to suffer major changes in the future.&lt;/p&gt;
&lt;p&gt;The experience of software is determined largely by the workflows that we set up
with the tools that we use. The tools we become dependent on grants the creators
of those tools power over us. If we use poorly-designed software with abusive
creator-user relationships, our experience will probably suck a lot. Being
careful with the tools that I choose means that I can establish workflows with
software that respects my experience. And everytime I use my machine (which by
now is around 6 years since its manufacture date), I always find it fast and
pleasant to use.&lt;/p&gt;
&lt;p&gt;Let me add one more twist: web browsers are a necessary evil. Browsers are
probably more complicated than OSes at this point but you cannot live in the
modern era without interacting with the modern web. My rule for applications on
the web is this: stick to the web for reading and multimedia consumption, but
anything that requires its own application should have its own application. Take
for example google docs. I really respect the use of google docs for its
collaborative feature, but using it as an information management system is a
disaster. If something exists as a web-application, there probably exists
something better natively. The good news is that using Firefox on Linux on my
half-decade old machine is still a relatively snappy experience (considering
that I only mainly use a browser to read and only read). Somehow despite the
sheer complexity of the browser, it still manages to remain performant and
efficient at times. As of now Firefox is the most performant+functional browser
on wayland Linux. But if I had a simpler tool to do the same thing I would most
definitely switch.&lt;/p&gt;
&lt;p&gt;I find it amazing that people can sometimes write software that reminds you that
the computer that you thought was slow is actually surprisingly fast. These
people did their homework and made software that somehow managed to squeeze out
every last bit of performance available from the silicon. The elegant design of
a simple program coupled with a deep understanding of the tech stack can yield
programs that are truly timeless. It is this art form that continues to drive me
to study more about computers and to one day be able to write software that show
us that computers are indeed fast and useful, and that they can be much faster
and way more useful than we think.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://blog.kowalczyk.info/article/2f72237a4230410a888acbfce3dc0864/lessons-learned-from-15-years-of-sumatrapdf-an-open-source-windows-app.html&#34;&gt;https://blog.kowalczyk.info/article/2f72237a4230410a888acbfce3dc0864/lessons-learned-from-15-years-of-sumatrapdf-an-open-source-windows-app.html&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Lindy_effect&#34;&gt;https://en.wikipedia.org/wiki/Lindy_effect&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>A first foray into IPv6</title>
      <link>https://richardwong.io/post/linux/2024-02-04-sun-a-first-foray-into-ipv6/</link>
      <pubDate>Sun, 04 Feb 2024 22:25:00 +0800</pubDate>
      
      <guid>https://richardwong.io/post/linux/2024-02-04-sun-a-first-foray-into-ipv6/</guid>
      <description>&lt;p&gt;About a week or two ago, I tried to connect my Thinkpad to my iPhone&amp;rsquo;s
hotspot. It was right after a recent iOS update (17.3). It was a very odd moment
as my Firefox could not load anything. My first instinct was to perform &lt;code&gt;ip a&lt;/code&gt;,
which would show if my wlan0 connection interface is connected. And it was. My
next thought was maybe it was one of those odd Linux moments where you have WiFi
but no internet because DHCP somehow failed. So I tried to set a static IP via a
systemd-networkd configuration. And it still didn&amp;rsquo;t work. Furthermore, this
whole time &lt;code&gt;ping 1.1.1.1&lt;/code&gt; did not work. It was more frustrating that the message
was &amp;ldquo;ping: connect: Network is unreachable&amp;rdquo;. It was frustrating since it was
clearly connected.&lt;/p&gt;
&lt;p&gt;One afternoon, I took a bit of time to investigate the issue. Again, I tried
looking at &lt;code&gt;ip a&lt;/code&gt; and interestingly, there was no &amp;ldquo;inet&amp;rdquo; field and there was only
an &amp;ldquo;inet6&amp;rdquo; field. I had a suspicion that perhaps DHCP worked for IPv6 but not
for IPv4. So I performed &lt;code&gt;ping ipv6.google.com&lt;/code&gt; and it worked!&lt;/p&gt;
&lt;p&gt;While having an IPv6-only connection, the internet is a trippy experience. As of
2024 February, the global adoption rate for IPv6 is around 41%. (&lt;a href=&#34;https://www.google.com/intl/en/ipv6/statistics.html&#34;&gt;according to
Google&lt;/a&gt;) That means that
more than half the web doesn&amp;rsquo;t work. My Firefox couldn&amp;rsquo;t load &amp;ldquo;anything&amp;rdquo;
initially because my main search engine, Duckduckgo, is IPv4-only. Using Google
worked. Hackernews worked. Wikipedia worked. richardwong.io didn&amp;rsquo;t work. Of
course it didn&amp;rsquo;t work, I didn&amp;rsquo;t add AAAA records to the IPv6 address of my
server. At that point I realized that I was part of the 59% that contributed to
the IPv6 adoption problem. And so I became a compliant citizen of the world and
added IPv6 records for richardwong.io. richardwong.io is dual-stack (IPv4 and
IPv6) networked from now on.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;But coming back to my broken hotspot, how am I to restore my connection to the
remaining 59% of the world&amp;rsquo;s websites that are still using IPv4? In other words,
how can I access IPv4 websites from an IPv6-only connection? A complicated way
to go about it is via DNS64/NAT64. This is a process where IPv6-only hosts can
talk to IPv4-hosts via an intermediate translation mechanism where all IPv4
A-records can be converted into IPv6 AAAA-records that my IPv6-only machine can
understand.  It is complicated because the kernel does not support NAT64
natively and so additional tools and kernel modules are required. Considering
that I am mainly using WiFi connections from fixed residential/school routers, I
will still be using mainly IPv4. This is not the way.&lt;/p&gt;
&lt;p&gt;A much simpler method would simply to use richardwong.io as a proxy. By using
&lt;code&gt;ssh -D &amp;lt;port&amp;gt; &amp;lt;proxy&amp;gt;&lt;/code&gt;, I am able to proxy via a IPv6-enabled public server using
SOCKS. All connections through the proxy are possible through the IPv4 and IPv6
connections of the server, not my client. In effect, I am browsing through my
server and using its IPv4 connection instead. And so I was able to workaround
the limitations that the bug has given me, and finally got around to enabling
IPv6 for my website and reading more on it (Just the fact that there are
hexadecimals in the IPv6 string scared me for a really long time, but I guess it
beats writing 128 0s and 1s&amp;hellip;).&lt;/p&gt;
&lt;p&gt;Now for some thoughts. It is horrifying that something as important as IPv6 is
not backward compatible with IPv4. I guess the lack of compatibility is causing
all the issues with IPv6 adoption. And that really sucks, because IPv6 can
enable all machines to be publically and uniquely addressable (IPv6 can hold
hundreds of times more addresses than atoms on Earth). Because of the limited
number of IPv4 addresses, most ISPs utilize a double-NAT where each IPv4 address
would have an internal network shared by the whole neighborhood. Home routers
would therefore have a private IP not reachable from the public internet. This
increases the utilization of each public IPv4 address and therefore reduces the
need for more addresses. But double-NAT is a terrible technology that feeds into
the consumption aspect of the internet and dissuades the aspect on sharing and
creation. You can ask from others but others can&amp;rsquo;t ask from you. I believe this
is one of the reasons why most people don&amp;rsquo;t make their own websites, because
they can&amp;rsquo;t just host stuff on their home machines. Instead you have to use a
publicly-addressable server from a company with a large pool of
IPv4/IPv6. I mean, who would want to rent a VPS box and configure their own
reverse-proxy to link their home machines to speak to the internet to host a
bunch of files (I will write a blog post on this in the future).&lt;/p&gt;
&lt;p&gt;IPv6 adoption is necessary for a more grassroots-based internet, where services
and websites are hosted on small, independent machines rather than on one of the
big, commercial cloud server offerings. As of right now, most ISPs are not
offering static IPv6 for homes.&lt;/p&gt;
&lt;p&gt;I think I still need to readup more on IPv6. A good resource would be to look at
the &lt;a href=&#34;https://tldp.org/HOWTO/Linux+IPv6-HOWTO/index.html&#34;&gt;tldp Linux IPv6 how-to
guide&lt;/a&gt;. Considering how VPS
services and Amazon AWS now charges more for IPv4 instances, it would be wise to
know how to setup a IPv4-compatible IPv6-only server.&lt;/p&gt;
&lt;h2 id=&#34;update&#34;&gt;Update: &lt;span class=&#34;timestamp-wrapper&#34;&gt;&lt;span class=&#34;timestamp&#34;&gt;[2024-04-21 Sun]&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;It is possible to access IPv4 via an IPv6-only network on linux. Just add the
following DNS64 addresses from cloudflare to your systemd-resolved config:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-text&#34;&gt;2606:4700:4700::64
2606:4700:4700::6400
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Somehow systemd-resolved is able to start resolving IPv4 addresses despite not
having set-up a NAT64 on the network.&lt;/p&gt;
&lt;p&gt;When I am using my IPv6 machine to get an IPv4 request via the DNS64 server, it
will get a AAAA resource record (RR) from the DNS64 server. Its just like any
other AAAA RR, like an IPv6 address. Then my machine sends an IPv6 packet with
the destination address being the synthesized AAAA record starting with the
standard DNS64 prefix &amp;ldquo;64:ff9b::&amp;rdquo; to the wild. By using a &lt;code&gt;traceroute&lt;/code&gt;, I was able
to find that somewhere along the way servers receiving my packet transitions
from &amp;ldquo;2001:..&amp;rdquo; (an IPv6 server) to &amp;ldquo;64:ff9b:..&amp;rdquo; (an IPv4 address translated back
into IPv6), suggesting that the packet was translated somewhere along the
way. It would appear that the network itself already had NAT64 services provided
by someone. By referencing this
&lt;a href=&#34;https://blog.apnic.net/2019/06/03/ipv6-deployment-and-challenges-at-sk-telecom/&#34;&gt;article&lt;/a&gt;&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;,
it would seem that Korean ISPs do indeed provide NAT64 as a provider-side
translator (PLAT) service. Since the NAT64 translation is already provided by
the network, the IPv4 destination server response will likewise be translated
back to IPv6 packets and back to me, which my IPv6-only machine can read.&lt;/p&gt;
&lt;p&gt;So this ties up the mystery of why a simple addition of DNS64 in system-resolved
config suddenly allowed IPv4 access from my IPv6 machine.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;See &lt;a href=&#34;https://www.google.com/intl/en/ipv6/statistics.html&#34;&gt;https://www.google.com/intl/en/ipv6/statistics.html&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://blog.apnic.net/2019/06/03/ipv6-deployment-and-challenges-at-sk-telecom/&#34;&gt;https://blog.apnic.net/2019/06/03/ipv6-deployment-and-challenges-at-sk-telecom/&lt;/a&gt;&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Using VS Code for Python Development</title>
      <link>https://richardwong.io/post/tools/2023-09-07-thu-using-vs-code-for-remote-coding/</link>
      <pubDate>Fri, 15 Sep 2023 23:51:00 +0900</pubDate>
      
      <guid>https://richardwong.io/post/tools/2023-09-07-thu-using-vs-code-for-remote-coding/</guid>
      <description>&lt;h2 id=&#34;jupyterlab-was-my-best-friend&#34;&gt;Jupyterlab was my best friend&lt;/h2&gt;
&lt;p&gt;For a very long time, I have used Jupyter notebooks via Jupyterlab to code in
Python. I was taught to use it in my undergrad and found it to be enough for my
needs. I really liked the tight feedback loop of the development process that
allows me to see what my code is doing immediately without needing to re-run the
entire thing.&lt;/p&gt;
&lt;p&gt;But the one thing that really, really grinds my gears is the fact that I was
coding the whole time without vim. Using the default Jupyter keymap is fine when
I just started to learn programming, but needing to go to my trackpad to
navigate within a Jupyter code cell today feels like a big step backward.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;But Richard, we have Jupyter extensions that can enable vim in Jupyterlab.&amp;rdquo; And
yes, the &lt;a href=&#34;https://github.com/jupyterlab-contrib/jupyterlab-vim&#34;&gt;jupyterlab-vim&lt;/a&gt;
extension exists to bring vim functionality to Jupyter cells. It worked for a
time and I was somewhat happy with it. A little odd thing was that the &amp;lt;Esc&amp;gt; key
to quit Editing mode to return to Vim&amp;rsquo;s Normal mode conflicted with the main
Jupyter &amp;lt;Esc&amp;gt; key to return to Jupyter&amp;rsquo;s Navigation mode, so you had to re-bind
the key to &amp;lt;Ctrl&amp;gt;-&amp;lt;Esc&amp;gt; (if I remember it correctly). The whole thing worked for
a time, until one day I updated it and there was no vim. I was back to editing
code like a caveman.&lt;/p&gt;
&lt;p&gt;Apparantly when my Jupyterlab got updated to version 4.0, the extensions needed
time to get updated too. Though its working now for version 4.0, I can&amp;rsquo;t help
but feel that the Jupyter ecosystem has over-extended itself to become an IDE in
the browser. Trying to fix things in Jupyterlab has also been an exercise in
frustration (e.g. theming Jupyterlab beyond light or dark mode, setting fonts
for code-cells and making sure the changes persist). It just felt like the thing
was becoming a mess and some day my environment would just fail on me when I
need it most.&lt;/p&gt;
&lt;p&gt;But I still like the notebook workflow. I don&amp;rsquo;t think I can move to developing
in &lt;code&gt;.py&lt;/code&gt; files again anytime soon. So instead of trying to make Jupyter become an
IDE, why not use Jupyter in an IDE?&lt;/p&gt;
&lt;h2 id=&#34;using-vs-code-with-local-conda-environments&#34;&gt;Using VS code with local conda environments&lt;/h2&gt;
&lt;p&gt;VS code has the ability to open &lt;code&gt;.ipynb&lt;/code&gt; files. Upon opening a file, everything
feels right at home. Some of the main navigation keys and shortcuts still work:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;J/K to navigate cells&lt;/li&gt;
&lt;li&gt;gg to go to top-most cell&lt;/li&gt;
&lt;li&gt;G to go to bottom-most cell&lt;/li&gt;
&lt;li&gt;Escape to go back to navigation mode&lt;/li&gt;
&lt;li&gt;A to insert new code cell above current cell&lt;/li&gt;
&lt;li&gt;B to insert new code cell below current cell&lt;/li&gt;
&lt;li&gt;C to copy current cell&lt;/li&gt;
&lt;li&gt;V to paste current cell&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But what about Vim? I installed the vim extension in vscode and I was good to
go. It just works.&lt;/p&gt;
&lt;p&gt;But the power feature that changed everything was the fact that VS code knows
how to start an IPython kernel without needing a Jupyter server. What??? Usually
my workflow would go like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;open a terminal&lt;/li&gt;
&lt;li&gt;&lt;code&gt;conda activate &amp;lt;env&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;jupyter lab&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;open browser at localhost:8080&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But somehow VS code, with the Jupyter extension, could run a kernel without
needing a Jupyter server to run. All you have to do is &amp;lt;Ctrl&amp;gt;+&amp;lt;Shift&amp;gt;+P, then
select &amp;ldquo;Python: Select Interpreter&amp;rdquo; and give it the path to the &lt;code&gt;python&lt;/code&gt; binary in
the conda environment binaries folder, and you can start running your code! VS
code can even start a kernel the next time you resume by remembering where your
conda environment is, so all you have to do is start VS code and you can start
coding.&lt;/p&gt;
&lt;h2 id=&#34;remote-machine-jupyter-notebook&#34;&gt;Remote machine Jupyter notebook&lt;/h2&gt;
&lt;p&gt;Another killer feature of VS code is the ability to connect to a remote machine
via SSH and run a VS code server on the remote server. Let me illustrate why.&lt;/p&gt;
&lt;p&gt;I always have my Thinkpad with me and editing code on it is a really enjoyable
experience, but it has a 5 year old 4-core processor without any significant GPU
compute. I don&amp;rsquo;t have enough computing power to run expensive data processing
applications. But I do have a server with an Nvidia GPU in my lab. Usually that
would mean that I must go to the lab in order to use the more powerful
machine. But if I could SSH to my lab machine, I could develop on the lab
machine through my notebook regardless of where I am.&lt;/p&gt;
&lt;p&gt;By remoting to my machine via SSH using VS code, I could access the files on my
remote machine through the ease and comfort of my local machine&amp;rsquo;s VS
code. Furthermore, I can utilize the conda environment on the remote machine,
giving me access to CUDA facilities in my PyTorch code. Though I cannot be in
the lab all the time, it is very useful to be able to run notebooks on my remote
machine at anytime I want.&lt;/p&gt;
&lt;p&gt;But a tricky problem is how you can SSH to a machine that does not have a
dedicated public IP.&lt;/p&gt;
&lt;p&gt;One method is to use a service that exposes your machine on
a public IP like ngrok.&lt;/p&gt;
&lt;p&gt;Another method is much more involved, but you can avoid the use of a third party
service for better privacy and security. First, perform reverse SSH
port-forwarding to a remote virtual private server that you own with a public
IP. Note that because your connection can die due to inactivity, the use of
autossh is advised.&lt;/p&gt;
&lt;p&gt;On the remote server:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;ssh -fN -R 5000:127.0.0.1:22 &amp;lt;public-ip server&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, port forward that same port to your machine via port forwarding the remote
port to your client machine local port.&lt;/p&gt;
&lt;p&gt;On your client machine:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;ssh -L 5000:127.0.0.1:5000 &amp;lt;public-ip server&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then SSH localhost at the local port and you then have an SSH connection to the
remote server.&lt;/p&gt;
&lt;p&gt;On your client machine:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;ssh 127.0.0.1 -p 5000
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&#34;persistent-vs-code-remote-notebook&#34;&gt;Persistent VS code remote notebook&lt;/h2&gt;
&lt;p&gt;One issue that I found with the setup in the previous section was that when my
SSH disconnects, the kernel is closed. A common workflow that I need is to open
a remote notebook, start a training cycle, and then close my notebook and go on
with my life. But this is not possible with a remote kernel.&lt;/p&gt;
&lt;p&gt;Unfortunately, this means that I cannot use the IPython kernel provided by VS
code, but I need to run a Jupyter server on the remote machine in order for the
kernel to survive when the SSH connection is closed. This means that even when I
close my client machine and the SSH connection is closed, the kernel can keep
running on the remote machine and my training cycle will not be interrupted.&lt;/p&gt;
&lt;p&gt;The first way to go about it is to run a Jupyter server on the remote
machine. First, SSH to the remote machine, then run: &lt;code&gt;jupyter server &amp;amp;&lt;/code&gt; in order
to make it run in the background. Then remote to the same machine in VS code via
SSH and connect to the kernel of the Jupyter server.&lt;/p&gt;
&lt;p&gt;The first method is good enough for the purpose of getting a persistent
notebook. But I wanted a less hacky solution and not have to use 2 SSH
connections.&lt;/p&gt;
&lt;p&gt;The second method is to setup a persistent terminal in the VS code remote
session.&lt;/p&gt;
&lt;p&gt;First, install &lt;code&gt;tmux&lt;/code&gt; on the remote server.&lt;/p&gt;
&lt;p&gt;Then on your client machine, add these to your &lt;code&gt;settings.json&lt;/code&gt; of your VS code.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-json&#34;&gt;&amp;quot;terminal.integrated.profiles.linux&amp;quot;: {
	&amp;quot;tmux&amp;quot;: {
		&amp;quot;path&amp;quot;: &amp;quot;/usr/bin/tmux&amp;quot;,
		&amp;quot;args&amp;quot;: [
			&amp;quot;new-session&amp;quot;,
			&amp;quot;-A&amp;quot;,
			&amp;quot;-s&amp;quot;,
			&amp;quot;main&amp;quot;
		],
	},
},
&amp;quot;terminal.integrated.defaultProfile.linux&amp;quot;: &amp;quot;tmux&amp;quot;,
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These settings allow your terminal in VS code to start with tmux enabled. This
has the benefit of allowing you to resume a previous tmux session. By running
jupyter server in the tmux session, the jupyter server will be attached to the
tmux session. Since disconnecting from an SSH will only detach the tmux session,
the tmux session will persist and all processes within the tmux session will
also persist. When you disconnect from the remote SSH session in VS code, and
then reconnect later on, your terminal session will be restored by attaching to
the same tmux session. And since the jupyter server is still alive, your
notebook should just resume from where you left off.&lt;/p&gt;
&lt;p&gt;That means after you &amp;lt;Ctrl&amp;gt;+&amp;lt;Enter&amp;gt; for your model training cell in your
notebook, you can just set your machine to sleep. And after a while you can open
your machine, and VS code will prompt you to reconnect (If you use my
port-forward solution for SSH, you might need to port-forward the public IP port
to your client machine again). Reconnect and you will be right where you left
off, where your model has finished training and you can evaluate the results of
the training session.&lt;/p&gt;
&lt;p&gt;To avoid needing to re-establish the port-forward connection from the public
server to your client, set the following in your VS code &lt;code&gt;settings.json&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-json&#34;&gt;&amp;quot;remote.SSH.defaultForwardedPorts&amp;quot;: [
    {
        &amp;quot;localPort&amp;quot;: 5000,
        &amp;quot;remotePort&amp;quot;: 5000,
        &amp;quot;name&amp;quot;: &amp;quot;your public server ip&amp;quot;
    }
]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With this, your VS code remote session will resume without any additional
steps.&lt;/p&gt;
&lt;h2 id=&#34;references&#34;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://code.visualstudio.com/docs/datascience/jupyter-notebooks&#34;&gt;VS code Jupyter Notebooks Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.zdyn.net/system/hacks/2020/09/19/vscode-term-session.html&#34;&gt;Persistent Terminal in VS code Remote Session&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>Orthogonal Graphs Part 1: Modeling the problem of drawing orthogonal graphs</title>
      <link>https://richardwong.io/post/research/2023-08-18-fri-how-to-draw-orthogonal-graphs/</link>
      <pubDate>Mon, 28 Aug 2023 22:42:00 +0800</pubDate>
      
      <guid>https://richardwong.io/post/research/2023-08-18-fri-how-to-draw-orthogonal-graphs/</guid>
      <description>&lt;h2 id=&#34;backstory-behind-the-dive-into-the-rabbit-hole&#34;&gt;Backstory behind the dive into the rabbit-hole&lt;/h2&gt;
&lt;p&gt;About a few months ago I was introduced to the problem of drawing
&amp;ldquo;aesthetically-pleasing graphs where edges have 90 degree bends.&amp;rdquo; I was
incredibly frustrated then as I had to deliver a code that will take in an excel
file and export a nice looking graph, and the only clue I had was the
aforementioned request with no data or examples. I had to start with no training
or background in this area. I would try to search for clues and was frequently
left with no leads. I would spend nearly a month trying to formulate the problem
from scratch, not realizing that the problem was way more complex than I
thought. Each educational resource would be built on the foundation of many more
papers and texts, and those too would reference yet more ideas and concepts. Not
wanting to let those months go to waste, I thought I would start writing on some
of these things.&lt;/p&gt;
&lt;h2 id=&#34;what-are-orthogonal-graphs&#34;&gt;What are Orthogonal Graphs?&lt;/h2&gt;
&lt;p&gt;An orthogonal drawing of a graph is a graph representation such that its edges
are composed of lines parallel to the vertical or horizontal axis, and in each
edge (which could be composed of many of such lines) the lines are connected via
90-degree bends.&lt;/p&gt;
&lt;p&gt;Below is an example of an orthogonal graph:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://richardwong.io/post/research/2023-08-18-fri-how-to-draw-orthogonal-graphs/output_graphn10e20s150i0.svg&#34;&gt;
&lt;/figure&gt;

&lt;p&gt;Its quite a nice looking graph isn&amp;rsquo;t it? Its not immediately obvious why the
above graph would look good. What would a bad graph look like? Perhaps the lines
would cross very often, making it difficult to trace an edge. Or perhaps a bad
graph would have nodes and/or edges that are bunched up together, making it hard
to distinguish nodes and edges. From these simple observations, we know that
aesthethic looking graphs must have the components evenly-laid out, and also
have the lines not cross.&lt;/p&gt;
&lt;p&gt;If you sat down to try to draw the above graph from scratch using the prior
observations, you would soon face a whole slew of conundrums:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Let&amp;rsquo;s suppose that you want to place a node on the surface. Which node do you
start with? How would you place the nodes such that you can route the edges
well?&lt;/li&gt;
&lt;li&gt;If placing the nodes need you to route the edges well, but you can&amp;rsquo;t route the
edges without some nodes on the screen, how can you even go about it?&lt;/li&gt;
&lt;li&gt;Perhaps we can randomly place the nodes on the surface and iteratively re-draw
the edges and then adjust the nodes accordingly&lt;/li&gt;
&lt;li&gt;Then moving one node would affect how to draw its edge, which would affect the
edges drawn near to those edges, which affect the nodes attached to all these
edges, which affects&amp;hellip;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You see? The problem is tough to model because every component is dependent on
each other. You cannot solve this problem with a local heuristic.&lt;/p&gt;
&lt;h2 id=&#34;an-other-worldy-solution&#34;&gt;An Other-worldy Solution&lt;/h2&gt;
&lt;p&gt;Instead of attacking the problem in a naive way like before, Roberto Tamassia,
an influential figure world of graph drawing, laid out an approach in 1987
called the Topology-Shape-Metrics approach. The three properties are defined to
be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Topology: the sequence of edges along the faces of the drawing (faces are
formed when a set of edges results in an enclosed region of the graph) that
does not change even if we change the shape of edges (aka introduce bends)&lt;/li&gt;
&lt;li&gt;Shape: A shape of the drawing is derived from the topology and the only thing
that is allowed to change is the length of each edge&lt;/li&gt;
&lt;li&gt;Metrics: 2 drawings share the same metrics if they are congruent (we can flip,
rotate, shift the drawings such that they overlay on top of each other)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;At first glance it doesn&amp;rsquo;t seem clear how these properties can help us. If we
look closely, it breaks down the required properties of a graph into incremental
properties, each building from the previous property. The topology of a graph,
though an abstract concept, tries to find what is similar between 2 drawings of
a graph at the most fundamental level. Without considering additional
properties, it is easier to find a graph that shares the same foundational
topology with the optimal orthogonal drawing rather than immediately jumping to
finding the exact metrics of the optimal orthogonal drawing itself (which was
what we tried to do from scratch earlier).&lt;/p&gt;
&lt;p&gt;How then can we find the topology of a graph? The graph embedding becomes the
next most important concept. A graph embedding is defined to be the circular
order of adjacent edges around each node of the graph. Because the embedding is
deeply tied to the topology, we can try to find the embedding of the graph (aka
the order of the graph) in order to find the optimal topology of the graph. By
choosing a good embedding, it gives us the direction to draw a good orthogonal
graph. But how can we find a good embedding? A 3 step algorithm is used to
progressively bring us from the topology to the metrics of a good orthogonal
drawing.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Planarization: the graph is made into a planar graph by introducing a dummy
node for each edge crossing. The attempt to planarize a graph gives an
embedding that minimizes edge crossings. But any planar embeddings by
themselves are insufficient as we can still organize the faces such that the
final planar embedding can have maximum-outer face and minimum-depth. This
almost gives us the optimal topology of the graph.&lt;/li&gt;
&lt;li&gt;Orthogonalization: attempt bend minimization by re-formulating the problem as
a network-flow problem. This gives us only how many bends there are on each
edge, but not where to place those bends.&lt;/li&gt;
&lt;li&gt;Compaction: find where to place the bends by minimizing the length of each
line in an edge. This is also another network-flow problem. Finally, the dummy
nodes are removed.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Though we do not yet have the coordinates needed to draw the orthogonal drawing,
we know where each node is supposed to be placed relative to another node (by
the circular order), and we know how many bends there are on each edge, and how
long each line has to be between a node and a bend (and also between
bends). There is now enough information to draw an orthogonal graph
drawing.&lt;/p&gt;
&lt;p&gt;Notice how the process is still covered with very broad-strokes. We did not go
into detail on how planarization, orthogonalization or compaction could be
done. Each of these steps require complex algorithms to solve their specific
problems. Without setting some hard restrictions, we would be left with solving
a few NP-hard problems just to produce a good-looking orthogonal graph! But
alas, I have reached the end of this article. Next time, I will show you how we
can produce orthogonal graphs with some code!&lt;/p&gt;
&lt;h2 id=&#34;references&#34;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://rtsys.informatik.uni-kiel.de/~biblio/downloads/theses/pkl-mt.pdf&#34;&gt;Klose, P. (2012). A generic framework for the topology-shapemetrics based layout. Christian-Albrechts-Universität zu Kiel.&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>Python and Anki</title>
      <link>https://richardwong.io/post/learning/2023-02-18-sat-python-and-anki/</link>
      <pubDate>Sun, 19 Feb 2023 00:56:00 +0900</pubDate>
      
      <guid>https://richardwong.io/post/learning/2023-02-18-sat-python-and-anki/</guid>
      <description>&lt;h2 id=&#34;why-use-anki&#34;&gt;Why use Anki?&lt;/h2&gt;
&lt;p&gt;I have been learning Korean thus far and the number of words has been quite
overwhelming. I had someone recommend the use of the spaced-repetition software
Anki for the very purpose of memorizing vocabulary. Though I was hesitant (Its
not that I doubted its use. As a matter of fact, I have used Anki in the past to
successfully memorize words in another language. Its just that setting it up was
such a PITA that I kinda put it off for a while), I was at a point that if I do
not become more efficient, I will not even have the time to completely review
what I have memorized. The premise is this: reviewing every single word is
wasting my time. I need only to review the words that I struggle with.&lt;/p&gt;
&lt;p&gt;Hence I decided to set about creating my Anki decks based on the words that I
needed to study for this language semester (I was enrolled in the Hanyang
University Language Program, perhaps I can write about it some day?). How could
I make Anki decks without sinking obscene amounts of time? I found that I could
use Python and a library called
&lt;a href=&#34;https://github.com/kerrickstaley/genanki&#34;&gt;Genanki&lt;/a&gt; to generate Anki decks. The
fortunate thing was I also found an amazing &lt;a href=&#34;https://charly-lersteau.com/posts/2019-11-17-create-anki-deck-csv/&#34;&gt;blog
post&lt;/a&gt; on how
to use this library.&lt;/p&gt;
&lt;h2 id=&#34;using-genanki&#34;&gt;Using Genanki&lt;/h2&gt;
&lt;p&gt;Firstly, I would create a TSV file of the words from a chapter of my Korean
vocabulary book. It looks something like this:&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;hangul&lt;/th&gt;
          &lt;th&gt;meaning&lt;/th&gt;
          &lt;th&gt;type&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;영화배우&lt;/td&gt;
          &lt;td&gt;actor/actress&lt;/td&gt;
          &lt;td&gt;noun&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;계란&lt;/td&gt;
          &lt;td&gt;egg&lt;/td&gt;
          &lt;td&gt;noun&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;야채&lt;/td&gt;
          &lt;td&gt;vegetable&lt;/td&gt;
          &lt;td&gt;noun&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;일찍&lt;/td&gt;
          &lt;td&gt;early&lt;/td&gt;
          &lt;td&gt;adverb&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;I know that I still needed to type out the words, but keying these information
in emacs is a lot faster than keying the same information in Anki itself. And
also, I inputted everything into emacs way before doing this because I wanted to
produce an electronic copy that I can review on the go. So it was incredibly
helpful to just export these emacs tables to TSV and start from there.&lt;/p&gt;
&lt;p&gt;For the code below, it is recommended that a Jupyter notebook be used to follow
along.&lt;/p&gt;
&lt;p&gt;We will first import the relevant libraries.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;import csv
import random
import genanki
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We then need to generate a 10-digit &lt;code&gt;model_id&lt;/code&gt; that will help Anki identify this
specific &amp;ldquo;Note Type&amp;rdquo;. All decks that you generate that share the same format
must use the same &lt;code&gt;model_id&lt;/code&gt; to be classified under the same &amp;ldquo;Note Type&amp;rdquo;. You can
find the &amp;ldquo;Note Type&amp;rdquo; when you open the &amp;ldquo;Browse&amp;rdquo; section of Anki. Not having the
same &lt;code&gt;model_id&lt;/code&gt; for decks of the same type will cause the creation of duplicate
Note Types that differ by a &amp;ldquo;+&amp;rdquo; symbol.&lt;/p&gt;
&lt;p&gt;Generate the &lt;code&gt;model_id&lt;/code&gt; for the first time that you run this, then comment that
line and keep using the same &lt;code&gt;model_id&lt;/code&gt; for subsequent deck generations.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;# generate once and use the hardcoded values
model_id = random.randrange(1 &amp;lt;&amp;lt; 30, 1 &amp;lt;&amp;lt; 31)
# model_id = &amp;lt;replace this with the new model_id digits&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then give names for the following variables:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;# Filename of the data file
data_filename = &amp;lt;name&amp;gt;

# Filename of the Anki deck to generate
deck_filename = &amp;lt;name&amp;gt;

# Title of the deck as shown in Anki
anki_deck_title = &amp;lt;name&amp;gt;

# Name of the card model
anki_model_name = &amp;lt;name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As for me, I like to use Python f-strings, which can replace the variable
bounded in &lt;code&gt;{}&lt;/code&gt; in the f-string with the value of the variable. In the following
example, I only have to define the &lt;code&gt;chapter_num&lt;/code&gt; and all the names will be
replaced. Ain&amp;rsquo;t that neat?&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;# chapter num
chapter_num = 9

# Filename of the data file
data_filename = f&amp;quot;chapter{chapter_num}&amp;quot;

# Filename of the Anki deck to generate
deck_filename = f&amp;quot;Level2_{data_filename}.apkg&amp;quot;

# Title of the deck as shown in Anki
anki_deck_title = &amp;quot;Hanyang Level 2 &amp;quot; + data_filename

# Name of the card model
anki_model_name = f&amp;quot;Hanyang_Korean&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The next part helps us to create the structure of the Anki cards&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;# Create the deck model

style = &amp;quot;&amp;quot;&amp;quot;
.card {
 font-family: arial;
 font-size: 24px;
 text-align: center;
 color: black;
 background-color: white;
}
&amp;quot;&amp;quot;&amp;quot;

anki_model = genanki.Model(
    model_id,
    anki_model_name,
    fields=[{&amp;quot;name&amp;quot;: &amp;quot;hangul&amp;quot;}, {&amp;quot;name&amp;quot;: &amp;quot;meaning&amp;quot;}, {&amp;quot;name&amp;quot;: &amp;quot;type&amp;quot;}],
    templates=[
        {
            &amp;quot;name&amp;quot;: &amp;quot;Card 1&amp;quot;,
            &amp;quot;qfmt&amp;quot;: &#39;&amp;lt;p class=&amp;quot;meaning&amp;quot;&amp;gt;{{meaning}}&amp;lt;/p&amp;gt;&#39;,
            &amp;quot;afmt&amp;quot;: &#39;{{FrontSide}}&amp;lt;hr id=&amp;quot;answer&amp;quot;&amp;gt;&amp;lt;p class=&amp;quot;hangul&amp;quot;&amp;gt;{{hangul}}&amp;lt;/p&amp;gt;&amp;lt;p class=&amp;quot;type&amp;quot;&amp;gt;{{type}}&amp;lt;/p&amp;gt;&#39;,
        },
        {
            &amp;quot;name&amp;quot;: &amp;quot;Card 2&amp;quot;,
            &amp;quot;qfmt&amp;quot;: &#39;&amp;lt;p class=&amp;quot;hangul&amp;quot;&amp;gt;{{hangul}}&amp;lt;/p&amp;gt;&#39;,
            &amp;quot;afmt&amp;quot;: &#39;{{FrontSide}}&amp;lt;hr id=&amp;quot;answer&amp;quot;&amp;gt;&amp;lt;p class=&amp;quot;meaning&amp;quot;&amp;gt;{{meaning}}&amp;lt;/p&amp;gt;&amp;lt;p class=&amp;quot;type&amp;quot;&amp;gt;{{type}}&amp;lt;/p&amp;gt;&#39;,
        },
    ],
    css=style,
)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can just re-use the &lt;code&gt;style&lt;/code&gt;. Remember that the fields that I have in my TSV
file are these (in-order): [ hangul, meaning, type ]. I would think that &lt;code&gt;qfmt&lt;/code&gt; is
&amp;ldquo;question-format&amp;rdquo; and &lt;code&gt;afmt&lt;/code&gt; is &amp;ldquo;answer-format&amp;rdquo;. These use HTML to specify the
template of the question and answer sides of the card. Just replace the variable
in the braces with the variables in the fields to display the value from the
fields.&lt;/p&gt;
&lt;p&gt;Here, I have 2 types of cards. &lt;code&gt;Card 1&lt;/code&gt; would prompt with the meaning of the word,
and I will need to be able to remember how to write the hangul of the word. &lt;code&gt;Card 2&lt;/code&gt; is the opposite; it would prompt with the hangul word, and I will need to
recall the meaning. The reason for this is that I realized that my memory is not
always bi-directional. I might remember how to write a word when given its
meaning, but somehow when being shown the actual word in hangul form, I might
forget what it means. &lt;code&gt;Card 2&lt;/code&gt; prevents this scenario by ensuring that my memory
would work in both directions. This has a downside of doubling my deck size :(&lt;/p&gt;
&lt;p&gt;The next step has us trying to populate the list &lt;code&gt;anki_notes&lt;/code&gt; with &lt;code&gt;anki_note&lt;/code&gt;
objects with fields populated from the TSV file. I use a &amp;ldquo;\t&amp;rdquo; delimiter because
I use a &lt;strong&gt;tab&lt;/strong&gt; delimited file. If you use a CSV, it would be a &amp;ldquo;,&amp;rdquo; delimiter.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;# The list of flashcards
anki_notes = []

with open(data_filename, &amp;quot;r&amp;quot;) as csv_file:

    csv_reader = csv.reader(csv_file, delimiter=&amp;quot;\t&amp;quot;)

    for row in csv_reader:
        anki_note = genanki.Note(
            model=anki_model,
            # hangul, meaning, type
            fields=[row[0], row[1], row[2]],
        )
        anki_notes.append(anki_note)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Shuffling the cards would help with not having similar cards being too close to
each other.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;# Shuffle flashcards
random.shuffle(anki_notes)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We will now create the deck and populate it with the &lt;code&gt;anki_note&lt;/code&gt; objects that we
placed in &lt;code&gt;anki_notes&lt;/code&gt; (the naming convention is not the best).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;# create anki deck
anki_deck = genanki.Deck(model_id, anki_deck_title)

# Add flashcards to the deck
for anki_note in anki_notes:
    anki_deck.add_note(anki_note)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Finally, create a package from the deck and save it.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-python&#34;&gt;# create package object
anki_package = genanki.Package(anki_deck)
# Save the deck to a file
anki_package.write_to_file(deck_filename)

# output line for status
print(&amp;quot;Created deck with {} flashcards&amp;quot;.format(len(anki_deck.notes)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You should now have a &lt;code&gt;.apkg&lt;/code&gt; file in the working directory. Import this file into
Anki and start studying!&lt;/p&gt;
&lt;p&gt;Disclaimer: I did not write most of the code in this post. Credits go to &lt;a href=&#34;https://charly-lersteau.com/&#34;&gt;Charly
Lersteau&lt;/a&gt; for his
&lt;a href=&#34;https://charly-lersteau.com/posts/2019-11-17-create-anki-deck-csv/&#34;&gt;post&lt;/a&gt; on
how he used Genanki to generate Anki decks for learning Mandarin. I merely
co-opted the codes for use with learning Korean.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Linux Power Optimizations</title>
      <link>https://richardwong.io/post/linux/2022-05-02-mon-linux-power-optimizations/</link>
      <pubDate>Tue, 24 Jan 2023 01:46:00 +0900</pubDate>
      
      <guid>https://richardwong.io/post/linux/2022-05-02-mon-linux-power-optimizations/</guid>
      <description>&lt;h2 id=&#34;background&#34;&gt;Background&lt;/h2&gt;
&lt;p&gt;In recent days one thing really bugged me: my laptop has terrible battery
life. I have long accepted that it was because my laptop was old, or that
because I was running Linux. I have always used my machine to type in a
text-editor, browse the web or listen to music. None of these seemed to me as
particularly intensive computing tasks, and yet my machine would always drop a
percentage of battery after around a few minutes of use.&lt;/p&gt;
&lt;p&gt;For a long time, my solution was to use power-profiles-daemon. It looked easy to
use, just use power-saving, balanced or performance modes. When I set it to
power-saving, my processor would run at the lowest speed (800MHz) and everything
would slow to a crawl. But hey, if it meant that I could use my computer for a
longer period of time, I didn&amp;rsquo;t mind the slightly slower performance. After all,
I mostly use emacs anyway, which could run on potato-level performance
machines. But it still wasn&amp;rsquo;t enough.&lt;/p&gt;
&lt;p&gt;I started to seriously consider getting ARM machines. Those Macbook airs do look
nice, and my current machine is nearing 5 years of use. I was convinced that I
was due for an upgrade, not because I needed a faster computer, but because I
needed a more efficient one.&lt;/p&gt;
&lt;p&gt;This topic cropped up in a conversation with one of my friends. His suggestion
was to just use Windows. And so I wondered, why is the battery life of machines
running Linux worse than Windows? I just assumed that it was due to Windows
getting more attention from manufacturers to actually produce functional drivers
and firmware for the machine and its components to run well. I then tried to
find a satisfactory reason on the internet&amp;hellip; and it just reinforces my
belief. Linux will always have worse battery life due to using drivers that are
not optimized to my machine.&lt;/p&gt;
&lt;h2 id=&#34;first-realization&#34;&gt;First Realization&lt;/h2&gt;
&lt;p&gt;But I came across a post on
&lt;a href=&#34;https://www.reddit.com/r/thinkpad/comments/alol03/tips_on_decreasing_power_consumption_under_linux/&#34;&gt;reddit&lt;/a&gt;. It
showed me so many things that I never thought of before, like power capping,
panel self-refresh. I tried to power cap my CPU to a few watts rather than the
default 20 watt limit. I also enabled panel self-refresh to see if it conserves
more power.&lt;/p&gt;
&lt;p&gt;However, my watt usage just would not go below 4 watts for a freshly-booted
system with no programs loaded. I have tried everything, from TLP and Powertop,
to following the arch guide on power optimizations.&lt;/p&gt;
&lt;p&gt;Then I saw this
&lt;a href=&#34;https://www.reddit.com/r/linux/comments/l49v4g/comment/gkpgo1j/?utm_source=share&amp;amp;utm_medium=web2x&amp;amp;context=3&#34;&gt;comment&lt;/a&gt;.
This user experienced the opposite - his battery life on Linux is a lot better
than that of Windows. I was intrigued. Then he revealed the clue: Package
C-state (package C0, C2, C3, C6, C8, and C10). This was a totally alien concept
to me. Furthermore, this is one area in which Linux systems can trump
windows. Apparently a windows system hardly goes below PC6 since there are so
many background tasks running all the time, meaning that the PC cannot idle at
the lowest power most of the time. &lt;code&gt;Powertop&lt;/code&gt; can give you a read-out on C-state
residency for your CPU, Package, and GPU. And true enough, my computer was not
able to go down to the deepest Package C-state level (PC10).&lt;/p&gt;
&lt;p&gt;Intel has a
&lt;a href=&#34;https://01.org/blogs/qwang59/2018/how-achieve-s0ix-states-linux&#34;&gt;blog&lt;/a&gt; post on
how to troubleshoot PC10 residency issues. The comment from earlier also
mentioned the same things. These are the areas to troubleshoot:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;enable PCIe runtime power mangement&lt;/li&gt;
&lt;li&gt;enable panel self-refresh&lt;/li&gt;
&lt;li&gt;ensure LTR requests are not preventing your device from reaching PC10&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;guide&#34;&gt;Guide&lt;/h2&gt;
&lt;p&gt;A quick way to check if PC10 can be reached is with the following command:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;sudo cat /sys/kernel/debug/pmc_core/package_cstate_show
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run it for a few times. When the numbers for PC10 increment, you know that it is
being reached.&lt;/p&gt;
&lt;p&gt;PCIe runtime power management can be enabled with the following kernel option in a
file &lt;code&gt;/etc/modprobe.d/newfile.conf&lt;/code&gt; or where you put your kernel boot options.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-cfg&#34;&gt;options pcie_aspm=force
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;PCIe aspm must also be set to a power-saving mode. I chose the lowest option
&amp;ldquo;powersupersave&amp;rdquo;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;echo &amp;quot;powersupersave&amp;quot; |
    sudo tee /sys/module/pcie_aspm/parameters/policy
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Panel self-refresh can be enabled with the kernel option:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-cfg&#34;&gt;options i915.enable_psr=0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For issues with LTR (latency tolerance reporting), it is more tricky. First, get
the number of devices.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;sudo cat /sys/kernel/debug/pmc_core/ltr_show
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then disable each device by passing a digit from 0 to (number of devices -
1). For me, I found 4 to be the culprit for preventing my CPU from entering
PC10.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;echo 4 |
    sudo tee /sys/kernel/debug/pmc_core/ltr_ignore
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&#34;second-realization&#34;&gt;Second Realization&lt;/h2&gt;
&lt;p&gt;After I have set my computer to apply these changes on boot, it would be able to
enter PC10 state right after booting. But this only applies when in the
TTY. When I login and my window manager loads, PC10 cannot be accessed.&lt;/p&gt;
&lt;p&gt;A big clue I found was that by booting into the default clean configuration of
SwayWM, PC10 can be accessed. This showed that it was something in my
configuration that was preventing PC10 from being accessed. I started to disable
things in my config and logging out and logging back into SwayWM. In the end, I
found that my status bar program, waybar, was the problem. I further narrowed it
down to the Tray component of waybar that was preventing my computer from
accessing the deeper PC10 state.&lt;/p&gt;
&lt;p&gt;I then replaced waybar with sway-bar + i3status-rust. This status bar allowed my
CPU to access the deeper PC10 idle mode.&lt;/p&gt;
&lt;h2 id=&#34;what-is-happening&#34;&gt;What is happening?&lt;/h2&gt;
&lt;p&gt;If we refer to the intel
&lt;a href=&#34;https://edc.intel.com/content/www/us/en/design/ipla/software-development-platforms/client/platforms/alder-lake-desktop/12th-generation-intel-core-processors-datasheet-volume-1-of-2/001/package-c-states/&#34;&gt;documentation&lt;/a&gt;,
we see that the processor enters PC10 when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;All IA cores in C10 + Processor Graphic cores in RC6.&lt;/li&gt;
&lt;li&gt;The platform components/devices allow proper LTR for entering Package C10.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This means that both the CPU and GPU must idle, and that device LTR must not
have issues.&lt;/p&gt;
&lt;p&gt;If something is constantly running in the background, the processor cannot enter
into PC10. Also, if one component has a misconfigured LTR, the processor also
cannot enter into PC10. This is why it is so tricky to get a Linux system with
proper functioning package C-states. Either the default graphical environment is
constantly running something in the background, preventing deep package
C-states, or one of the component LTR is bugged, also preventing deep package
C-states.&lt;/p&gt;
&lt;h2 id=&#34;results&#34;&gt;Results&lt;/h2&gt;
&lt;p&gt;Previously, my idle wattage would never go below 4 watts. Now with firefox and
emacs open, the idle wattage is 2.5 watts.&lt;/p&gt;
&lt;p&gt;Realistically, usage wattage previously would be around 4.5-5 watts, while usage
wattage is now around 3-3.5 watts.&lt;/p&gt;
&lt;p&gt;Due to the severely degraded state of my battery(s), I only have 28Wh of
capacity compared to the rated 42Wh&amp;rsquo;s. 28Wh can last for around 6 hours and 10
minutes at 4.5 watts, and 8 hours at 3.5 watts. That is a significant battery
life gain considering the age of the machine. Perhaps I do not need a new
computer after all (tbh I really need to get new batteries).&lt;/p&gt;
&lt;h2 id=&#34;thoughts&#34;&gt;Thoughts&lt;/h2&gt;
&lt;p&gt;My past attempts to manage power consumption on my laptop was mainly by managing
clockspeeds. I thought that a processor consumed power based on how high it is
clocked to. Others have found big gains by just running &lt;code&gt;powertop&lt;/code&gt; or &lt;code&gt;tlp&lt;/code&gt;, but
tweaking both has not given me signficantly greater battery life. But what I
missed was processor C-states, especially Package C-states. The processor was
designed to power-gate portions of itself when not in use. Clearly Intel has put
in a lot of effort to allow the processor to idle at very low power when not in
use. But because of a lack of knowledge, I just attributed the high idle power
usage to Intel processors being Intel processors; hot and power-hungry.&lt;/p&gt;
&lt;p&gt;I was pleasantly surprised at how efficient an Intel 8th gen processor can
be. When allowed to idle, it can go down to 2-2.5 watts. I am glad that my
assumptions were proven wrong and that Linux systems can indeed be very
efficient. However what I found is that many things can interfere with the
system&amp;rsquo;s ability to enter into the lowest-power PC10 state. These
troubleshooting steps are highly technical and non-obvious. If not for the
reddit post and the subsequent Intel blog posts and documentation, I would not
have realized that there was anything wrong with my computer.&lt;/p&gt;
&lt;p&gt;Knowing all these, I am curious as to how many Linux (and even windows) machines
out there are misconfigured to never be able to idle at deeper C-states. As most
reviews of laptops only focus on the performance of the laptop at maximum power,
the very significant factor of idle power is often over-looked. Moreover, it
might actually be the single largest contributor of the actual battery-life
experience of the user. This might be one reason why Intel laptops are still
able to last very long despite AMD chips having a much better usage power-draw.&lt;/p&gt;
&lt;p&gt;In my own usage, I usually have a browser and a text-editor open. Most of the
time, I am reading something from my browser and pausing to think before writing
on my editor. I am essentially doing nothing with the computer in these
moments. And in these moments of inactivity with my current configuration,
the panel engages self-refresh and allows the processor to deep-idle. But when I
need to do something again, like scrolling and typing, the machine exits its
deep-idle quickly and responds, before quickly going back to idling. This allows
the average power usage to remain very low while still being snappy.&lt;/p&gt;
&lt;p&gt;Coming back to where I started, it is nice to be able to squeeze just a little
bit more out of my machine. In my next machine, the ability to achieve PC10
residency is a definite must-have.&lt;/p&gt;
&lt;h2 id=&#34;updates&#34;&gt;Updates &lt;span class=&#34;timestamp-wrapper&#34;&gt;&lt;span class=&#34;timestamp&#34;&gt;[2023-02-19 Sun]&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;I realized that doing the following actually rendered my USB unstable. Audio
would consistently underrun, causing terrible audio artifacts when using USB
audio.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;echo 4 |
    sudo tee /sys/kernel/debug/pmc_core/ltr_ignore
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This was always meant to be a hack and not meant to be used as the final
solution. Hence I decided to do a bit of digging.&lt;/p&gt;
&lt;p&gt;By referring to this
&lt;a href=&#34;https://01.org/blogs/qwang59/2020/linux-s0ix-troubleshooting&#34;&gt;document&lt;/a&gt; and
searching for the keyword &amp;ldquo;IP OFFSET&amp;rdquo; under the &amp;ldquo;check device LTR value&amp;rdquo;
section, I found that the &lt;code&gt;IP OFFSET&lt;/code&gt; of 4 referred to the &lt;code&gt;XHCI&lt;/code&gt;. In other words,
the USB-host controller was being affected. That explained why my USB audio
device was bugging out.&lt;/p&gt;
&lt;p&gt;To see what devices were being used, the command &lt;code&gt;lsusb -tv&lt;/code&gt; is helpful. It turns
out that the &lt;code&gt;XHCI&lt;/code&gt; was not only responsible for my USB ports, but was also
handling my bluetooth and camera as well.&lt;/p&gt;
&lt;p&gt;I disabled my camera from within the BIOS firmware settings. And voila! My
computer could enter PC10 states even without the &amp;ldquo;ltr_ignore&amp;rdquo; hack.&lt;/p&gt;
&lt;p&gt;What was a further shock to me was that when I cut my screen-power to the
minimum, an idle-power of 1.9 watts was possible. No matter what I did prior to
this (killing all radios, turning off the display etc.), the lowest idle-power
was always around 2.3 watts.&lt;/p&gt;
&lt;p&gt;Damn it, it was the camera all-along&amp;hellip;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Graphing Linux Battery Usage</title>
      <link>https://richardwong.io/post/linux/2022-08-23-tue-graphing-linux-battery-usage/</link>
      <pubDate>Tue, 23 Aug 2022 15:39:00 +0900</pubDate>
      
      <guid>https://richardwong.io/post/linux/2022-08-23-tue-graphing-linux-battery-usage/</guid>
      <description>&lt;p&gt;For a long time, I have used gnome-power to look at battery use graphs. However,
its graphs are difficult to read. The x-axis isn&amp;rsquo;t well-labelled and it is
difficult to understand what the battery percentage is at a certain hour.&lt;/p&gt;
&lt;p&gt;However, I realized that most of the information found in gnome-power are
actually derived from &lt;code&gt;upower&lt;/code&gt;. What made me excited was that I found that &lt;code&gt;upower&lt;/code&gt;
logs the battery changes at &lt;code&gt;/var/lib/upower/history-charge-&amp;lt;battery-id&amp;gt;.dat&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Opening up the file, there are 3 information columns: unix-timestamp, the
battery percentage, and the battery state. And so I decided to do-away with
using a program and just use R to help me understand my battery history.&lt;/p&gt;
&lt;p&gt;Note: updated on &lt;span class=&#34;timestamp-wrapper&#34;&gt;&lt;span class=&#34;timestamp&#34;&gt;[2023-02-19 Sun]&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-R&#34;&gt;library(lubridate)
library(dplyr)
library(ggplot2)

start_time = paste(Sys.Date(), &amp;quot; 06:00:00&amp;quot;)
end_time = Sys.time()
# source file

bat &amp;lt;- list(&amp;quot;/var/lib/upower/history-charge-01AV424-24-4992.dat&amp;quot;,
            &amp;quot;/var/lib/upower/history-charge-01AV489-23-6222.dat&amp;quot;)

# function to save plot
savePlot &amp;lt;- function(x,myPlot) {
        pdf(paste(&amp;quot;bat&amp;quot;, x, &amp;quot;.pdf&amp;quot;, sep = &amp;quot;&amp;quot;))
        print(myPlot)
        dev.off()
}

for (x in 1:2) {
dat &amp;lt;- readLines(bat[[x]])
df = as.data.frame(do.call(rbind, strsplit(dat, split=&amp;quot;\\s{1,}&amp;quot;)), stringsAsFactors=FALSE)
df$V1 &amp;lt;- as.POSIXct(as.numeric(df$V1), origin=&amp;quot;1970-01-01&amp;quot;)
df$V2 &amp;lt;- as.numeric(df$V2)

# Generate some times
t_seq &amp;lt;- seq(from = ymd_hms(start_time, tz= Sys.timezone()),
             to = ymd_hms(end_time, tz = Sys.timezone()),
             by = &amp;quot;10 min&amp;quot;)

myPlot &amp;lt;- df %&amp;gt;%
filter(V1 &amp;gt;= start_time) %&amp;gt;%
filter(V1 &amp;lt;= end_time) %&amp;gt;%
ggplot(aes(V1,V2)) +
  geom_point(na.rm=TRUE) +
  scale_x_datetime(date_labels = &amp;quot;%m-%d %H:%M&amp;quot;, breaks = t_seq) +
  scale_y_continuous(limits = c(0, 100), breaks = seq(0, 100, 10)) +
  theme(axis.text.x=element_text(angle=90))

savePlot(x,myPlot)

}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Replace &lt;code&gt;bat&lt;/code&gt; with your own &lt;code&gt;battery.dat&lt;/code&gt; files.&lt;/p&gt;
&lt;p&gt;This program converts the unix-timestamp to year-month-date-hour-minutes-seconds
format. The battery percentage is on the y-axis, with the time on the
x-axis. This creates a graph of the battery usage from 6am up to the time that
you run the script.&lt;/p&gt;
&lt;p&gt;To run the script, use the &lt;code&gt;Rscript &amp;lt;file&amp;gt;&lt;/code&gt; command. Then, view the files in your
working directory with a PDF viewer.&lt;/p&gt;
&lt;p&gt;Now you can look at you battery history with better knowledge of what the
percentage was at a certain time.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Experience with the Raspberry Pi 4</title>
      <link>https://richardwong.io/post/hardware/2022-07-14-thu-experience-with-raspberry-pi-4/</link>
      <pubDate>Thu, 14 Jul 2022 20:52:00 +0800</pubDate>
      
      <guid>https://richardwong.io/post/hardware/2022-07-14-thu-experience-with-raspberry-pi-4/</guid>
      <description>&lt;p&gt;The Raspberry Pi 4 is quite an interesting piece of hardware. It is a
single-board computer (SBC) with a fairly decent CPU of 4x ARM A72 cores. Think
of mid-2010&amp;rsquo;s era smartphones. It is paired with a Broadcom VideoCore VI
GPU that is clocked at 500MHz.&lt;/p&gt;
&lt;h2 id=&#34;as-a-server&#34;&gt;As a Server&lt;/h2&gt;
&lt;p&gt;I installed an ARM 64-bit Ubuntu 20.04 Server image to try to host some stuff on
it. It worked suprisingly well! Some things I tried to host was a NextCloud
instance via an Ubuntu snap and a static-site hosted with Nginx. As the tasks
were relatively light, the Raspberry Pi 4 and its 4 CPU cores handled all these
things like a champ.&lt;/p&gt;
&lt;h2 id=&#34;as-a-desktop&#34;&gt;As a Desktop&lt;/h2&gt;
&lt;p&gt;This is were it gets a little tricky. In order to use a computer as a good
desktop, it has to be smooth. For things to be smooth on screen, there must be
some degree of graphics hardware-acceleration. Unfortunately, the GPU just isn&amp;rsquo;t
up to snuff in the graphics department.&lt;/p&gt;
&lt;p&gt;In order for there to be graphics acceleration, a special kernel built for the
Raspberry Pi 4 must be used. This is found in the Raspberry Pi OS Linux
distro. Other Linux distros lack this special kernel module found in the
Raspberry Pi OS for graphics. However, even after installing the Raspberry Pi OS
(64-bit), I found that web-browsers like Firefox and Chromium were
nigh-unusable. It is just too janky to be used as an effective web-browsing
machine.&lt;/p&gt;
&lt;p&gt;What makes things worse is that video hardware-acceleration is basically
non-existent in the desktop. What makes this particularly frustrating is that
the built-in VideoCore GPU does have dedicated video-decode blocks for H264 and
HEVC codecs! Hence all video playback is done via CPU decode only, which limits
video to 720p playback. I believe that the 32-bit OS supports video-decode
acceleration using some obscure decoder (OMX), but it still doesn&amp;rsquo;t solve the
earlier issues of inherent slowness of graphical programs.&lt;/p&gt;
&lt;p&gt;I believe that the Raspberry Pi 4 is not suitable for desktop use. It was meant
as an educational / tinkerer project platform, not a desktop replacement
computer.&lt;/p&gt;
&lt;h2 id=&#34;final-thoughts&#34;&gt;Final Thoughts&lt;/h2&gt;
&lt;p&gt;I initially bought the Raspberry Pi 4 to tinker with it. Thus far, my tinkering
has been constrained purely to software projects. I believe that is a real pity
as the GPIO pins allows for unlimited input and output accessories. I could log
readings from various sensors (temperature, humidity, air quality etc.), or I
could have a signboard displaying random strings based on the time of the
day.&lt;/p&gt;
&lt;p&gt;But even so, it worked well as a server for a few months before I moved all my
server hosting stuff to a remote VPS. My experience with it as a desktop was
frankly not good as I just couldn&amp;rsquo;t get it to work well despite trying
everything I could to optimize it. But for what it is, its actually quite good
value for a computer under a hundred (SGD) dollars.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Hosting your own Email Server</title>
      <link>https://richardwong.io/post/projects/2022-07-14-thu-hosting-your-own-email-server/</link>
      <pubDate>Thu, 14 Jul 2022 13:15:00 +0900</pubDate>
      
      <guid>https://richardwong.io/post/projects/2022-07-14-thu-hosting-your-own-email-server/</guid>
      <description>&lt;p&gt;The first question is&amp;hellip; why? Why host your own email? The answer for me is
control.&lt;/p&gt;
&lt;p&gt;Emails are almost considered a foundational part of your digital identity. You
need an email to create an account anywhere around the internet. The email is
what ties most of your digital identity to your real person. It is paramount
that you have full ownership over your own email.&lt;/p&gt;
&lt;p&gt;However, emails are notoriously difficult to setup. I was able to build my own
email with this
&lt;a href=&#34;https://workaround.org/ispmail/bullseye/big-picture/&#34;&gt;resource&lt;/a&gt;, but even so, a
quick glance through the overview page will cause you to sit down for an
afternoon to really understand how different components come together to allow
for the simple act of receiving and sending emails. I spent many weeks reading
through the entire tutorial to try to
&lt;a href=&#34;https://www.merriam-webster.com/dictionary/grok&#34;&gt;grok&lt;/a&gt; it. Even though I
knew how to host this blog, I must confess that I was really lost throughout
this whole tutorial. Emails really are a wholly different beast.&lt;/p&gt;
&lt;p&gt;Emails are complicated because it is not one thing, but a collection of software
and protocols. There is the mail server that talks with other mail servers via
SMTP, and an email client that talks with my mail server via IMAP or
POP3. Within the mail server is a database of email addresses, aliases and the
associated passwords, and also the directory to store the actual email
files. Each of the protocols and functions are governed by specific
software. Postfix will handle SMTP stuff. Dovecot is a magical do-it-all
software. It handles authentication (by hooking up with the MySQL database),
handles the actual email files on disk, and talks with the client via IMAP or
POP3. There is also Spamassassin that handles incoming spam emails. Postfix and
Dovecot must work together seamlessly for the whole operation to work, and as
such their configs are non-trivial.&lt;/p&gt;
&lt;p&gt;As if it wasn&amp;rsquo;t complicated enough, a barebones email service will not work with
modern email systems like Gmail, Outlook or any other reputable email
service. You have to enable a myriad of verification schemes for your email to
be trusted enough to even be received by such such services. These services
won&amp;rsquo;t even allow your mail to be received into the Spam folder if there&amp;rsquo;s a
slight misconfig in your security settings.&lt;/p&gt;
&lt;p&gt;It is extremely tempting to just use Gmail. If I really had no time, I would
just use a Gmail account and get on with life. But just taking the time to sit
down and configure this email service has allowed me to see an email service for
what it truly is: a collection of software and protocols. There is nothing
mysterious about it, but it is difficult. I do not have to be at the mercy of
the terms and conditions of whatever email provider I use. I do not have to
relearn their web-interface when they undergo their once-in-a-few-year
refresh. I do not have to be constrained by their web interface to do anything
(web interfaces are slooooow). Truth be told, most of my gripes with modern
email services are their web front-ends. You can just use their IMAP and SMTP
addresses and use a local client with these services as the back-end. But the
most important part of hosting your own mail is that the email files are safe
from the prying eyes of the big data firms.&lt;/p&gt;
&lt;p&gt;An alternative would be to use a privacy-focused email service. I have been
using Tutanota and its web-based client is extremely slow. Tutanota also doesn&amp;rsquo;t
cache searches, so simple searches will take tens of seconds. Also, my user
accounts in various services were disabled because their system has a global
flag on all tutanota accounts.&lt;/p&gt;
&lt;p&gt;Another popular privacy-oriented email service is ProtonMail. From what I know,
Protonmail offers an IMAP option. But given their
&lt;a href=&#34;https://techcrunch.com/2021/09/06/protonmail-logged-ip-address-of-french-activist-after-order-by-swiss-authorities/&#34;&gt;track-record&lt;/a&gt;
I would trust them with the same trust I have for Google (none).&lt;/p&gt;
&lt;p&gt;The state of email services is really disappointing. However, by creating an email
service that is simple enough for my uses, I can guarantee control, privacy and
speed.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Notetaking with Git and Emacs</title>
      <link>https://richardwong.io/post/tools/2022-07-01-notetaking-with-git-and-emacs/</link>
      <pubDate>Fri, 01 Jul 2022 00:00:00 +0900</pubDate>
      
      <guid>https://richardwong.io/post/tools/2022-07-01-notetaking-with-git-and-emacs/</guid>
      <description>&lt;p&gt;My current preferred notetaking application is org-mode in Emacs. My method of
organizing my notes is having a few large files that encompass a portion of my
life. These files could contain tens of thousands of lines of content. Since
these files are just textfiles with UTF-8 or ASCII, the files are &lt;strong&gt;very&lt;/strong&gt; lean and
potentially future-proof.&lt;/p&gt;
&lt;p&gt;I was thinking of a way to backup my org files. In my previous note-taking app
(Joplin), the app was linked to dropbox and was routinely synced with the
service. This ensured that my notes were available everywhere, including mobile
clients. A method to emulate such a behavior is to create a folder in my
Nextcloud directory and edit the org files from there. However, I remembered a
few times where I made heavy edits to my markdown notes and wished I could see
the files in a past version. And since I was learning Git, I decided to use Git
to version control my ~/org directory.&lt;/p&gt;
&lt;p&gt;But why Git? Git is made for the very purpose of tracking changes in primarily
text files. And with some utilities like &lt;code&gt;git diff&lt;/code&gt;, I could track the changes I
made across all my notes since the last commit. With Git, I could go into any
particular commit at a certain time period of my choice, and view the content of
my notes from then. Thus Git itself is the journal. This allows me to be more
aware of the progress of life between commits. Furthermore, I have a self-hosted
remote Git server accessible by ssh with a public key. This ensures total
privacy with my backup solution.&lt;/p&gt;
&lt;p&gt;Should you take notes with Git and Emacs Org-mode? I won&amp;rsquo;t recommend it since
the learning curve might be steep. I just happen to be learning both separately
and put them together to synergize my learning experience. But I must say, there
is nothing quite like it.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Rmarkdown, in a blog post?</title>
      <link>https://richardwong.io/post/demo/rmarkdown-in-a-blogpost/</link>
      <pubDate>Sun, 16 Jan 2022 23:00:05 +0800</pubDate>
      
      <guid>https://richardwong.io/post/demo/rmarkdown-in-a-blogpost/</guid>
      <description>&lt;p&gt;This post is a demonstration of an exported Rmarkdown document that I made for
one of my undergraduate assignments, converted into a blog-post form via the R
package hugodown.&lt;/p&gt;
&lt;h2 id=&#34;question-8a&#34;&gt;Question 8a&lt;/h2&gt;
&lt;p&gt;import the College.csv dataset using read.csv&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/getwd.html&#39;&gt;getwd&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;/home/richard/Insync/hochuan97@gmail.com/Google Drive/1School/2122Sem1/ST3248/Homework questions/Tutorial1&#34;&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/getwd.html&#39;&gt;setwd&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;/home/richard/Insync/hochuan97@gmail.com/Google Drive/1School/2122Sem1/ST3248/Homework questions/Tutorial1&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/read.table.html&#39;&gt;read.csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;College.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                              X Private Apps Accept Enroll Top10perc Top25perc&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 Abilene Christian University     Yes 1660   1232    721        23        52&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2           Adelphi University     Yes 2186   1924    512        16        29&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3               Adrian College     Yes 1428   1097    336        22        50&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4          Agnes Scott College     Yes  417    349    137        60        89&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5    Alaska Pacific University     Yes  193    146     55        16        44&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6            Albertson College     Yes  587    479    158        38        62&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   F.Undergrad P.Undergrad Outstate Room.Board Books Personal PhD Terminal&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1        2885         537     7440       3300   450     2200  70       78&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2        2683        1227    12280       6450   750     1500  29       30&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3        1036          99    11250       3750   400     1165  53       66&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4         510          63    12960       5450   450      875  92       97&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5         249         869     7560       4120   800     1500  76       72&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6         678          41    13500       3335   500      675  67       73&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   S.F.Ratio perc.alumni Expend Grad.Rate&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1      18.1          12   7041        60&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2      12.2          16  10527        56&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3      12.9          30   8735        54&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4       7.7          37  19016        59&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5      11.9           2  10922        15&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6       9.4          11   9727        55&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;question-8b&#34;&gt;Question 8b&lt;/h2&gt;
&lt;p&gt;renaming the rows based on the first column of the dataset&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/colnames.html&#39;&gt;rownames&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# select all rows of first col&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                              Private Apps Accept Enroll Top10perc Top25perc&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Abilene Christian University     Yes 1660   1232    721        23        52&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelphi University               Yes 2186   1924    512        16        29&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adrian College                   Yes 1428   1097    336        22        50&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Agnes Scott College              Yes  417    349    137        60        89&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Alaska Pacific University        Yes  193    146     55        16        44&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Albertson College                Yes  587    479    158        38        62&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                              F.Undergrad P.Undergrad Outstate Room.Board Books&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Abilene Christian University        2885         537     7440       3300   450&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelphi University                  2683        1227    12280       6450   750&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adrian College                      1036          99    11250       3750   400&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Agnes Scott College                  510          63    12960       5450   450&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Alaska Pacific University            249         869     7560       4120   800&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Albertson College                    678          41    13500       3335   500&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                              Personal PhD Terminal S.F.Ratio perc.alumni Expend&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Abilene Christian University     2200  70       78      18.1          12   7041&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelphi University               1500  29       30      12.2          16  10527&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adrian College                   1165  53       66      12.9          30   8735&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Agnes Scott College               875  92       97       7.7          37  19016&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Alaska Pacific University        1500  76       72      11.9           2  10922&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Albertson College                 675  67       73       9.4          11   9727&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                              Grad.Rate&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Abilene Christian University        60&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelphi University                  56&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adrian College                      54&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Agnes Scott College                 59&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Alaska Pacific University           15&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Albertson College                   55&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;comments: the first column is now Private, and each row is now named with the university&lt;/p&gt;
&lt;h2 id=&#34;question-8c-i&#34;&gt;Question 8c i&lt;/h2&gt;
&lt;p&gt;Produce numerical summary of variables in the data set&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/summary.html&#39;&gt;summary&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    Private               Apps           Accept          Enroll    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Length:777         Min.   :   81   Min.   :   72   Min.   :  35  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Class :character   1st Qu.:  776   1st Qu.:  604   1st Qu.: 242  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Mode  :character   Median : 1558   Median : 1110   Median : 434  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                     Mean   : 3002   Mean   : 2019   Mean   : 780  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                     3rd Qu.: 3624   3rd Qu.: 2424   3rd Qu.: 902  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                     Max.   :48094   Max.   :26330   Max.   :6392  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    Top10perc       Top25perc      F.Undergrad     P.Undergrad     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Min.   : 1.00   Min.   :  9.0   Min.   :  139   Min.   :    1.0  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  1st Qu.:15.00   1st Qu.: 41.0   1st Qu.:  992   1st Qu.:   95.0  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Median :23.00   Median : 54.0   Median : 1707   Median :  353.0  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Mean   :27.56   Mean   : 55.8   Mean   : 3700   Mean   :  855.3  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  3rd Qu.:35.00   3rd Qu.: 69.0   3rd Qu.: 4005   3rd Qu.:  967.0  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Max.   :96.00   Max.   :100.0   Max.   :31643   Max.   :21836.0  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     Outstate       Room.Board       Books           Personal   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Min.   : 2340   Min.   :1780   Min.   :  96.0   Min.   : 250  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  1st Qu.: 7320   1st Qu.:3597   1st Qu.: 470.0   1st Qu.: 850  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Median : 9990   Median :4200   Median : 500.0   Median :1200  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Mean   :10441   Mean   :4358   Mean   : 549.4   Mean   :1341  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  3rd Qu.:12925   3rd Qu.:5050   3rd Qu.: 600.0   3rd Qu.:1700  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Max.   :21700   Max.   :8124   Max.   :2340.0   Max.   :6800  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;       PhD            Terminal       S.F.Ratio      perc.alumni   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Min.   :  8.00   Min.   : 24.0   Min.   : 2.50   Min.   : 0.00  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  1st Qu.: 62.00   1st Qu.: 71.0   1st Qu.:11.50   1st Qu.:13.00  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Median : 75.00   Median : 82.0   Median :13.60   Median :21.00  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Mean   : 72.66   Mean   : 79.7   Mean   :14.09   Mean   :22.74  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  3rd Qu.: 85.00   3rd Qu.: 92.0   3rd Qu.:16.50   3rd Qu.:31.00  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Max.   :103.00   Max.   :100.0   Max.   :39.80   Max.   :64.00  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      Expend        Grad.Rate     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Min.   : 3186   Min.   : 10.00  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  1st Qu.: 6751   1st Qu.: 53.00  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Median : 8377   Median : 65.00  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Mean   : 9660   Mean   : 65.46  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  3rd Qu.:10830   3rd Qu.: 78.00  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Max.   :56233   Max.   :118.00&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;question-8c-ii&#34;&gt;Question 8c ii&lt;/h2&gt;
&lt;p&gt;Produce scatterplot matrix of first 10 columns&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Private&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/factor.html&#39;&gt;as.factor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Private&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# turning Private to factor&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/pairs.html&#39;&gt;pairs&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;
&lt;img src=&#34;figs/unnamed-chunk-4-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;
&lt;/div&gt;
&lt;h2 id=&#34;question-8c-iii&#34;&gt;Question 8c iii&lt;/h2&gt;
&lt;p&gt;boxplots of outstate Outstate verses Private&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/plot.default.html&#39;&gt;plot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Private&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Outstate&lt;/span&gt;,
     xlab &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Private&#39;&lt;/span&gt;,
     ylab &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Outstate&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;img src=&#34;figs/unnamed-chunk-5-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;
&lt;/div&gt;
&lt;h2 id=&#34;question-8c-iv&#34;&gt;Question 8c iv&lt;/h2&gt;
&lt;p&gt;creating new qualitative variable Elite&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;Elite&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/rep.html&#39;&gt;rep&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;No&#34;&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# create repeat vector of no&#39;s, for number of rows in college&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;Elite&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Top10perc&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;50&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Yes&#34;&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# replace any No with Yes conditionally for the row&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;Elite&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/factor.html&#39;&gt;as.factor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Elite&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# return as factor instead of numeric&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt; , &lt;span class=&#39;nv&#39;&gt;Elite&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# append to dataframe &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;check how many elite universities&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/summary.html&#39;&gt;summary&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Elite&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# 78 elite universities&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  No Yes &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 699  78&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;comments: there are 78 elite universities&lt;/p&gt;
&lt;p&gt;boxplot of Outstate vs Elite&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/plot.default.html&#39;&gt;plot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Elite&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Outstate&lt;/span&gt;,
     xlab &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Elite&#39;&lt;/span&gt;,
     ylab &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Outstate&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;img src=&#34;figs/unnamed-chunk-8-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;
&lt;/div&gt;
&lt;h2 id=&#34;question-8c-v&#34;&gt;Question 8c v&lt;/h2&gt;
&lt;p&gt;Create histograms for a few quantitative variables with differing number of bins&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/par.html&#39;&gt;par&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mfrow &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# set plot into 4 quadrants&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# Apps&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/hist.html&#39;&gt;hist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Apps&lt;/span&gt;, breaks&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;,main &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Application histogram, bin 10&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;  
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/hist.html&#39;&gt;hist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Apps&lt;/span&gt;, breaks&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;50&lt;/span&gt;,main &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Application histogram, bin 50&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;  
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/hist.html&#39;&gt;hist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Apps&lt;/span&gt;, breaks&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;, main &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Application histogram, bin 100&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/hist.html&#39;&gt;hist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Apps&lt;/span&gt;, breaks&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;500&lt;/span&gt;, main &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Application histogram, bin 500&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;img src=&#34;figs/unnamed-chunk-9-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;
&lt;span class=&#39;c&#39;&gt;# Top25perc&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/hist.html&#39;&gt;hist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Top25perc&lt;/span&gt;, breaks&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, main &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Top 25 histogram, bin 10&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/hist.html&#39;&gt;hist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Top25perc&lt;/span&gt;, breaks&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;50&lt;/span&gt;, main &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Top 25 histogram, bin 50&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/hist.html&#39;&gt;hist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Top25perc&lt;/span&gt;, breaks&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;,main &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Top 25 histogram, bin 100&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/hist.html&#39;&gt;hist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Top25perc&lt;/span&gt;, breaks&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;500&lt;/span&gt;,main &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Top 25 histogram, bin 500&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;img src=&#34;figs/unnamed-chunk-9-2.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;
&lt;span class=&#39;c&#39;&gt;# Enroll&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/hist.html&#39;&gt;hist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;PhD&lt;/span&gt;, breaks&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;,  main &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;PhD histogram, bin 10&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/hist.html&#39;&gt;hist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;PhD&lt;/span&gt;, breaks&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;50&lt;/span&gt;,  main &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;PhD histogram, bin 50&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;  
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/hist.html&#39;&gt;hist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;PhD&lt;/span&gt;, breaks&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;, main &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;PhD histogram, bin 100&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/hist.html&#39;&gt;hist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;college&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;PhD&lt;/span&gt;, breaks&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;500&lt;/span&gt;, main &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;PhD histogram, bin 500&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;img src=&#34;figs/unnamed-chunk-9-3.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;
&lt;/div&gt;
&lt;h2 id=&#34;question-8c-vi&#34;&gt;Question 8c vi&lt;/h2&gt;
&lt;p&gt;Continued exploration.&lt;/p&gt;
&lt;p&gt;By observing the scatterplot, we can see several associated variables. Apps, Accept, Enroll, F.Undergrad are associated with each other. Top10perc and Top25perc are associated with each other.&lt;/p&gt;
&lt;p&gt;Also, from the boxplots, we can also see that out-of-state (Outstate) tuition is higher for Private universities, and also for elite universities. We can see that out-of-state tuition can be explained partly by whether the university is private, or whether it is an elite university.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Introduction to BTRFS</title>
      <link>https://richardwong.io/post/linux/2021-11-09-introduction-to-btrfs/</link>
      <pubDate>Tue, 09 Nov 2021 09:40:05 +0800</pubDate>
      
      <guid>https://richardwong.io/post/linux/2021-11-09-introduction-to-btrfs/</guid>
      <description>&lt;p&gt;BTRFS. B-tree FS. Butter FS. I personally call it B-tree FS. Not many Linux
Distros come with BTRFS by default, but many provide it as an option in the
installer. Personally, I found it to be scary at first, opting to use LVM
(logical volume manager) initially. But with time I realised that the things I
tried to do to ensure redundancy of data was better achieved with BTRFS.&lt;/p&gt;
&lt;h2 id=&#34;hierarchy-and-subvolumes&#34;&gt;Hierarchy and Subvolumes&lt;/h2&gt;
&lt;p&gt;If you use other filesystems, you would probably set up your filesystem with the
following hierarchy:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;boot -&amp;gt; FAT32 / 500MB
swap -&amp;gt; linux-swap / size of RAM
root -&amp;gt; ext4 / 20GB
home -&amp;gt; ext4 / rest of your disk
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, in my BTRFS system, it looks like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;boot -&amp;gt; FAT32 / 500MB
BTRFS partition -&amp;gt; rest of the disk 
    root -&amp;gt; @root subvolume 
    home -&amp;gt; @home subvolume
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This might look very confusing. Firstly, where is the swap? I personally prefer
alternatives to having a swap-partition, be it swap-files or zram. In BTRFS,
creating a disk-based swap is slightly more complicated. We&amp;rsquo;ll touch on this
towards the end of the article. Secondly, why do I not need to set the size of
the root and home partitions in BTRFS? This is your first encounter with
subvolumes: they are not partitions. You can think of them more like directories
than traditional partitions. This means that they dynamically scale with the
size of the files in them. They can expand and shrink without ruining and
corrupting your disk.&lt;/p&gt;
&lt;h2 id=&#34;how-to-set-up-a-btrfs-disk&#34;&gt;How to set up a BTRFS disk&lt;/h2&gt;
&lt;p&gt;Firstly, we have to wipe your disk to install a new GPT partition layout.&lt;/p&gt;
&lt;p&gt;I assume that you are using a disk named /dev/sda in your lsblk.&lt;/p&gt;
&lt;p&gt;We will run fdisk. Run fdisk by running &lt;code&gt;fdisk&lt;/code&gt; in your terminal with
superuser.&lt;/p&gt;
&lt;p&gt;Options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;p: print current disk info&lt;/li&gt;
&lt;li&gt;g: create new GPT table&lt;/li&gt;
&lt;li&gt;n: create new partition&lt;/li&gt;
&lt;li&gt;t: set partition type (this is not setting the filesystem)&lt;/li&gt;
&lt;li&gt;L: list partition type&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For the following steps, just key in the letters as shown.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;create new table&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;g&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start=&#34;2&#34;&gt;
&lt;li&gt;create boot partition&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;n&lt;/li&gt;
&lt;li&gt;press enter without keying anything for part number and first sector&lt;/li&gt;
&lt;li&gt;for Last Sector: +500M&lt;/li&gt;
&lt;li&gt;t: 1&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start=&#34;3&#34;&gt;
&lt;li&gt;create linux filesystem partition&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;follow defaults by pressing enter all the way&lt;/li&gt;
&lt;li&gt;t: 20 - reminder: L to list partition types&lt;/li&gt;
&lt;/ul&gt;
&lt;ol start=&#34;4&#34;&gt;
&lt;li&gt;write changes to disk&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;w - note: this is irreversible&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;creating-filesystems-for-your-partitions&#34;&gt;Creating filesystems for your partitions&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;lsblk # verify partition layout
mkfs.fat -F32 /dev/sda1
mkfs.btrfs -R free-space-tree -m dup -L &amp;lt;label-name&amp;gt; /dev/sda2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;some options listed here for mkfs.btrfs are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;R : set cache-type. free-space-tree, or space_cache=v2, is a much faster and
scalable option compared to the default v1&lt;/li&gt;
&lt;li&gt;m : metadata options. single, raid, dup. I used dup for duplicate so that
there is on disk redundancy for metadata. More on this later.&lt;/li&gt;
&lt;li&gt;L : label for BTRFS partition. You can give this anything. I usually name this
after the distro that I install the system on, or the name of the SSD / HDD
model or manufacturer.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;create-and-mount-btrfs-subvolumes&#34;&gt;Create and mount BTRFS subvolumes&lt;/h2&gt;
&lt;p&gt;I will now demonstrate how to create BTRFS subvolumes. You might need to run
mount and btrfs with superuser.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// mount the BTRFS partition on /mnt 
mount -o /dev/sda2 /mnt
cd /mnt

// create the subvolumes 
btrfs subvolume create demo

// let us unmount to remount the individual subvolume
cd /
umount /mnt

// mount the new subvolume &amp;quot;demo&amp;quot;
mount -o noatime,compress=zstd:2,space_cache=v2,subvol=demo /dev/sda2 /mnt
cd /mnt
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What have I done here? I mounted the BTRFS partition at /mnt, created a
subvolume named &amp;ldquo;demo&amp;rdquo;, and remounted &amp;ldquo;demo&amp;rdquo; at /mnt.&lt;/p&gt;
&lt;p&gt;Note that only the subvolume &amp;ldquo;demo&amp;rdquo; is mounted. That means that we can only
access the files in the &amp;ldquo;demo&amp;rdquo; subvolume. We can treat &amp;ldquo;demo&amp;rdquo; as a fully
contained &amp;ldquo;partition&amp;rdquo; in itself.&lt;/p&gt;
&lt;p&gt;This is how we can create &amp;ldquo;root&amp;rdquo; and &amp;ldquo;home&amp;rdquo; subvolumes (just replace the above
demo with &amp;ldquo;root&amp;rdquo; and &amp;ldquo;home&amp;rdquo;) and mount them at the mountpoints &amp;ldquo;/&amp;rdquo; for root and
&amp;ldquo;/home&amp;rdquo; for home respectively.&lt;/p&gt;
&lt;h2 id=&#34;mount-options-for-btrfs&#34;&gt;Mount options for BTRFS&lt;/h2&gt;
&lt;p&gt;So far, we have only demonstrated the creation of BTRFS subvolumes that appear
as if they are dynamic partitions. The real magic lies in the options we give to
/etc/fstab to mount them on system boot.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;UUID=&amp;lt;UUID&amp;gt; /mountpoint btrfs noatime,compress=zstd:2,ssd,space_cache=v2,subvol=/subvol	0 0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that we can get UUID using &amp;ldquo;lsblk -o PATH,UUID&amp;rdquo;&lt;/p&gt;
&lt;p&gt;What are the options listed here?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;noatime: no atime updates for each file. BTRFS incurs performance penalty with
frequent atime updates due to its CoW (copy-on-write) nature.&lt;/li&gt;
&lt;li&gt;compress: set compression algorithm and level of compression. zstd:2 has the
fastest mix of write and read speeds. zstd:3 is the default and is fine.
Higher numbers have better compression ratios at the cost of speed.
&lt;ul&gt;
&lt;li&gt;Refer to
&lt;a href=&#34;https://docs.google.com/spreadsheets/d/1x9-3OQF4ev1fOCrYuYWt1QmxYRmPilw_nLik5H_2_qA/edit#gid=0&#34;&gt;here&lt;/a&gt;
for the benchmarks of different zstd levels and similar compression
algorithms.&lt;/li&gt;
&lt;li&gt;as of the time of writing, there is no way to set &amp;ldquo;fast&amp;rdquo; levels for ZSTD
in fstab options (&lt;a href=&#34;https://github.com/facebook/zstd/issues/2821&#34;&gt;source&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;space_cache=v2 : a scalable free space cache that uses trees. v1 slows down if
disk is bigger than 1TB&lt;/li&gt;
&lt;li&gt;ssd: tells btrfs we are using SSD. omit this if you use HDD.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;btrfs-features&#34;&gt;BTRFS features&lt;/h2&gt;
&lt;p&gt;In the mount options, I have covered the copy-on-write and compression features
of BTRFS. These are some of the amazing features of BTRFS that makes it a modern
filesystem that puts it ahead of other filesystems with the exception of ZFS.&lt;/p&gt;
&lt;p&gt;Copy-on-write, or CoW, is a feature where copy is deferred until the the file is
modified. A copy operation is O(1) time, regardless of the size. That means that
if I were to copy the whole subvolume to a new subvolume (this is called
snapshotting), it is an O(1) operation. Let that sit in for while.&lt;/p&gt;
&lt;p&gt;And speaking of snapshots, you can create read-only snapshots of a live-running
system, allowing you to backup your computer while it is running. And if your
system fails in the future, or a file is lost, you can simply restore it by
booting a live disk, mounting a disk and doing just 2 move operations: &lt;code&gt;mv root broken_root&lt;/code&gt; and &lt;code&gt;mv snapshot root&lt;/code&gt;, then setting the restored root to
read and write and setting the broken root to read-only. Now you have a bootable
system that is identical to the moment when you snapshotted it. I will cover
this in future post on BTRFS snapshots.&lt;/p&gt;
&lt;p&gt;Another great feature of snapshots is that you can send them over a unix pipe,
and yes, that includes SSH. So you can remotely snapshot your system and send
the files over the internet to a VPS to store your backups. But sending whole
disks that could be hundreds of gigabytes over the network each time is not
feasible, hence there is a function to perform an incremental send, that is,
sending only the changes of a new snapshot from an older one to build the new
snapshot on the receiving using the existing older snapshot as a base. This is a
great feature that makes backups a breeze and is relatively lighter on network
usage, amounting to only multiple gigabytes for a week of changes. (for some
gigabit internet is not available, but I believe a LAN with another local
machine should be able to achieve hundred megabit speeds with only a couple of
ethernet cables and a relatively modern WiFi router)&lt;/p&gt;
&lt;p&gt;Compression in BTRFS, or otherwise known as &amp;ldquo;transparent compression&amp;rdquo; is just
lossless compression, aka compression that you benefit from without noticing its
ill-effects (artifacting, data-loss). The obvious benefits of compression is
reduced disk space usage. But the greater benefit of file-system compression is
I/O speed increases. It is sometimes faster to compress data, send the
compressed data through the bottlenecked I/O channels, and decompress the data
on the other side. Here, we utilize the fact that CPUs can compress and
decompress data much faster than the actual I/O transfer speed to sacrifice some
CPU cycles to accelerate I/O.&lt;/p&gt;
&lt;p&gt;In BTRFS, not only is data stored, but metadata is stored alongside data. Every
data has a checksum associated with it, and this checksum is stored in the
metadata. The metadata is important as it is the means to check for data
corruption AND also correct data corruption. Why would there be a need for data
correction? Haven&amp;rsquo;t people been using their computers fine without random data
suddenly disappearing from them, even in the land of Windows? Read
&lt;a href=&#34;https://arstechnica.com/information-technology/2014/01/bitrot-and-atomic-cows-inside-next-gen-filesystems/&#34;&gt;this&lt;/a&gt;
article. Random file corruptions occur because of bit-rot, and without
checksumming and filesystem-based error-correction, you might lose precious
files to the evil stochastic processes that randomly choose which bits to flip.
With BTRFS and the &lt;code&gt;btrfs scrub&lt;/code&gt; operation, your files will remain the same
for all time, until your disk fails&amp;hellip;&lt;/p&gt;
&lt;h2 id=&#34;btrfs-quirks&#34;&gt;BTRFS quirks&lt;/h2&gt;
&lt;p&gt;These come mainly from its CoW feature. Remember, CoW means that a copy is
deferred until the file is modified. Why doesn&amp;rsquo;t BTRFS just modify the file in
place? Why keep the old file and write a new file with the modifications?
Doesn&amp;rsquo;t that incur greater disk usage?&lt;/p&gt;
&lt;p&gt;Yes. CoW is not magic. Our O(1) copy is possible because files are never
modified in-place. Our files will always be available by just pointing to it,
thus the new snapshot &amp;ldquo;copy&amp;rdquo; simply points back to the unchanged files. Every
modification operation is simply writing a new file at a new block.&lt;/p&gt;
&lt;p&gt;This is the reason why BTRFS subvolumes are always mounted with &amp;ldquo;noatime&amp;rdquo;
option. We want to minimize unnecessary file modifications as much as possible,
because each modificaiton will trigger a disk-write operation of the whole file.
This incurs an I/O penalty, but this would be ok if the disk is used without
another BTRFS feature called snapshots because older blocks would simply be
marked as discarded after modification, which in an SSDs case would be trim-ed
in O(1) time. (Note that SSDs also do not modify data in place, but writing new
data to fresh blocks and discarding old blocks, thus BTRFS is very suited for
the architecture of SSDs) The issue lies in using BTRFS with snapshots with
frequent file modifications. A simple recursive atime update through all
directories will trigger a new write on all the updated files without deleting
the old date.&lt;/p&gt;
&lt;p&gt;Disk slow-down will happen in the event of frequent file modifications. Thus
directories or files with frequent modifications like a virtual machine qcow2
file or a database directory will need to have CoW disabled via &lt;code&gt;sudo chattr +C file&lt;/code&gt; OR &lt;code&gt;sudo chattr -R +C dir&lt;/code&gt;. Fortunately, through some magic, it
is possible to snapshot subvolumes with CoW disabled (by momentarily enabling
CoW during the moment of snapshoting to preserve old blocks).&lt;/p&gt;
&lt;p&gt;Though BTRFS employs checksumming and utilizes metadata to recover corrupted
data, what happens when the metadata itself is corrupted? In the event that the
metadata is corrupted, perfectly fine data is flagged as corrupted with no
option to tell whether the data is indeed corrupted or the option to restore the
data.  Therefore it is important to have redundancy for the metadata.&lt;/p&gt;
&lt;p&gt;Earlier, the BTRFS partition was created with the &amp;ldquo;-m dup&amp;rdquo; option. This creates
a BTRFS partition with duplicate metadata, thus ensuring redundancy even for the
metadata. Now it will take the corruption of 2 duplicate checksums on different
parts of the disk to totally corrupt a data. That&amp;rsquo;s not going to happen unless
your entire disk is failing.&lt;/p&gt;
&lt;h2 id=&#34;is-it-worth-it&#34;&gt;Is it worth it?&lt;/h2&gt;
&lt;p&gt;BTRFS definitely has its fair share of quirks, but even the best filesystem,
ZFS, has its cons when compared to BTRFS. For a single disk user, BTRFS is
arguably as good as it gets. Now that you have a disk set-up with BTRFs, you can
now follow my other guides tagged with &amp;ldquo;BTRFS&amp;rdquo; to unlock even more powerful
functionality.&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
