<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.5">Jekyll</generator><link href="https://daviskirkendall.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://daviskirkendall.com/" rel="alternate" type="text/html" /><updated>2024-05-16T22:50:30+00:00</updated><id>https://daviskirkendall.com/feed.xml</id><title type="html">Davis Kirkendall</title><subtitle>Davis Kirkendall's personal coding blog for python, web, data, devops and other stuff</subtitle><entry><title type="html">Why I use Doom Emacs</title><link href="https://daviskirkendall.com/2021/08/05/why-i-use-doom-emacs/" rel="alternate" type="text/html" title="Why I use Doom Emacs" /><published>2021-08-05T00:00:00+00:00</published><updated>2021-08-05T00:00:00+00:00</updated><id>https://daviskirkendall.com/2021/08/05/why-i-use-doom-emacs</id><content type="html" xml:base="https://daviskirkendall.com/2021/08/05/why-i-use-doom-emacs/"><![CDATA[<h1 id="me-vs-emacs">Me vs. Emacs</h1>

<p>GNU Emacs is (and has been since 1985) a text editor that has always focused on
extreme customizability. Users do anything from editing code to writing books
to reading email to browsing the web to playing Tetris.</p>

<p>I have been using Emacs as my main text editor for over 10 years now mainly
due to the fact that I can make it behave <strong>EXACTLY</strong> the way I want.
For a long time there wasn’t really another choice if you wanted a truly
customizable editor (VIM counts but more on that later). In the last few years,
VScode has actually changed this a little bit allowing all sorts of extensions
to make it a pretty customizable editor.</p>

<p>Once in a while the question comes up: Why would you use/learn Emacs if you can just
start with VScode?</p>

<p>Looking at VScode made me revisit a question I had not asked in a long time:
Could I (in theory) switch to a different editor if I really wanted.
The answer I came up with is <strong>NO</strong>, mainly because I realized how absurdly dependent I am on my 10 year old Emacs
configuration that has organically grown to a something that might come alive or
turn into SkyNet at any time.</p>

<p>This realization pushed me to experiment with simplifying or at least
standardizing my configuration a tiny bit such that I wouldn’t be completely
helpless if I were ever forced to delete all
traces of my personal Emacs configuration.</p>

<p>I went through a few strategies:</p>

<h2 id="1-trying-to-be-more-disciplined">1. Trying to be more disciplined</h2>

<p>The first thing I tried was fairly simple: Just be disciplined and use standard
Emacs keybindings and default packages settings more.</p>

<p>Unfortunately this failed miserably as the Emacs keybindings are not very
ergonomic (for me) on a modern squashed laptop keyboard and aren’t very intuitive (to me).
In addition my personal keybindings were sometimes close “enough” to the originals that I would end up getting confused all the time.
I got lazy and gave up pretty quickly.</p>

<h2 id="2-use-someone-elses-emacs-configuration">2. Use someone else’s Emacs configuration</h2>

<p>There a bunch of people who spend a great amount of time configuring Emacs and
have published their configurations on GitHub. I could just go there grab one
and stick to it (or at least not mess it up).
A notable example in this category would be:</p>

<ul>
  <li>https://github.com/purcell/emacs.d</li>
</ul>

<p>Steve Purcell’s personal Emacs config in which he basically takes the “disciplined” approach mentioned above, but did it much, much better than I could ever do.</p>

<p>In the end, I decided to not go this route as I think it I would end up just morphing it into my broken unmaintainable strange configuration again (see the discipline problem above).</p>

<h2 id="3-pre-bundled-emacs-distributions">3. Pre-bundled Emacs “Distributions”</h2>

<p>These are various “meta-configurations” that pre-configure Emacs with (hopefully)
sensible settings and often bundle a few packages to give Emacs a modern look
and feel. Notable mentions here are:</p>

<ul>
  <li>
    <p><a href="https://github.com/bbatsov/prelude">Prelude</a>: Nice configuration with a framework feeling to it, doing a lot of work for you and separating out a “personal” configuration folder to allow the user to leave the core prelude settings alone.</p>
  </li>
  <li>
    <p><a href="https://www.spacemacs.org/">Spacemacs</a>: True magic framework.
This does everything for you, looks awesome right from the start, has all sorts of stuff baked in and is easy to start on as it adds a whole meta-configuration system on top called
“layers”. It also uses vim keybindings (evil-mode).</p>
  </li>
  <li>
    <p><a href="https://github.com/hlissner/doom-emacs">Doom Emacs</a>: Seems to be inspired by Spacemacs (also uses vim keybindings) but has a different approach regarding customization.
I ended up choosing doom because the defaults were good, it’s was easy to add what, just as easy to opt-out of what I don’t want and at the same time possible to extend and modify the stuff that doesn’t work for me.</p>
  </li>
</ul>

<h1 id="diving-into-doom-emacs">Diving into Doom Emacs</h1>

<p>Doom Emacs is written by <a href="https://github.com/hlissner">Henrik Lissner</a> and it’s pretty amazing what he has done.
The configuration system is very clean and let’s the user go from having a nice out of the box no-configuration experience (including a walkthrough setup wizard) to integrating your own Elisp code without breaking anything.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cp ~/.emacs.d ~/.emacs.d.backup # backup your own configuration if you have one
git clone --depth 1 https://github.com/hlissner/doom-emacs ~/.emacs.d
~/.emacs.d/bin/doom install
</code></pre></div></div>

<p>The generated file <code class="language-plaintext highlighter-rouge">~/.doom.d/init.el</code>, which looks like <a href="https://github.com/hlissner/doom-emacs/blob/develop/init.example.el">this</a>, is the only file you really have to edit if you’re getting started.
Just uncomment the parts you want and run</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code>~/.emacs.d/bin/doom refresh
</code></pre></div></div>

<p>which will download and configure the correct packages so the next time you
start Emacs they will be there.</p>

<p>Regarding other configuration files, the <code class="language-plaintext highlighter-rouge">package.el</code> file defines what external packages need to be loaded and the
<code class="language-plaintext highlighter-rouge">config.el</code> is basically a free for all configuration file similar to the
<code class="language-plaintext highlighter-rouge">init.el</code> we’re used to in Emacs.</p>

<p>The setup forces the me to think about the structure of <a href="https://github.com/daviskirk/doom.d">my configuration</a> and be a bit more organized… nice!</p>

<h2 id="turning-evil-and-learning-vim-keybindings">Turning evil and learning vim keybindings</h2>

<p>Learning Vim keybindings actually has a lot of advantages:</p>

<ul>
  <li>Vim Keybindings actually have an internal (if somewhat convoluted) logic to
them <a href="https://yanpritzker.com/learn-to-speak-vim-verbs-nouns-and-modifiers-d7bfed1f6b2d">verbs, nouns and
modifiers</a>,
so it’s not as common to change every single navigation key binding as it is in Emacs land.</li>
  <li>Vim or Vi is everywhere on basically every server and on every (unix) desktop.</li>
  <li>(Almost) every application related to software development has vim keybindings
(I have the feeling Emacs bindings aren’t quite as ubiquitous since so many
Emacs users rebind the default Emacs bindings anyway)</li>
</ul>

<p>The big advantage in using doom Emacs (or emacs + evil-mode in general) is that you still don’t have to give up all of Emacs other customization possibilities and features.
I still get to use <a href="https://magit.vc/">Magit</a>, Docker and Kubernetes integration, org mode and all the good stuff I like about Emacs in the first place.</p>

<h1 id="conclusion">Conclusion</h1>

<p>I don’t know if I can stick with the “default” Doom Emacs configuration or if I will end up in the same place I was a couple of months ago again.
I do think I will be able to stick to the basic Vim navigational bindings which will at least help me navigate other computers and servers (where I do not have my configurations installed) more successfully.</p>

<p>I get the feeling that modern configurable editors like VScode have inspired the Emacs community to think a little bit about “out of the box” usability for people that are used to using younger editors like VScode or Atom, and I’m glad about this.
After all, there are still enough reasons to use Emacs over any other editor and it would be a shame if anyone lost out because default Emacs scared them away on the first day.</p>]]></content><author><name></name></author><category term="emacs" /><category term="vscode" /><summary type="html"><![CDATA[Doom Emacs broadens my editor horizons]]></summary></entry><entry><title type="html">Datetime conversion discovery</title><link href="https://daviskirkendall.com/2015/02/19/datetime-vs.-numpy-vs.-pandas/" rel="alternate" type="text/html" title="Datetime conversion discovery" /><published>2015-02-19T00:00:00+00:00</published><updated>2015-02-19T00:00:00+00:00</updated><id>https://daviskirkendall.com/2015/02/19/datetime%20vs.%20numpy%20vs.%20pandas</id><content type="html" xml:base="https://daviskirkendall.com/2015/02/19/datetime-vs.-numpy-vs.-pandas/"><![CDATA[<p>
Date and time handling seem to always be a tiny bit frustrating. This is not
only because getting it right is a really hard thing to do but also because
there are many different ways of looking at the problem. In python, there are
lots of differen types and modules for handling dates and times, including the
builtin <code>datetime</code> module, <code>numpy</code>'s <code>datetime64</code> system and the many different
tools and abstractions that <code>pandas</code> provides on top.
</p>

<div class="org-src-container">

<pre class="src src-python"><span style="color: #F0DFAF; font-weight: bold;">import</span> numpy <span style="color: #F0DFAF; font-weight: bold;">as</span> np
<span style="color: #F0DFAF; font-weight: bold;">import</span> pandas <span style="color: #F0DFAF; font-weight: bold;">as</span> pd
<span style="color: #F0DFAF; font-weight: bold;">import</span> datetime
</pre>
</div>

<p>
This <code>datetime.datetime</code> objects is initialized based on seconds.
For example, this will work:
</p>
<div class="org-src-container">

<pre class="src src-python"><span style="color: #DFAF8F;">dt64</span> = np.datetime64<span style="color: #DCDCCC;">(</span><span style="color: #CC9393;">'2015-02-19T15:20:15'</span><span style="color: #DCDCCC;">)</span>
<span style="color: #DFAF8F;">datetime_cast</span> = dt64.astype<span style="color: #DCDCCC;">(</span>datetime.datetime<span style="color: #DCDCCC;">)</span>
datetime_cast
</pre>
</div>

<pre class="example">
datetime.datetime(2015, 2, 19, 14, 20, 15)
</pre>

<p>
However, if you start using types and time bases other than second and minutes,
the conversions will just not work, and return <code>long</code> objects.
</p>

<div class="org-src-container">

<pre class="src src-python"><span style="color: #DFAF8F;">dt64</span> = np.datetime64<span style="color: #DCDCCC;">(</span><span style="color: #CC9393;">'2015-02-19T15:20:15'</span>,<span style="color: #CC9393;">'ns'</span><span style="color: #DCDCCC;">)</span>  <span style="color: #5F7F5F;"># </span><span style="color: #7F9F7F;">nanoseconds</span>
<span style="color: #DFAF8F;">datetime_cast</span> = dt64.astype<span style="color: #DCDCCC;">(</span>datetime.datetime<span style="color: #DCDCCC;">)</span>
datetime_cast
</pre>
</div>

<pre class="example">
1424355615000000000L
</pre>

<p>
I stumbled across this when working with <code>pandas</code> timeseries.
<code>pd.Datetimeindex</code> objects use <code>datetime64[ns]</code> objects under the hood to that
if for some reason you were to create a timerange using pandas and work with
the underlying <code>datetime64[ns]</code> array. A conversion to <code>datetime.datetime</code>
objects will no longer work directly.
</p>

<p>
Let's say we have this construct:
</p>
<div class="org-src-container">

<pre class="src src-python"><span style="color: #DFAF8F;">dates</span> = pd.date_range<span style="color: #DCDCCC;">(</span><span style="color: #CC9393;">'2012-1-1'</span>, periods=5, freq=<span style="color: #CC9393;">'D'</span><span style="color: #DCDCCC;">)</span>
dates
</pre>
</div>

<pre class="example">
&lt;class 'pandas.tseries.index.DatetimeIndex'&gt;
[2012-01-01, ..., 2012-01-05]
Length: 5, Freq: D, Timezone: None
</pre>

<div class="org-src-container">

<pre class="src src-python"><span style="color: #DFAF8F;">dates_dt64</span> = dates.values
dates_dt64
</pre>
</div>

<pre class="example">
array(['2012-01-01T01:00:00.000000000+0100',
       '2012-01-02T01:00:00.000000000+0100',
       '2012-01-03T01:00:00.000000000+0100',
       '2012-01-04T01:00:00.000000000+0100',
       '2012-01-05T01:00:00.000000000+0100'], dtype='datetime64[ns]')
</pre>

<p>
and we want see represent a value as a <code>datetime.datetime</code> object.
As long as we stay within pandas, we're fine:
</p>
<div class="org-src-container">

<pre class="src src-python"><span style="color: #DFAF8F;">ts</span> = dates<span style="color: #DCDCCC;">[</span>0<span style="color: #DCDCCC;">]</span> <span style="color: #5F7F5F;"># </span><span style="color: #7F9F7F;">scalar timestamp</span>
ts
</pre>
</div>
<pre class="example">
Timestamp('2012-01-01 00:00:00', offset='D')
</pre>

<div class="org-src-container">

<pre class="src src-python">ts.to_datetime<span style="color: #DCDCCC;">()</span>
</pre>
</div>
<pre class="example">
datetime.datetime(2012, 1, 1, 0, 0)
</pre>

<p>
If we use the underlying values however:
</p>
<div class="org-src-container">

<pre class="src src-python"><span style="color: #DFAF8F;">dt64</span> = dates_dt64<span style="color: #DCDCCC;">[</span>0<span style="color: #DCDCCC;">]</span>  <span style="color: #5F7F5F;"># </span><span style="color: #7F9F7F;">scalar datetime64 object</span>
<span style="color: #DFAF8F;">dt</span> = dt64.astype<span style="color: #DCDCCC;">(</span>datetime.datetime<span style="color: #DCDCCC;">)</span>  <span style="color: #5F7F5F;"># </span><span style="color: #7F9F7F;">try cast</span>
dt
</pre>
</div>

<pre class="example">
1325376000000000000L
</pre>

<p>
We get stuck with a <code>long</code> because <code>dates_dt64</code> base is in nanoseconds.
</p>
<div class="org-src-container">

<pre class="src src-python">ts.dtype
</pre>
</div>

<pre class="example">
'org_babel_python_eoe'
</pre>

<p>
The fix is easy when you know this is going on:
</p>
<div class="org-src-container">

<pre class="src src-python"><span style="color: #DFAF8F;">dates_dt64_s</span> = dates_dt64.astype<span style="color: #DCDCCC;">(</span><span style="color: #CC9393;">'datetime64[s]'</span><span style="color: #DCDCCC;">)</span>
<span style="color: #DFAF8F;">dt64_s</span> = dates_dt64_s<span style="color: #DCDCCC;">[</span>0<span style="color: #DCDCCC;">]</span>  <span style="color: #5F7F5F;"># </span><span style="color: #7F9F7F;">single datetime63 object</span>
<span style="color: #DFAF8F;">dt_seconds</span> = dt64_s.astype<span style="color: #DCDCCC;">(</span>datetime.datetime<span style="color: #DCDCCC;">)</span>
dt_seconds
</pre>
</div>

<pre class="example">
datetime.datetime(2012, 1, 1, 0, 0)
</pre>

<p>
Thank god that for most use cases, pandas handles all of these weird casts and
conversions beautifully so that you don't need to know any of the above in 99%
of your uses.
</p>]]></content><author><name></name></author><summary type="html"><![CDATA[How different underlying types make for confusing conversions between datetime formats in python]]></summary></entry></feed>