<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Blog | Raul Benencia</title>
    <link>https://rbenencia.name/blog/</link>
    <description>Recent content in Blog on Raul Benencia</description>
    
    <language>en-us</language>
    <lastBuildDate>Fri, 19 Jun 2026 22:38:56 -0300</lastBuildDate><atom:link href="https://rbenencia.name/blog/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>The best dependency is the one you don&#39;t need</title>
      <link>https://rbenencia.name/blog/2026-06-19-dependencies/</link>
      <pubDate>Fri, 19 Jun 2026 22:38:56 -0300</pubDate>
      <guid>https://rbenencia.name/blog/2026-06-19-dependencies/</guid>
      <description>&lt;p&gt;Antoine de Saint-Exupéry, best known for &lt;em&gt;Le Petit Prince&lt;/em&gt;, wrote in &lt;em&gt;Terre des hommes&lt;/em&gt; that:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Il semble que la perfection soit atteinte non quand il n’y a plus rien à ajouter, mais quand il n’y a plus rien à retrancher.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is normally translated to English as:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Perfection is finally obtained not when there is no longer anything to add, but when there’s no longer anything to take away.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This philosophy can also be applied to software. The UNIX adage “make each program do one thing well” encourages slim applications that are not bloated with features or dependencies.&lt;/p&gt;
&lt;p&gt;In this article I want to focus on dependencies. Every dependency is also a trust relationship: in upstream maintainers, their release process, their response to vulnerability disclosures, and the continued availability of their maintenance time. Dependencies are therefore delegated maintenance and delegated trust. Some are worth that delegation; some are not. The constant stream of &lt;a href=&#34;https://en.wikipedia.org/wiki/Supply_chain_attack&#34;&gt;supply chain attacks&lt;/a&gt; is a reminder that dependencies can be a liability.&lt;/p&gt;
&lt;p&gt;Eight years ago I wrote &lt;a href=&#34;https://rbenencia.name/blog/2018-05-20-shoelaces/&#34;&gt;Shoelaces&lt;/a&gt;, a tool for automating server bootstrapping. Back in the day, the company I was working for ran entirely on-premises, and we were scaling fast. My role as an SRE was full-stack in the broadest sense: it ranged from fine-tuning complex distributed systems to the mundane work of screwing hundreds of disks into drive caddies before inserting them into servers. We automated everything we could.&lt;/p&gt;
&lt;p&gt;Shoelaces was our solution to server bootstrapping automation. Whenever a server was turned on, it would show up on a webpage and allow the operator to choose from a list of recipes. In this way we simplified the installation of bare-metal servers such as Kubernetes workers, Xen virtualizers, and various database servers, among other systems. Shoelaces would also support fully unattended bootstrapping: a CIDR could be associated with a recipe, and every device attempting an iPXE boot on that network would get a full OS installation. This was useful for configuring appliances that would later get shipped to customers.&lt;/p&gt;
&lt;p&gt;As my company moved to the cloud, we stopped using Shoelaces in favor of other technologies. Server bootstrapping was replaced with API calls, autoscaling groups, etc. My software fulfilled its task and metaphorically sank with the data center we left behind. However, Shoelaces kept receiving an occasional pull request or bug report, and a small user base started growing. When time allowed, I would spend some cycles applying patches, updating minor dependencies and doing general maintenance.&lt;/p&gt;
&lt;p&gt;A task that is slightly more involved is to upgrade dependencies to new &lt;a href=&#34;https://en.wikipedia.org/wiki/Software_versioning#Semantic_versioning&#34;&gt;major versions&lt;/a&gt;. It’s normally not difficult, but it’s repetitive and cumbersome. The advent of LLMs makes these chores more straightforward: a simple prompt can go through a changelog and refactor all code to conform with the new version. In most circumstances, this is good and is the desired outcome. However, simply updating dependencies means that in a few months, or even days, they will be outdated again. Like Sisyphus in the Greek myth, the operator will be condemned to push a boulder up a hill, only for it to roll back down with the next vulnerability disclosure.&lt;/p&gt;
&lt;!-- Automating this pipeline is paramount to be ahead of the flood of zero day vulnerabilities discovered by models such as [Claude Mythos](https://tech-insider.org/anthropic-claude-mythos-zero-day-project-glasswing-2026/), especially because exploits can be produced at an [alarming rate](https://zerodayclock.com/). --&gt;
&lt;p&gt;I want to point out an alternative to constant patching: prune out unnecessary bloat. Revisit dependencies to understand what is mandatory, and what’s there to make developers’ lives slightly simpler in the short term, at the expense of maintenance toil in the long term. Shoelaces is a small piece of software, and most of its dependencies were used minimally. The backend dependencies included libraries for HTTP routing, middleware chaining, configuration from command-line flags and structured logging. The frontend dependencies included Bootstrap CSS/JS for navbar, grids, and other elements. Bootstrap bundled legacy icon fonts, but there were no first-party references, so they were effectively unused. jQuery was used for AJAX requests, DOM manipulation, event handlers, and fade effects. All in all, these dependencies are nice to have, but they’re not mandatory. I’m neither actively maintaining Shoelaces nor developing new features for it, so the best use of my time is to prepare it for the software afterlife by trimming out anything that’s not compulsory.&lt;/p&gt;
&lt;p&gt;I released a &lt;a href=&#34;https://github.com/thousandeyes/shoelaces&#34;&gt;new minor version of Shoelaces&lt;/a&gt; with that vision in mind. In the backend, &lt;a href=&#34;https://github.com/thousandeyes/shoelaces/blob/master/CHANGELOG.md?plain=1#L19-L20&#34;&gt;most Go dependencies&lt;/a&gt; were decommissioned in favor of standard library implementations (the standard library now includes many features that were not present in the previous version of Shoelaces), along with small, focused implementations developed with LLM assistance. I used LLM assistance here in a bounded way: not to introduce new abstractions, but to replace small, well-understood dependency usages with local code that could be reviewed directly. In the frontend, &lt;a href=&#34;https://github.com/thousandeyes/shoelaces/blob/master/CHANGELOG.md?plain=1#L23-L24&#34;&gt;JavaScript and CSS code was replaced&lt;/a&gt; with local implementations that now leverage the browser DOM APIs. The interface looks slightly less polished, but the trade-off was well worth making. In this release, the Go dependency set went from 10 module entries to 1, while roughly 800 KB of vendored Bootstrap, jQuery, and font assets were replaced with about 15 KB of local CSS and JavaScript. This simplification also has consequences beyond the Shoelaces tree itself. A &lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1140456&#34;&gt;few&lt;/a&gt; &lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1140457&#34;&gt;dependencies&lt;/a&gt; that had been packaged exclusively for Shoelaces can now be dropped from the Debian archive, reducing not only the application’s dependency graph but also the maintenance surface around it.&lt;/p&gt;
&lt;p&gt;Dependencies can be a liability. They might save a few hours of coding in the short term at the expense of Sisyphean patching sessions in the long run. With LLMs, implementing small features normally covered by dependencies is much cheaper. However, I’m not suggesting to reinvent the wheel for every piece of software because that has its own risks as well: more code to maintain and, of course, a larger attack surface. While Antoine de Saint-Exupéry was writing about airplanes when describing his concept of perfection, his words fit the software industry perfectly. Software can gain longevity not through new features, but by reducing the amount of code, process, and external trust it asks future maintainers to carry.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Org Tempus</title>
      <link>https://rbenencia.name/blog/2026-06-01-org-tempus/</link>
      <pubDate>Mon, 01 Jun 2026 08:23:41 -0300</pubDate>
      <guid>https://rbenencia.name/blog/2026-06-01-org-tempus/</guid>
      <description>&lt;p&gt;Time management is a tricky business. Ideally we should spend our precious time in Earth doing things that we’re interested in for as long as we want. Unfortunately that’s not how the life of a modern human works. We have responsibilities, chores, busy work, etc. We have activities that we enjoy doing, and tasks that we have to get over, and ideally we should make progress in all of them. We’re in a constant state of context switching. Additionally, we need to take regular breaks to ensure our brain is not overly engaged.&lt;/p&gt;
&lt;p&gt;As an Emacser, I’m an avid user of &lt;a href=&#34;https://orgmode.org/&#34;&gt;Org Mode&lt;/a&gt;. I find it essential to keep track of my perennial list of tasks, both personal and at work. Org has a handy &lt;a href=&#34;https://orgmode.org/manual/Clocking-Work-Time.html&#34;&gt;clocking feature&lt;/a&gt; that allows you to track the time you spent on each task. This feature is essential to ensure I don’t overwork, or underwork, in any of my responsibilities. However, it’s a bit of a hassle to clock in and clock out all the time, particularly if you take regular breaks.&lt;/p&gt;
&lt;p&gt;Enter &lt;a href=&#34;https://github.com/rul/org-tempus&#34;&gt;Org Tempus&lt;/a&gt;, an Emacs package I’ve written on top of Org Mode to automate many parts of my workflow. In particular, Org Tempus allows setting up a default task to auto clock-in when activity is detected in the workstation. This default task is how I track administrative work: catching up with emails, messages, and capturing new work items. How “activity” is detected is configurable and extendable: it can be activity coming from Emacs itself, or activity coming from a desktop environment such as GNOME. The package also permits setting intervals for breaks (similar to the Pomodoro technique) and total worked time, and sends notifications when the thresholds are reached.&lt;/p&gt;
&lt;p&gt;Overall, Org Tempus has enabled me to be more intentional with how I spend my computing time. Check the &lt;a href=&#34;https://github.com/rul/org-tempus/blob/main/README.md&#34;&gt;README&lt;/a&gt; for the full list of features. I’ve just released &lt;a href=&#34;https://github.com/rul/org-tempus/releases/tag/0.0.2&#34;&gt;version 0.0.2&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Emacs server, systemd and XAUTHORITY</title>
      <link>https://rbenencia.name/blog/emacs-daemon-as-a-systemd-service/</link>
      <pubDate>Tue, 30 May 2023 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/emacs-daemon-as-a-systemd-service/</guid>
      <description>&lt;p&gt;Running Emacs as a systemd service should be relatively straightforward
if using its Debian package, given that it comes with a systemd
unit.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a fragment:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ cat /usr/lib/systemd/user/emacs.service | head -n7
[Unit]
Description=Emacs text editor
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/

[Service]
Type=notify
ExecStart=/usr/bin/emacs --fg-daemon
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;However, I&amp;rsquo;ve faced the following problem: when running &lt;code&gt;emacsclient&lt;/code&gt;
from a graphical interface, nothing happened, and it was not clear
what to do next.&lt;/p&gt;
&lt;p&gt;To unravel these kind of problems, we should always start by checking
the logs. An interesting line showed up:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ journalctl  --user -u emacs.service
...
May 18 16:51:51 zorzal emacs[1308]: Authorization required, but no authorization protocol specified
...
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After some digging, I realized this happens because the Emacs server
was started before the &lt;code&gt;XAUTHORITY&lt;/code&gt; variable was set, and &lt;a href=&#34;https://en.wikipedia.org/wiki/X_Window_authorization&#34;&gt;we need
that variable&lt;/a&gt;
to communicate with the display server.&lt;/p&gt;
&lt;p&gt;A quick search didn&amp;rsquo;t show a straightforward or clean
solution. Remediating this problem should be relatively simple: we
just need to instruct systemd to start the Emacs server &lt;em&gt;after&lt;/em&gt; the
graphical session.  systemd &lt;a href=&#34;https://www.freedesktop.org/software/systemd/man/systemd.special.html#graphical-session.target&#34;&gt;comes
preloaded&lt;/a&gt;
with a special &lt;code&gt;target&lt;/code&gt; that can be used for this purpose:
&lt;code&gt;graphical-session.target&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A &lt;a href=&#34;https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Description&#34;&gt;systemd
drop-in&lt;/a&gt;
file can be used to establish this dependency:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ cat ~/.config/systemd/user/emacs.service.d/override.conf
[Unit]
Requires=graphical-session.target
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To pick-up the override, we must remember to run: &lt;code&gt;systemd --user daemon-reload&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Why isn&amp;rsquo;t this a default in the shipped unit file? I suppose we can&amp;rsquo;t
assume the user will always have a graphical session when launching
an Emacs server, so it wouldn&amp;rsquo;t be safe to make it a default.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Debian contributions — October 2021</title>
      <link>https://rbenencia.name/blog/2021-10-10-debian-contributions/</link>
      <pubDate>Sun, 10 Oct 2021 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2021-10-10-debian-contributions/</guid>
      <description>&lt;p&gt;Greetings, and welcome to another round of Debian contributions.&lt;/p&gt;
&lt;h3 id=&#34;fortunes-it&#34;&gt;fortunes-it&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Prepared NMU that fixes the following typo bugs:
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=787140&#34;&gt;#787140&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=788097&#34;&gt;#788097&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=792271&#34;&gt;#792271&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=833062&#34;&gt;#833062&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;devscripts&#34;&gt;devscripts&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Reported
&lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=996392&#34;&gt;#996392&lt;/a&gt;. The
bug describes
a typo in &amp;ldquo;nmudiff&amp;rdquo; manpage. Included a patch.&lt;/li&gt;
&lt;li&gt;Reported
&lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=996565&#34;&gt;#996565&lt;/a&gt;. The
bug describes a misleading situation with the delay header when
&lt;code&gt;nmudiff&lt;/code&gt; is run by a non-DD. Included a patch.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;foremost&#34;&gt;foremost&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;http://foremost.sourceforge.net/&#34;&gt;Foremost&lt;/a&gt; is a program to recover
files based on their headers, footers, and internal data structures.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Closed
&lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=912365&#34;&gt;#912365&lt;/a&gt;. The
bug was tagged &amp;ldquo;moreinfo&amp;rdquo; for more than a year, no info has been
provided and it seems unreproducible.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;rotix&#34;&gt;rotix&lt;/h3&gt;
&lt;p&gt;The &amp;ldquo;rotix&amp;rdquo; package allows you to generate rotational obfuscations,
like the world-famous ROT-13.&lt;/p&gt;
&lt;p&gt;In this batch of contributions, I&amp;rsquo;ve:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://salsa.debian.org/rul/rotix/-/commit/38db68847a2cd43c9d3be76b9b681e1063d7f3c8&#34;&gt;Revamped and
modernized&lt;/a&gt;
the packaging.&lt;/li&gt;
&lt;li&gt;Fixed the NL translation and
&lt;a href=&#34;https://github.com/shemminga/rotix/pull/2&#34;&gt;submitted&lt;/a&gt; the patch to upstream.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;misc&#34;&gt;Misc&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Updated my &lt;a href=&#34;https://wiki.debian.org/Ra%C3%BAlBenencia&#34;&gt;Debian wiki profile&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Added myself to the &lt;a href=&#34;https://wiki.debian.org/LowThresholdNmu&#34;&gt;low threshold NMU&lt;/a&gt; list.&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>Debian contributions — September 2021</title>
      <link>https://rbenencia.name/blog/2021-09-29-debian-contributions/</link>
      <pubDate>Wed, 29 Sep 2021 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2021-09-29-debian-contributions/</guid>
      <description>&lt;p&gt;Greetings from San Francisco, and welcome to another round of Debian
contribution logs. Days are getting darker and shorter as summer
breezes out unamusingly. Perhaps it was not my coldest winter, but
it was chilly anyway.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&#34;https://rbenencia.name/img/bay_bridge.jpg&#34; alt=&#34;San Francisco&#39;s Bay Bridge&#34;&gt;
  &lt;figcaption&gt;San Francisco&#39;s Bay Bridge&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h3 id=&#34;shoelaces&#34;&gt;Shoelaces&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://rbenencia.name/blog/2018-05-20-shoelaces/&#34;&gt;Shoelaces&lt;/a&gt; is a
tool for automating servers bootstrapping. I gave a talk about it on
&lt;a href=&#34;https://rbenencia.name/blog/2019-07-30-debconf-19/&#34;&gt;DebConf 19&lt;/a&gt;. On
these contributions batch, I&amp;rsquo;ve:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Uploaded golang-github-namsral-flag version
1.7.4~alpha+git20170814.67f268f2-2 and golang-github-justinas-alice
version 1.2.0-1. These packages are Shoelaces&amp;rsquo;s dependencies. I&amp;rsquo;ve
prepared their release the &lt;a href=&#34;https://rbenencia.name/blog/2021-04-29-debian-contributions/&#34;&gt;month
before&lt;/a&gt;,
but didn&amp;rsquo;t have write permissions on their git repo. &lt;a href=&#34;https://lists.debian.org/debian-go/2021/04/msg00058.html&#34;&gt;Tina kindly
gave them to
me&lt;/a&gt;. Thank
you!&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;prometheus-nginx-vts-exporter&#34;&gt;Prometheus Nginx VTS exporter&lt;/h3&gt;
&lt;p&gt;The prometheus-nginx-vts-exporter package is a Prometheus exporter for
Nginx VTS metrics.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Shortly after I created this package for Debian, &lt;a href=&#34;https://github.com/vozlt/nginx-module-vts/commit/0d09d52531ac37d2ff7a491d181063cdb8dd7856&#34;&gt;support was
added&lt;/a&gt;
for exporting Prometheus metrics directly from the plugin
itself. Consequently, upstream &lt;a href=&#34;https://github.com/hnlq715/nginx-vts-exporter/commit/9321e9ffa16a09f1a706a5577e84397ba6abb911&#34;&gt;decided to
stop&lt;/a&gt; the development of this exporter. Being no longer useful to have
this package on Debian, I filed a &lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=988002&#34;&gt;removal
request&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;emacs-theme--zenburn&#34;&gt;Emacs theme — Zenburn&lt;/h3&gt;
&lt;p&gt;This package provides a low contrast color theme for Emacs. Zenburn is
designed to minimise eye strain during long periods of work.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;After reviewing the current packaging situation, I &lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=978656#10&#34;&gt;expressed my
intent&lt;/a&gt;
to adopt zenburn-emacs.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I&amp;rsquo;ve
&lt;a href=&#34;https://salsa.debian.org/emacsen-team/zenburn-emacs/-/merge_requests/1&#34;&gt;prepared&lt;/a&gt;
a new upstream release and brushed up its packaging. Then, I&amp;rsquo;ve
&lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=978656#19&#34;&gt;requested&lt;/a&gt;
sponsorship. &lt;a href=&#34;https://spwhitton.name/&#34;&gt;Sean Whitton&lt;/a&gt; kindly uploaded
it for me.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=988297&#34;&gt;#988297&lt;/a&gt;
was opened, in what must be the highest record between adopting a
package and getting a bug reported on it. I&amp;rsquo;ve
&lt;a href=&#34;https://salsa.debian.org/emacsen-team/zenburn-emacs/-/commit/b6aae5d7d18aa4088803c998d11dcfcfef90f4ad&#34;&gt;prepared&lt;/a&gt;
a fix release.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;emacs-theme--clues&#34;&gt;Emacs theme — Clues&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&#34;https://tracker.debian.org/pkg/clues-emacs&#34;&gt;clues-emacs&lt;/a&gt; package
provides a theme for Emacs. I adopted it during &lt;a href=&#34;https://rbenencia.name/blog/2019-07-30-debconf-19/&#34;&gt;DebConf
19&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://salsa.debian.org/rul/themole/-/tree/debian/0.3-3&#34;&gt;Updated&lt;/a&gt;
VCS to include a non-maintainer upload.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;the-mole&#34;&gt;The Mole&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://sourceforge.net/projects/themole/&#34;&gt;The Mole&lt;/a&gt; is an automatic
SQL Injection exploitation tool.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://salsa.debian.org/rul/themole/-/tree/debian/0.3-3&#34;&gt;Updated&lt;/a&gt;
VCS to include a non-maintainer upload.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;foremost&#34;&gt;Foremost&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;http://foremost.sourceforge.net/&#34;&gt;Foremost&lt;/a&gt; is a program to recover
files based on their headers, footers, and internal data structures.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://salsa.debian.org/rul/foremost/-/tree/debian/1.5.7-11&#34;&gt;Uploaded&lt;/a&gt;
foremost version 1.5.7-11, which includes a rediff of its patches to
use &lt;code&gt;gbp pq&lt;/code&gt; and a fix to bug
&lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=994067&#34;&gt;#994067&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>Debian contributions — April 2021</title>
      <link>https://rbenencia.name/blog/2021-04-29-debian-contributions/</link>
      <pubDate>Thu, 29 Apr 2021 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2021-04-29-debian-contributions/</guid>
      <description>&lt;p&gt;Greetings from a windy San Francisco. This blog is a bit quiet; let&amp;rsquo;s
fix that. I will start making some noise by sharing my contributions to the Debian
project.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&#34;https://rbenencia.name/img/dolores_sanfrancisco.jpg&#34; alt=&#34;San Francisco downtown&#34;&gt;
  &lt;figcaption&gt;A view of San Francisco downtown, from Dolores Park.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h3 id=&#34;debsources&#34;&gt;Debsources&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://salsa.debian.org/qa/debsources&#34;&gt;Debsources&lt;/a&gt; is the software
behind &lt;a href=&#34;https://sources.debian.org/&#34;&gt;sources.debian.org&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;2021-03-26:
&lt;a href=&#34;https://salsa.debian.org/qa/debsources/-/merge_requests/1&#34;&gt;Fixed&lt;/a&gt;
Docker build and updated HACKING instructions for running the Docker
environment; I wanted to give a shot to the bugs tagged &lt;code&gt;newcomer&lt;/code&gt;,
but the first challenge I found was that — on &lt;code&gt;master&lt;/code&gt; — the
Docker-build instructions were not working. This contribution fixed
that. After submitting it, though, I was made aware that the Docker
build was already fixed on another branch.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;2021-03-27:
&lt;a href=&#34;https://salsa.debian.org/qa/debsources/-/merge_requests/2&#34;&gt;Fixed&lt;/a&gt;
Flake8 E741: A simple contribution to get familiar with the
debsources code base. This contribution was put on hold. We decided
to wait until the current effort for migrating from Python 2 to
Python 3 is finished.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;2021-03-28: &lt;a href=&#34;https://salsa.debian.org/qa/debsources/-/merge_requests/3&#34;&gt;Fixed&lt;/a&gt; &lt;code&gt;test_news&lt;/code&gt; test. I faced several issues with this
test, so I fixed them.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;2021-04-06:
&lt;a href=&#34;https://salsa.debian.org/qa/debsources/-/merge_requests/4&#34;&gt;Added&lt;/a&gt;
CI. Debsources used to have a Travis CI but it stopped working at
some point. This merge request started the discussion for using
Salsa CI.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;2021-04-09:
&lt;a href=&#34;https://salsa.debian.org/qa/debsources/-/merge_requests/4/diffs?diff_id=67300&amp;amp;start_sha=6792d804bb72b3fd2a735cb172a012a73d7bf64b&#34;&gt;Enhanced&lt;/a&gt;
Docker-build&amp;rsquo;s Makefile, as it was not using the same targets than
the main Makefile. This patch fixed that situation, making it
consistent.&lt;/p&gt;
&lt;p&gt;This contribution was part of the same merge request I started on
2021-04-06.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;2021-04-17:
&lt;a href=&#34;https://salsa.debian.org/qa/debsources/-/merge_requests/4/diffs?diff_id=68204&amp;amp;start_sha=42f6dd9e92518e4a26b3d6ecbba9d2680e970f0f&#34;&gt;Fixed&lt;/a&gt;
&lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=783832&#34;&gt;#783832&lt;/a&gt;. This
bug was opened about six years ago to track tests that were failing
to run on a CI (Travis, on those remote times). I&amp;rsquo;ve successfully
ran all tests with Salsa CI, so this bug was finally closed.&lt;/p&gt;
&lt;p&gt;This contribution was part of the same merge request I started on
2021-04-06.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Kudos to &lt;a href=&#34;https://matthieu.io/&#34;&gt;Matthieu Caneill&lt;/a&gt; for patiently
sponsoring these contributions. Thank you!&lt;/p&gt;
&lt;h3 id=&#34;carnivore&#34;&gt;Carnivore&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&#34;https://salsa.debian.org/qa/qa/-/tree/master/carnivore&#34;&gt;Carnivore
project&lt;/a&gt; —
maintained by the QA team — is a database that plenty of Debian
services use under the hood. From its README:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Goal is to reliably correlate identities with each other, that is, alternative
email addresses, and the like, for the purpose of having all sorts of QA
scripts, including DDPO, MIA, lintian, etc. etc. be able to show data grouped by
maintainer, even though a single maintainer might be using multiple different
email addresses.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I wanted to tackle some its
&lt;a href=&#34;https://bugs.debian.org/cgi-bin/pkgreport.cgi?package=qa.debian.org#_0_0_4&#34;&gt;bugs&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;2021-04-01: My first conclusion after analyzing the code base was
that a small change will have big impact, so testing was
paramount. The project does not describe how to do local testing,
and I suspect there&amp;rsquo;s no direct way of doing so. &lt;a href=&#34;https://salsa.debian.org/qa/qa/-/merge_requests/33&#34;&gt;This
contribution&lt;/a&gt;
adds a Docker test environment to ease local testing.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I&amp;rsquo;m still looking for someone to sponsor this contribution&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;2021-04-03: carnivore gathers the name for a given identity from
packages — using &lt;code&gt;Maintainer&lt;/code&gt; and &lt;code&gt;Uploaders&lt;/code&gt; field —, from GPG keys
on the Debian keyrings, and from LDAP (DDs only). Some identities
will have multiple names associated. Sometimes, this behavior is
unwanted:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://bugs.debian.org/963210&#34;&gt;#963210&lt;/a&gt; — carnivore: DDPO still
using old name&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=694081&#34;&gt;#694081&lt;/a&gt;
— carnivore: should not import name from revoked gpg key&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&#34;https://salsa.debian.org/qa/qa/-/merge_requests/34&#34;&gt;This
contribution&lt;/a&gt;
allows setting a preferred name for a given identity.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I&amp;rsquo;m still looking for someone to sponsor this contribution&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;emacs-theme--clues&#34;&gt;Emacs theme — Clues&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&#34;https://tracker.debian.org/pkg/clues-emacs&#34;&gt;clues-emacs&lt;/a&gt; package
provides a theme for Emacs. I adopted it during &lt;a href=&#34;https://rbenencia.name/blog/2019-07-30-debconf-19/&#34;&gt;DebConf
19&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;2021-04-07:
&lt;a href=&#34;https://salsa.debian.org/rul/clues-emacs/-/commit/a27910d4f3d175189f9c1a44db7f4e7ccacd8b39&#34;&gt;Commited&lt;/a&gt;
an NMU patch to the VCS.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;2021-04-12:
&lt;a href=&#34;https://salsa.debian.org/rul/clues-emacs/-/commit/70812af7f49b71da8602c6f1f0ace3f8748e54ce&#34;&gt;Prepared&lt;/a&gt;
version 1.0.1-3. This version updates the packaging and adds CI. I
was still missing DM upload permissions and
&lt;a href=&#34;https://wiki.debian.org/Josue%20Ortega&#34;&gt;Josue&lt;/a&gt; kindly gave them to
me. Thank you!&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;shoelaces&#34;&gt;Shoelaces&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://rbenencia.name/blog/2018-05-20-shoelaces/&#34;&gt;Shoelaces&lt;/a&gt; is a
tool for automating servers bootstrapping. I gave a talk about it on
&lt;a href=&#34;https://rbenencia.name/blog/2019-07-30-debconf-19/&#34;&gt;DebConf 19&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;2021-04-10:
&lt;a href=&#34;https://salsa.debian.org/rul/shoelaces/-/tree/debian/1.2.0&amp;#43;ds-1&#34;&gt;Uploaded&lt;/a&gt;
version shoelaces_1.2.0+ds-1. This version packages a new upstream
release, and also updates the packaging in general.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;2021-04-18:
&lt;a href=&#34;https://salsa.debian.org/go-team/packages/golang-github-namsral-flag/-/merge_requests/2/commits&#34;&gt;Prepared&lt;/a&gt;
golang-github-namsral-flag version
1.7.4~alpha+git20170814.67f268f2-2. This package is a shoelaces
dependency.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;2021-04-20:
&lt;a href=&#34;https://salsa.debian.org/go-team/packages/golang-github-justinas-alice/-/merge_requests/3&#34;&gt;Prepared&lt;/a&gt;
golang-github-justinas-alice version 1.2.0-1. This package is a
shoelaces dependency.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;the-mole&#34;&gt;The Mole&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://sourceforge.net/projects/themole/&#34;&gt;The Mole&lt;/a&gt; is an automatic
SQL Injection exploitation tool.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;2021-04-11:
&lt;a href=&#34;https://salsa.debian.org/rul/themole/-/tree/debian/0.3-3&#34;&gt;Uploaded&lt;/a&gt;
version 0.3-3. This version updates the packaging and adds CI.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;foremost&#34;&gt;Foremost&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;http://foremost.sourceforge.net/&#34;&gt;Foremost&lt;/a&gt; is a program to recover
files based on their headers, footers, and internal data structures.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;2021-04-16:
&lt;a href=&#34;https://salsa.debian.org/rul/foremost/-/tree/debian/1.5.7-10&#34;&gt;Uploaded&lt;/a&gt;
foremost version 1.5.7-10. I&amp;rsquo;ve updated the packaging, added CI and
fixed a FTBFS on the way. I&amp;rsquo;ve also attended to a long-standing
merge request from the Ubuntu team, and updated their &lt;a href=&#34;https://bugs.launchpad.net/ubuntu/&amp;#43;source/foremost/&amp;#43;bug/690392&#34;&gt;bug
report&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;</description>
    </item>
    
    <item>
      <title>DebConf 19</title>
      <link>https://rbenencia.name/blog/2019-07-30-debconf-19/</link>
      <pubDate>Tue, 30 Jul 2019 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2019-07-30-debconf-19/</guid>
      <description>&lt;p&gt;After many years of virtually assisting
&lt;a href=&#34;https://www.debconf.org/&#34;&gt;DebConf&lt;/a&gt; — the annual Debian
conference — I&amp;rsquo;ve finally had the opportunity of going and enjoying
it in-person. This year it was held in &lt;a href=&#34;https://debconf19.debconf.org/&#34;&gt;Curitiba, Brasil&lt;/a&gt;.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&#34;https://rbenencia.name/img/parque_tangua.jpg&#34; alt=&#34;Parque Tanguá, Curitiba&#34;&gt;
  &lt;figcaption&gt;Parque Tanguá, Curitiba.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;It was a unique experience; not only did I get to put a face to the
names and nicks — and nicks and names to many new faces — I also &lt;a href=&#34;https://meetings-archive.debian.net/pub/debian-meetings/2019/DebConf19/shoelaces-painless-server-bootstrapping.webm&#34;&gt;got to
present
Shoelaces&lt;/a&gt;
to the wider Debian community.&lt;/p&gt;
&lt;p&gt;As I mentioned in the talk, I wanted the talk to spark some interest
on any DD that was willing to sponsor the Shoelaces package into the
Debian archive, but I was lucky enough to get it even before the
talk. Thank you, Dererk! It&amp;rsquo;s official, &lt;a href=&#34;https://tracker.debian.org/pkg/shoelaces&#34;&gt;Shoelaces is available on
Debian&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Kudos to the DebConf Video Team for doing an amazing job with the
recording, and to the DebConf Team in general for having organized
such a wonderful event. Overall, I&amp;rsquo;m quite happy with the experience
and would definitely do it again.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Kafka Topics: Pitfalls and Insights</title>
      <link>https://rbenencia.name/blog/2019-03-30-kafka-topics/</link>
      <pubDate>Sat, 30 Mar 2019 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2019-03-30-kafka-topics/</guid>
      <description>&lt;p&gt;A few weeks ago I published an article on ThousandEyes&amp;rsquo; blog
describing my experiences with Kafka Topics.&lt;/p&gt;
&lt;p&gt;Do &lt;a href=&#34;https://medium.com/thousandeyes-engineering/kafka-topics-pitfalls-and-insights-38bafc791a83&#34;&gt;check it
out&lt;/a&gt;
if you&amp;rsquo;re interested.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Debian Maintainer</title>
      <link>https://rbenencia.name/blog/2018-07-25-debian-maintainer/</link>
      <pubDate>Wed, 25 Jul 2018 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2018-07-25-debian-maintainer/</guid>
      <description>&lt;p&gt;As of yesterday, I&amp;rsquo;ve been bestowed the title of &lt;a href=&#34;https://wiki.debian.org/DebianMaintainer&#34;&gt;Debian
Maintainer&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Those who know me knows how much I admire the Debian project, so it&amp;rsquo;s
truly an honor to get this recognition and be able to keep giving back
to the community in a more autonomous way.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;d like to thank Lisandro for
&lt;a href=&#34;https://nm.debian.org/process/516/advocate/&#34;&gt;advocating&lt;/a&gt; this
process.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Shoelaces</title>
      <link>https://rbenencia.name/blog/2018-05-20-shoelaces/</link>
      <pubDate>Sun, 20 May 2018 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2018-05-20-shoelaces/</guid>
      <description>&lt;p&gt;Some days ago I announced the release of
&lt;a href=&#34;https://github.com/thousandeyes/shoelaces&#34;&gt;Shoelaces&lt;/a&gt;, a tool for
automating servers bootstrapping. It&amp;rsquo;s particularly useful on
on-premise data centers environments.&lt;/p&gt;
&lt;p&gt;Check the &lt;a href=&#34;https://medium.com/thousandeyes-engineering/open-sourcing-shoelaces-a-tool-for-unmanned-server-bootstrapping-e7b493ee0b14&#34;&gt;original blog
post&lt;/a&gt;
for more details.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>LibrePlanet 2018</title>
      <link>https://rbenencia.name/blog/2018-03-23-libreplanet-2018/</link>
      <pubDate>Fri, 23 Mar 2018 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2018-03-23-libreplanet-2018/</guid>
      <description>&lt;p&gt;This year I was fortunate enough to be able to travel to Boston,
Massachusetts, to the annual &lt;a href=&#34;https://www.libreplanet.org/2018/&#34;&gt;Libreplanet&lt;/a&gt;
conference.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s been a long trip from San Francisco, I didn&amp;rsquo;t get a lot sleep,
but all the sleepiness went away during my first impressions of the city. See,
it doesn&amp;rsquo;t snow in the city where I&amp;rsquo;m originally from, so seeing the snow
piled-up next to the side-walk has certain charm that I like.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&#34;https://rbenencia.name/img/boston_bridge.jpg&#34; alt=&#34;Boston University Bridge&#34;&gt;
  &lt;figcaption&gt;Boston University Bridge&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
  &lt;img src=&#34;https://rbenencia.name/img/boston_awaking.jpg&#34; alt=&#34;Boston awaking&#34;&gt;
  &lt;figcaption&gt;Next to the Charles River, Boston is awakening&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Anyway, if you are around at the conference, come, chat, exchange GPG
keys!  Today I&amp;rsquo;ll be going to
&lt;a href=&#34;http://www.eximiousproductions.com/2018/03/09/spinachcon-2018/&#34;&gt;SpinachCon&lt;/a&gt;
and later in the day to the FSF Open House.&lt;/p&gt;
&lt;p&gt;See you around!&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Using notmuch-emacs along with other folder-based MUA</title>
      <link>https://rbenencia.name/blog/2015-06-24-notmuch-imap-sync/</link>
      <pubDate>Wed, 24 Jun 2015 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2015-06-24-notmuch-imap-sync/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve started to leave my &lt;em&gt;mutt&lt;/em&gt; niche in order to start using
&lt;em&gt;notmuch-emacs&lt;/em&gt; MUA. All in all, I can see the see the speed advantage
of using &lt;em&gt;notmuch&lt;/em&gt;, among other little perks. Nevertheless, the
approach of tagging emails instead of organizing them in IMAP folders
makes the use of &lt;em&gt;notmuch&lt;/em&gt; a little non-portable for others folder
based user agents. I wouldn&amp;rsquo;t mind that, but I like receiving my
emails on my mobile phone and as far as I know there is no such thing
as a mobile &lt;em&gt;notmuch&lt;/em&gt; MUA.&lt;/p&gt;
&lt;p&gt;In this blog post I&amp;rsquo;ll share my approach for using a &lt;em&gt;notmuch&lt;/em&gt; based agent,
as &lt;em&gt;notmuch-emacs&lt;/em&gt;, along with other folder based agents, as &lt;em&gt;Thunderbird&lt;/em&gt;
or &lt;em&gt;K-9 Mail&lt;/em&gt;. The first thing to do is to define the layout of our IMAP
folders. In our examples we&amp;rsquo;ll use something like this:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ ls -1 ~/Maildir
archive
cur
debian
debian.devel
debian.haskell
debian.haskell.commits
debian.haskell.maintainers
debian.haskell.maintainers.junk
debian.misc
debian.project
new
tmp
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So, here I have my &lt;strong&gt;inbox&lt;/strong&gt; folder along with an &lt;strong&gt;archive&lt;/strong&gt; maildir and a
hierarchy of folders containing Debian mailing lists. In my folder based
mobile agent, K-9, I won&amp;rsquo;t be bothered with notifications of new mailing
list emails, as the agent is configured to only check for new emails in the
&lt;strong&gt;inbox&lt;/strong&gt; folder. On the other hand, in a default &lt;em&gt;notmuch&lt;/em&gt; setup each time
I run &lt;code&gt;notmuch new&lt;/code&gt; the database will be filled with all the emails in all
the folders and will tag the new ones with &lt;code&gt;inbox&lt;/code&gt;. Now, when I&amp;rsquo;m using
&lt;em&gt;notmuch-emacs&lt;/em&gt;, I like that my &lt;code&gt;inbox&lt;/code&gt; emails be only the ones in my
&lt;strong&gt;inbox&lt;/strong&gt; folder. Besides, I&amp;rsquo;ll also like to add a tag that matches the
name of the folder the email is in. In &lt;em&gt;notmuch&lt;/em&gt; language:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#!/bin/sh
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;notmuch new
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;notmuch tag +archive -inbox &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;path:archive/**&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;notmuch tag +debian -inbox &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;path:debian/**&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;notmuch tag +debian-devel -inbox &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;path:debian.devel/**&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;notmuch tag +debian-project -inbox &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;path:debian.project/**&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;notmuch tag +debian-haskell -inbox &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;path:debian.haskell/**&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;notmuch tag +debian-haskell-commits -inbox &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;path:debian.haskell.commits/**&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;notmuch tag +debian-haskell-maintainers -inbox &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;path:debian.haskell.maintainers/**&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;notmuch tag +debian-haskell-maintainers-junk -inbox -unread &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;path:debian.haskell.maintainers.junk/**&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;notmuch tag +debian-misc -inbox &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;path:debian.misc/**&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;With this method we can use a folder based approach with &lt;em&gt;notmuch&lt;/em&gt;
tags. Let&amp;rsquo;s move to another topic. In the &lt;em&gt;notmuch&lt;/em&gt; world, archiving an
email means removing the &lt;code&gt;inbox&lt;/code&gt; tag. If we only do this, all the archived
emails will still be in our &lt;strong&gt;inbox&lt;/strong&gt; folder, so what we&amp;rsquo;ll like to do is
to move &lt;em&gt;to&lt;/em&gt; the &lt;strong&gt;archive&lt;/strong&gt; folder all the emails &lt;em&gt;from&lt;/em&gt; the &lt;strong&gt;inbox&lt;/strong&gt;
folder that don&amp;rsquo;t have the &lt;code&gt;inbox&lt;/code&gt; tag. In other words:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;function&lt;/span&gt; archive&lt;span style=&#34;color:#f92672&#34;&gt;()&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; $# -ne &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       echo &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Incorrent parameters. Send INBOX and ARCHIVE&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; e in &lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;notmuch search --output&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;files &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;path:&lt;/span&gt;$1&lt;span style=&#34;color:#e6db74&#34;&gt;/**&amp;#34;&lt;/span&gt; and not tag:inbox&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        mv $e $2
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;done&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;archive cur &lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;MAILDIR&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;/archive/cur
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, one little detail is left: &lt;em&gt;spam&lt;/em&gt;. In a folder based agent, we&amp;rsquo;ll
usually have a &lt;strong&gt;spam&lt;/strong&gt; folder. In the &lt;em&gt;notmuch&lt;/em&gt; world, when we tag an
email with &lt;code&gt;spam&lt;/code&gt;, a decent client won&amp;rsquo;t show it in the results of
&lt;em&gt;notmuch&lt;/em&gt; searches, but it will remain in the folder it was found. So, what
we have to do is to move all the &lt;code&gt;spam&lt;/code&gt; tagged email to our &lt;strong&gt;spam&lt;/strong&gt;
folder.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; e in &lt;span style=&#34;color:#66d9ef&#34;&gt;$(&lt;/span&gt;notmuch search --output&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;files tag:spam and not &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;path:spam/**&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;)&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    mv $e $MAILDIR/spam/cur
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;done&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So, if we cron this little script we&amp;rsquo;ll be able to use a &lt;em&gt;notmuch&lt;/em&gt; based
MUA along with an IMAP folder based one. Enjoy!&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Chess and C, day 3</title>
      <link>https://rbenencia.name/blog/2015-04-01-chess-3/</link>
      <pubDate>Wed, 01 Apr 2015 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2015-04-01-chess-3/</guid>
      <description>&lt;p&gt;Finally, after setting the skeleton of the game on
&lt;a href=&#34;https://rbenencia.name/blog/2015-03-27-chess-1/&#34;&gt;day 1&lt;/a&gt; and
&lt;a href=&#34;https://rbenencia.name/blog/2015-03-28-chess-2/&#34;&gt;day 2&lt;/a&gt;, I&amp;rsquo;ve managed to get a chess board
where you can actually &lt;em&gt;play&lt;/em&gt;. Of course, it&amp;rsquo;s quite rudimentary and you&amp;rsquo;ll
have to input the coordinates by typing them, but I think that for the
moment it&amp;rsquo;ll do.&lt;/p&gt;
&lt;p&gt;The first thing to think about is how are we going to represent a movement
in our game. Basically, a movement is a couple of coordinates representing
the origin and destination of a piece. Let&amp;rsquo;s capture that idea in a type.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;typedef&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;struct&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    Coord orig;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    Coord dest;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;} Move;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As you can see, the type is quite simple and will suit perfectly our
needs. Anyway, the type alone won&amp;rsquo;t serve us if we don&amp;rsquo;t have a way of
inputting the movements. How are we going to implement the input system
will depend on the interface we will be using. For the moment our interface
is CLI based, but we should think that in a future we may be able to
implement something using &lt;em&gt;curses&lt;/em&gt; or GTK. For that reason, the input
system should be as detached as possible from the logic of the game. I&amp;rsquo;ve
decided to encapsulate all the input related logic in the function &lt;code&gt;Move input_move()&lt;/code&gt; and a bunch of &lt;code&gt;static&lt;/code&gt; declared sub-functions. The final
result is something similar to the following output.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;White&amp;#39;s turn.
Orig coordinate: e9
Invalid coordinate. Write something like &amp;#34;e2&amp;#34;: e2
Dest coordinate: e4
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;As you may have guessed, this input will move the pawn on square &lt;code&gt;e2&lt;/code&gt; to
&lt;code&gt;e4&lt;/code&gt;. Due to the decoupling of the input system and the logic of the game
it&amp;rsquo;s possible to implement more than one input system without any pain. In
a future, maybe, I&amp;rsquo;ll implement an input system using algebraic
coordinates.&lt;/p&gt;
&lt;p&gt;Now that we have a representation of the movements and a way of input them,
we can start implementing the main game loop. It&amp;rsquo;s implementation is quite
trivial and looks very similar to the following piece of code.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;while&lt;/span&gt; (&lt;span style=&#34;color:#f92672&#34;&gt;!&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;game_is_checkmate&lt;/span&gt;(board, current_player)) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#a6e22e&#34;&gt;print_board&lt;/span&gt;(board, current_player);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        move_valid &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;while&lt;/span&gt; (&lt;span style=&#34;color:#f92672&#34;&gt;!&lt;/span&gt;move_valid) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            m &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;input_move&lt;/span&gt;();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#a6e22e&#34;&gt;game_is_move_valid&lt;/span&gt;(board, current_player, m))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                move_valid &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#a6e22e&#34;&gt;printf&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Invalid move. Please, try again. &amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        board &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;board_make_move&lt;/span&gt;(board, m);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        current_player &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; current_player &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; WHITE &lt;span style=&#34;color:#f92672&#34;&gt;?&lt;/span&gt; BLACK : WHITE;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As you can see, in this implementation the real logic of chess rules lives
in the functions &lt;code&gt;int game_is_checkmate(Board, Color)&lt;/code&gt; and &lt;code&gt;int game_is_move_valid(Board, Color, Move)&lt;/code&gt; which, for the moment, aren&amp;rsquo;t
implemented and always return 0 and 1 respectively.&lt;/p&gt;
&lt;p&gt;Finally, thanks to all the abstraction and modular code we&amp;rsquo;ve written it&amp;rsquo;s
possible to implement a tiny short &lt;code&gt;main()&lt;/code&gt; function like the following one.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#include&lt;/span&gt; &lt;span style=&#34;color:#75715e&#34;&gt;&amp;#34;board.h&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#include&lt;/span&gt; &lt;span style=&#34;color:#75715e&#34;&gt;&amp;#34;game.h&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;int&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#a6e22e&#34;&gt;board_delete&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;game_loop&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;board_init&lt;/span&gt;()));
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And that&amp;rsquo;s it! We have a working interface were we can &lt;em&gt;play&lt;/em&gt;. Here is how
will look the board after a few moves.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  +---|---|---|---|---|---|---|---+
8 | R | N | B | Q | K | B | N | R |
  +---|---|---|---|---|---|---|---+
7 | P | P | P |   | / | P | P | P |
  +---|---|---|---|---|---|---|---+
6 |   | / |   | P |   | / |   | / |
  +---|---|---|---|---|---|---|---+
5 | / |   | / |   | P |   | / |   |
  +---|---|---|---|---|---|---|---+
4 |   | / |   | / | p | / |   | / |
  +---|---|---|---|---|---|---|---+
3 | / |   | / |   | / | n | / |   |
  +---|---|---|---|---|---|---|---+
2 | p | p | p | p |   | p | p | p |
  +---|---|---|---|---|---|---|---+
1 | r | n | b | q | k | b | / | r |
  +---|---|---|---|---|---|---|---+
    a   b   c   d   e   f   g   h

White&#39;s turn.
Orig coordinate: 
&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    
    <item>
      <title>Chess and C, day 2</title>
      <link>https://rbenencia.name/blog/2015-03-28-chess-2/</link>
      <pubDate>Sat, 28 Mar 2015 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2015-03-28-chess-2/</guid>
      <description>&lt;p&gt;Yesterday I&amp;rsquo;ve &lt;a href=&#34;https://rbenencia.name/blog/2015-03-27-chess-1/&#34;&gt;started&lt;/a&gt; a blog post series
where about writing a small chess interface in C. I&amp;rsquo;ve set up the types
&lt;code&gt;Color&lt;/code&gt;, &lt;code&gt;PieceType&lt;/code&gt;, &lt;code&gt;Piece&lt;/code&gt;, &lt;code&gt;Square&lt;/code&gt; and &lt;code&gt;Board&lt;/code&gt;, and talked about the
general idea of the game. Finally, I&amp;rsquo;ve shown some of the logic behind
printing and initializing the &lt;code&gt;Board&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;One of the problems I&amp;rsquo;ve talked about yesterday was the fact that I&amp;rsquo;m
hardcoding the initial positions to the inner representation of the board.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Board &lt;span style=&#34;color:#a6e22e&#34;&gt;_pawns&lt;/span&gt;(Board b) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;short&lt;/span&gt; white_pawns_row &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;, black_pawns_row &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;6&lt;/span&gt;, i;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; (i &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;; i &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt; SIZE; i&lt;span style=&#34;color:#f92672&#34;&gt;++&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        b[white_pawns_row][i].piece &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;new_piece&lt;/span&gt;(WHITE, PAWN);
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is quite ugly because I&amp;rsquo;m tying the initialization to the types and in
a future we might find this to be pretty restrictive. Another case where
this approach isn&amp;rsquo;t useful is in the &lt;code&gt;print_board(Board)&lt;/code&gt;
function. Yesterday what I did was something similar to the following piece
of code.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; (i &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;; i &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt; SIZE; i&lt;span style=&#34;color:#f92672&#34;&gt;++&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; (j &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;; j &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt; SIZE; j&lt;span style=&#34;color:#f92672&#34;&gt;++&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#a6e22e&#34;&gt;print_square&lt;/span&gt;(b[i][j]);
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, let suppose that we want to print the board from the black player
perspective. Auch. We might need to code a &lt;code&gt;print_board_backwards(Board)&lt;/code&gt;
function. Ugly ugly. Sounds like we&amp;rsquo;re repeating code. So, what do we do?
We add a layer of indirection. Let&amp;rsquo;s introduce the &lt;code&gt;Coord&lt;/code&gt; type!&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;typedef&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;struct&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;char&lt;/span&gt; row;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;char&lt;/span&gt; col;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;} Coord;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now, after coding some utility functions it&amp;rsquo;s possible to do something like
this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;static&lt;/span&gt; Board &lt;span style=&#34;color:#a6e22e&#34;&gt;_kings&lt;/span&gt;(Board b) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#a6e22e&#34;&gt;_set_new_piece&lt;/span&gt;(b, &lt;span style=&#34;color:#a6e22e&#34;&gt;coord_init&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;e1&amp;#34;&lt;/span&gt;), WHITE, KING);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#a6e22e&#34;&gt;_set_new_piece&lt;/span&gt;(b, &lt;span style=&#34;color:#a6e22e&#34;&gt;coord_init&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;e8&amp;#34;&lt;/span&gt;), BLACK, KING);
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Pretty neat, isn&amp;rsquo;t it? By the way, yesterday I forgot to make &lt;code&gt;static&lt;/code&gt; all
the internal functions, so I&amp;rsquo;ve also fixed that. Anyway, how can this
representation help us to, say, use only one function to print the board
both forwards and backwards? Well, I&amp;rsquo;ve implemented the following
functions.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;/*
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt; * Returns the next coordinate. Useful for traversing the board forwards.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt; */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Coord &lt;span style=&#34;color:#a6e22e&#34;&gt;coord_next&lt;/span&gt;(Coord);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;/*
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt; * Returns the previous coordinate. Useful for traversing the board backwards.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt; */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Coord &lt;span style=&#34;color:#a6e22e&#34;&gt;coord_prev&lt;/span&gt;(Coord);
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;rsquo;ll see how this functions are used in a minute. Meanwhile, we&amp;rsquo;ll need to
add a new parameter to the board printing function: the side or perspective
we will use for the board, i.e. if we are the black player or the white
player. Let&amp;rsquo;s use the already defined &lt;code&gt;Color&lt;/code&gt; type! Here is the complete
implementation.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;print_board&lt;/span&gt;(Board b, Color side) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    Coord c &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;_next_coord&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;coord_null&lt;/span&gt;(), side);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;char&lt;/span&gt; current_row &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;coord_get_row&lt;/span&gt;(c);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#a6e22e&#34;&gt;_print_row_separator&lt;/span&gt;();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;while&lt;/span&gt; (&lt;span style=&#34;color:#f92672&#34;&gt;!&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;coord_is_null&lt;/span&gt;(c)) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;// Print row if it&amp;#39;s the first column
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#a6e22e&#34;&gt;_first_column&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;coord_get_col&lt;/span&gt;(c), side))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#a6e22e&#34;&gt;printf&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;%c &amp;#34;&lt;/span&gt;, current_row);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;// Print the square
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#a6e22e&#34;&gt;print_square&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;board_get_square&lt;/span&gt;(b, c));
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;// Shall we move forward or backwards?
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        c &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;_next_coord&lt;/span&gt;(c, side);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#75715e&#34;&gt;// If the row changed then we must start a new line
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#a6e22e&#34;&gt;coord_get_row&lt;/span&gt;(c) &lt;span style=&#34;color:#f92672&#34;&gt;!=&lt;/span&gt; current_row) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#a6e22e&#34;&gt;printf&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;|&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;\n&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#a6e22e&#34;&gt;_print_row_separator&lt;/span&gt;();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            current_row &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;coord_get_row&lt;/span&gt;(c);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#a6e22e&#34;&gt;_print_columns&lt;/span&gt;(side);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The magic of the implementation is in the &lt;code&gt;_next_coord(c, side)&lt;/code&gt;, which
allow us to code the printing function without paying too much attention to
the side of the board we&amp;rsquo;re printing. As you may have guessed, its
implementation is quite simple.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;static&lt;/span&gt; Coord &lt;span style=&#34;color:#a6e22e&#34;&gt;_next_coord&lt;/span&gt;(Coord c, Color side)  {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; (side &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; WHITE)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;coord_next&lt;/span&gt;(c);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;coord_prev&lt;/span&gt;(c);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, here is how the chess board will be printed from a white player
perspective.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  +---|---|---|---|---|---|---|---+
8 | R | N | B | Q | K | B | N | R |
  +---|---|---|---|---|---|---|---+
7 | P | P | P | P | P | P | P | P |
  +---|---|---|---|---|---|---|---+
6 |   | / |   | / |   | / |   | / |
  +---|---|---|---|---|---|---|---+
5 | / |   | / |   | / |   | / |   |
  +---|---|---|---|---|---|---|---+
4 |   | / |   | / |   | / |   | / |
  +---|---|---|---|---|---|---|---+
3 | / |   | / |   | / |   | / |   |
  +---|---|---|---|---|---|---|---+
2 | p | p | p | p | p | p | p | p |
  +---|---|---|---|---|---|---|---+
1 | r | n | b | q | k | b | n | r |
  +---|---|---|---|---|---|---|---+
    a   b   c   d   e   f   g   h
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And here is the black player perspective.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  +---|---|---|---|---|---|---|---+
1 | r | n | b | k | q | b | n | r |
  +---|---|---|---|---|---|---|---+
2 | p | p | p | p | p | p | p | p |
  +---|---|---|---|---|---|---|---+
3 |   | / |   | / |   | / |   | / |
  +---|---|---|---|---|---|---|---+
4 | / |   | / |   | / |   | / |   |
  +---|---|---|---|---|---|---|---+
5 |   | / |   | / |   | / |   | / |
  +---|---|---|---|---|---|---|---+
6 | / |   | / |   | / |   | / |   |
  +---|---|---|---|---|---|---|---+
7 | P | P | P | P | P | P | P | P |
  +---|---|---|---|---|---|---|---+
8 | R | N | B | K | Q | B | N | R |
  +---|---|---|---|---|---|---|---+
    h   g   f   e   d   c   b   a
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Stay tuned for the following blog post of the series! I’ll add a user input
system so we can start playing real chess. &lt;code&gt;;-)&lt;/code&gt;&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Chess and C, day 1</title>
      <link>https://rbenencia.name/blog/2015-03-27-chess-1/</link>
      <pubDate>Fri, 27 Mar 2015 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2015-03-27-chess-1/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve been programming in Haskell as my main language for almost a year
now. Among other things, I love the concept of purity and expressiveness it
provides. In fact, I&amp;rsquo;ve gotten so used to the functional paradigm that I&amp;rsquo;m
having problems when writing code in other languages, as C, which kind of
sucks because I&amp;rsquo;m a teaching assistant of a subject where we use that
language.&lt;/p&gt;
&lt;p&gt;In order to remove the dust from my C skills I&amp;rsquo;ve decided to write a small
chess game. Nothing fancy, just a program with a small interface to receive
user movements and maybe a
&lt;a href=&#34;http://en.wikipedia.org/wiki/Portable_Game_Notation&#34;&gt;PGN&lt;/a&gt; re-player. As
I&amp;rsquo;m thinking about portability, I&amp;rsquo;ll avoid the use of non-portable
libraries.&lt;/p&gt;
&lt;p&gt;As good ol&amp;rsquo; Haskell teach us, let&amp;rsquo;s start by defining some types. We&amp;rsquo;ll
start with the very basics, the pieces. I can&amp;rsquo;t help thinking about
algebraic data types when coding this &lt;code&gt;:-)&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;typedef&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;enum&lt;/span&gt; {WHITE, BLACK} Color;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;typedef&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;enum&lt;/span&gt; {PAWN, ROCK, KNIGHT, BISHOP, QUEEN, KING} PieceType;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And then a &lt;code&gt;struct&lt;/code&gt; to contain these &lt;code&gt;enum&lt;/code&gt;s.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;typedef&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;struct&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    Color color;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    PieceType type;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;} Piece;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A &lt;code&gt;Piece&lt;/code&gt; will be placed in square, so let&amp;rsquo;s also define it a type. We can
reuse our &lt;code&gt;Color&lt;/code&gt; type.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;typedef&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;struct&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    Color color;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    Piece&lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt; piece;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;} Square;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;When a &lt;code&gt;Square&lt;/code&gt; is empty, it&amp;rsquo;s piece field will be &lt;code&gt;NULL&lt;/code&gt;. I have to admit
that when I designed the type I really missed the functional approach of a
&lt;code&gt;Maybe&lt;/code&gt; data type because it would easily allow me to express an empty
square by using &lt;code&gt;Nothing&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Last but no least, we&amp;rsquo;ll need a type for containing our sixty-four
squares. For the moment let&amp;rsquo;s use this simple type synonym.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;typedef&lt;/span&gt; Square&lt;span style=&#34;color:#f92672&#34;&gt;**&lt;/span&gt; Board;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;All right, now that we have defined the types, let&amp;rsquo;s start coding some
logic. We&amp;rsquo;ll start by initializing a &lt;code&gt;Board&lt;/code&gt; with its squares and piece
positions.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve defined the function &lt;code&gt;Board board_init()&lt;/code&gt; which will allocate memory
for the board and then call the function &lt;code&gt;Board _initial_setup(Board)&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Board &lt;span style=&#34;color:#a6e22e&#34;&gt;_setup_pieces&lt;/span&gt;(Board b) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;_pawns&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;_rocks&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;_knights&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;_bishops&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;_queens&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;_kings&lt;/span&gt;(b)))))); &lt;span style=&#34;color:#75715e&#34;&gt;// :-)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Board &lt;span style=&#34;color:#a6e22e&#34;&gt;_initial_setup&lt;/span&gt;(Board b) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;_setup_pieces&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;_setup_colors&lt;/span&gt;(b));
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As you may have guessed, when coding &lt;code&gt;_setup_pieces&lt;/code&gt; I used the functional
approach of function composition. The smalls functions that set up the
pieces just &lt;code&gt;malloc&lt;/code&gt; memory for a &lt;code&gt;Piece&lt;/code&gt; and set it up in its initial
position. For example, here is the function that initialize the pawns.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Board &lt;span style=&#34;color:#a6e22e&#34;&gt;_pawns&lt;/span&gt;(Board b) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;short&lt;/span&gt; white_pawns_row &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;, black_pawns_row &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;6&lt;/span&gt;, i;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; (i &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;; i &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt; SIZE; i&lt;span style=&#34;color:#f92672&#34;&gt;++&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        b[white_pawns_row][i].piece &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;new_piece&lt;/span&gt;(WHITE, PAWN);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; (i &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;; i &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt; SIZE; i&lt;span style=&#34;color:#f92672&#34;&gt;++&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        b[black_pawns_row][i].piece &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;new_piece&lt;/span&gt;(BLACK, PAWN);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; b;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I&amp;rsquo;m not happy with directly using the matrix indices. I&amp;rsquo;ll probably make an
API for using chess coordinates.&lt;/p&gt;
&lt;p&gt;Aside from initializing the board I&amp;rsquo;m also interested in watching it appear
on the screen, so I&amp;rsquo;ve coded a &lt;code&gt;print_board(Board)&lt;/code&gt; function that loops
trough the board and calls &lt;code&gt;print_square(Square)&lt;/code&gt; which, if the square is
not empty, will call &lt;code&gt;print_piece(Piece)&lt;/code&gt;. This last function will call
&lt;code&gt;int piece_character(Piece)&lt;/code&gt; to get the piece representation of our
choice. I would like to implement something like:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;int&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;piece_character&lt;/span&gt;(Piece p) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;switch&lt;/span&gt; (p.color) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; WHITE:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;switch&lt;/span&gt; (p.type) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; PAWN:   &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;♙&amp;#39;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; ROCK:   &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;♖&amp;#39;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&amp;hellip; but I&amp;rsquo;ve yet to understand how to use UTF-8 characters in a portable
way. For the moment I will stay with the following implementation:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;switch&lt;/span&gt; (p.type) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; PAWN:   res &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;  &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;p&amp;#39;&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; ROCK:   res &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;  &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;r&amp;#39;&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; KNIGHT: res &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;  &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;n&amp;#39;&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; BISHOP: res &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;  &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;b&amp;#39;&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; QUEEN:  res &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;  &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;q&amp;#39;&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;case&lt;/span&gt; KING:   res &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;  &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;k&amp;#39;&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;break&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; (p.color &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; BLACK)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;toupper&lt;/span&gt;(res);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; res;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, here is the small &lt;code&gt;main()&lt;/code&gt; I&amp;rsquo;ve implemented:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;int&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;main&lt;/span&gt;() {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    Board b &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;board_init&lt;/span&gt;();
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#a6e22e&#34;&gt;print_board&lt;/span&gt;(b);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#a6e22e&#34;&gt;board_delete&lt;/span&gt;(b);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And here is how the board will be printed on the screen:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;➜  chess git:(master) ./main 
+---|---|---|---|---|---|---|---+
| r | n | b | k | q | b | n | r |
+---|---|---|---|---|---|---|---+
| p | p | p | p | p | p | p | p |
+---|---|---|---|---|---|---|---+
|   | / |   | / |   | / |   | / |
+---|---|---|---|---|---|---|---+
| / |   | / |   | / |   | / |   |
+---|---|---|---|---|---|---|---+
|   | / |   | / |   | / |   | / |
+---|---|---|---|---|---|---|---+
| / |   | / |   | / |   | / |   |
+---|---|---|---|---|---|---|---+
| P | P | P | P | P | P | P | P |
+---|---|---|---|---|---|---|---+
| R | N | B | K | Q | B | N | R |
+---|---|---|---|---|---|---|---+
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Stay tuned for the following post! I&amp;rsquo;ll add a coordinate system and user input.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>CVE-2013-1436</title>
      <link>https://rbenencia.name/blog/2013-07-26-cve-2013-1436/</link>
      <pubDate>Fri, 26 Jul 2013 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2013-07-26-cve-2013-1436/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve just made an
&lt;a href=&#34;http://article.gmane.org/gmane.comp.security.oss.general/10722&#34;&gt;advisory&lt;/a&gt;
about &lt;strong&gt;CVE-2013-1436&lt;/strong&gt;. It was quite interesting to discover and
exploit. A
&lt;a href=&#34;http://handra.rampa.sk/dawb/patch?repoPURL=http%3A%2F%2Fcode.haskell.org%2FXMonadContrib&amp;amp;repoPHash=20130708144813-1499c-0c3e284d3523c0694b9423714081761813bc1e89&#34;&gt;patch&lt;/a&gt;
with a fix is already available. If you use &lt;code&gt;xmonad&lt;/code&gt; along with
&lt;code&gt;xmobar&lt;/code&gt; or &lt;code&gt;dzen&lt;/code&gt;, you should patch and re-compile your &lt;code&gt;xmonad&lt;/code&gt;
binary as soon as posible, or you&amp;rsquo;ll be exposed to a remote command
injection vulnerability.&lt;/p&gt;
&lt;p&gt;I would like to thank &lt;a href=&#34;http://www.joachim-breitner.de&#34;&gt;Joachim Breitner&lt;/a&gt;
and the &lt;a href=&#34;http://www.debian.org/security/&#34;&gt;Debian Security Team&lt;/a&gt; for their
help in disclosing this issue.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Controlling nVidia cards fans with nouveau in Debian</title>
      <link>https://rbenencia.name/blog/2013-03-25-controlling_nvidia_cards_fans_with_nouveau_in_debian/</link>
      <pubDate>Mon, 25 Mar 2013 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2013-03-25-controlling_nvidia_cards_fans_with_nouveau_in_debian/</guid>
      <description>&lt;p&gt;Unlike few years ago, current
&lt;a href=&#34;http://nouveau.freedesktop.org/wiki&#34;&gt;nouevau&lt;/a&gt; drivers work like a
charm. The only major feature I was missing was the ability to control the
fans because by default they&amp;rsquo;re very noisy, and for me silence is a
feature. Fortunately, as Christmas gift one of the last
&lt;a href=&#34;http://cgit.freedesktop.org/nouveau/linux-2.6/tree/Documentation/thermal/nouveau_thermal&#34;&gt;commits&lt;/a&gt;
of 2012 introduced this functionality.&lt;/p&gt;
&lt;p&gt;Yesterday I finally found some time to play with this feature, and here
I&amp;rsquo;ll describe the steps I&amp;rsquo;ve followed to make it work in Debian. My video
card is a GTS 250, but this procedure should also work on similar
cards. I&amp;rsquo;m using &lt;code&gt;sid&lt;/code&gt;, but I don&amp;rsquo;t see why this shouldn&amp;rsquo;t work in
&lt;code&gt;wheezy&lt;/code&gt;. Be aware, we&amp;rsquo;ll have to change the kernel and this may very well
introduce bugs in your system.&lt;/p&gt;
&lt;p&gt;Anyway, lets begin. The feature to play with &lt;code&gt;nVidia&lt;/code&gt; cards fans was merged
in the Linux kernel 3.7 or 3.8, I&amp;rsquo;m not sure, so we&amp;rsquo;ll have to install one
of them in our system. One option to do it is to download and compile the
kernel from &lt;a href=&#34;https://www.kernel.org/&#34;&gt;kernel.org&lt;/a&gt;, but an easier way is to
install it from the Debian &lt;code&gt;experimental&lt;/code&gt; repository, as at the moment of
writing this &lt;code&gt;wheezy&lt;/code&gt; and &lt;code&gt;sid&lt;/code&gt; have Linux kernel version 3.2. In order
to do it, add the experimental repository to your &lt;code&gt;sources.list&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# echo &amp;quot;deb http://debian.unlp.edu.ar/debian/ experimental main&amp;quot; &amp;gt;&amp;gt; /etc/apt/sources.list
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Our next step is to install the kernel:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# apt-get update &amp;amp;&amp;amp; apt-get -t experimental install linux-image-3.8-trunk-amd64
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that this step will quickly be outdated, as in a few months this
kernel version will reach &lt;code&gt;sid&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Before rebooting your system to try your shiny new kernel, you may have to
do one extra step. I had to do it with my GTS 250 card in order to make
this procedure work. Whenever you load the &lt;code&gt;nouveau&lt;/code&gt; module, you have to
load it with an extra parameter. I&amp;rsquo;ve decided to do it from GRUB, but you
can choose to do it with &lt;code&gt;modprobe&lt;/code&gt;. In order to do it from GRUB, add the
&lt;code&gt;nouveau.perflvl_wr=7777&lt;/code&gt; parameter to the variable
&lt;code&gt;GRUB_CMDLINE_LINUX_DEFAULT&lt;/code&gt; in the &lt;code&gt;/etc/default/grub&lt;/code&gt; file. It should
look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;cat /etc/default/grub | grep nouveau
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;quiet nouveau.perflvl_wr=7777&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then we have to tell GRUB to re-generate the menu. As root:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# update-grub2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Go now and reboot your system. You should have the followings files
available:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ls /sys/class/drm/card0/device | grep pwm1
pwm1
pwm1_enable
pwm1_max
pwm1_min
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;pwm1_enable&lt;/code&gt; represents the current fan management mode (&lt;code&gt;NONE&lt;/code&gt;, &lt;code&gt;MANUAL&lt;/code&gt; or
&lt;code&gt;AUTO&lt;/code&gt;). &lt;code&gt;pwm1&lt;/code&gt; represents the current power percentage of the fan. Ours
steps we&amp;rsquo;ll be to put the fan in MANUAL management mode and then lower the
power percentage to something reasonable. Lets try it:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# echo 1 &amp;gt; /sys/class/drm/card0/device/pwm1_enable
# echo 40 &amp;gt; /sys/class/drm/card0/device/pwm1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You should be now enjoying silence. In order to do this automatically
whenever your system boots, just add the previous command to
&lt;code&gt;/etc/rc.local&lt;/code&gt; file.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>CVE-2012-0220</title>
      <link>https://rbenencia.name/blog/2012-05-17-cve-2012-0220/</link>
      <pubDate>Thu, 17 May 2012 00:00:00 +0000</pubDate>
      <guid>https://rbenencia.name/blog/2012-05-17-cve-2012-0220/</guid>
      <description>&lt;p&gt;Two days ago I was playing with &lt;a href=&#34;http://ikiwiki.info/&#34;&gt;ikiwiki&lt;/a&gt;&amp;rsquo;s
login methods and its templates. After that came the turn of the
&lt;a href=&#34;http://ikiwiki.info/plugins/comments/&#34;&gt;comments plugin&lt;/a&gt; and its input
fields. Almost accidentaly, I discovered that the contents of
comment&amp;rsquo;s author input field weren&amp;rsquo;t correctly sanitized, having as a
consequence a
&lt;a href=&#34;https://en.wikipedia.org/wiki/Cross-site_scripting#Persistent&#34;&gt;stored XSS&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I spent the rest of that day trying to figure out where the bug
was. A couple of details slowed my search down for hours:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I didn&amp;rsquo;t know how ikiwiki&amp;rsquo;s code was structured&lt;/li&gt;
&lt;li&gt;I dislike perl&amp;rsquo;s syntax&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It was 3 AM when I realized my brain wasn&amp;rsquo;t working properly anymore,
and decided to get some sleep. Next day, after spending hours
debugging ikiwiki&amp;rsquo;s code, I finally found out where the bug was.&lt;/p&gt;
&lt;p&gt;I contacted &lt;a href=&#34;http://joeyh.name/&#34;&gt;Joey Hess&lt;/a&gt; (ikiwiki&amp;rsquo;s creator) and
the &lt;a href=&#34;http://www.debian.org/security/&#34;&gt;Debian Security Team&lt;/a&gt; in order
to disclose the vulnerability. Their work was flawless and fast, and a
few hours later the bug was disclosed with CVE ID
&lt;a href=&#34;https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2012-0220&#34;&gt;CVE-2012-0220&lt;/a&gt;.
An advisory was made with DSA ID
&lt;a href=&#34;http://www.debian.org/security/2012/dsa-2474&#34;&gt;DSA-2474&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    
  </channel>
</rss>
