Escape with Spacemacs in Tmux

21 October 2020

I’ve occasionally been using a SSH session from my Pixel phones for years to login to my servers and write Clojure code in Emacs. I’d often run into an issue where I find myself having a weird time switching between NORMAL and INSERT modes when I’d hit ESCAPE quickly and try to move the cursor.

Googling my random problems is a favorite pastime, and I’ve finally stumbled upon an article about tmux and vim escape key. I learned that it’s probably been tmux sporadically eating my ESCAPE key, so I’ve tried disabling the built-in delay by adding to my .tmux.conf:

set -g -s escape-time 0

Templates and Snippets in Emacs

30 August 2020

I was only trying to write that last article, but it took me days to finally do it. I had so much work to do before I got there.

I had come to appreciate Emacs automatically inserting the boilerplate namespace declarations in new Clojure files, and I really thought I needed such convenience for my blog posts written in AsciiDoc in JBake. I dove down a 20-tab-deep, yak-shaving hole to get it done. [1]

I had to figure out the right search terms and names for what Emacs was doing for me. I finally found yatemplate which seems similar to yasnippets. Spacemacs has the templates layer for integrating yatemplate support, so I added that layer and created a template for my adoc files in my .emacs.d directory. My simple case worked, but I recognized that I’ll want that template on all my machines, so having a local copy of it wouldn’t cut it. I needed a way to check-in and version more Emacs/Spacemacs files than just my ~/.spacemacs files I was previously distributing.

I learned yasnippets would default to looking in ~/.spacemacs.d/ if the configuration was in there, so I had to move my ~/.spacemacs file over to ~/.spacemacs.d/init.el. To have the templates layer source templates from the .spacemacs.d directory, it required an extra bit of configuration when introducing it to the dotspacemacs-configuration-layers:

  (templates :variables templates-private-directory "~/.spacemacs.d/templates")

At this point, I could now commit my .spacemacs.d directory with the regular configuration file and the supporting templates and snippets. All those files will be cloned to all my workstations.

I was almost ready to write that article, but yasnippet and yatemplate have this fancy templating language. I’m sure that can make my article-creation even smarter! I read a bit more and found a couple cool elisp functions for automatically filling in the date and building a title from the file name. With the final enhancements to my adoc template, I could write the article, if I could only remember what I was trying to do in the first place. I hope to at least remember how to use these snippets and templates for future work.

1. I often measure task complexity in the number of tabs I end up having opened.

Clojure Core Logic for a Puzzle

11 May 2020

Lock Puzzle

I saw a puzzle pop up on Facebook a couple weeks ago, and it looked like a fun exercise for core.logic, since the puzzle simply requires keeping track of some constraints and reconciling them to one answer.

I had previously tinkered with the core.logic primer and I referred back to it to complete this little puzzle. I had originally coded some more complete rules about exclusion of some values which could have been implied by the puzzle, but I found they could be dropped and still get down to one answer. I started from the entire problem space of all digits and added the constraints to watch and verify each constraint’s effects.

(ns scratch.2020-05
  (:require [clojure.core.logic :as l]))

(l/run* [a b c]
  ;; all digits 0-9
  (l/membero a (range 10))
  (l/membero b (range 10))
  (l/membero c (range 10))
  ;; 6 8 2 one digit is right and in its right place
    [(l/== a 6)]
    [(l/== b 8)]
    [(l/== c 2)])
  ;; 6 1 4 one digit is right but in the wrong place
    [(l/membero a [1 4])]
    [(l/membero b [6 4])]
    [(l/membero c [6 1])])
  ;; 206 2 digits are right, but both are in the wrong place
    [(l/membero a [0 6])
      (l/membero b [2 6])
      (l/membero c (remove #{2 0 6} (range 10)))]
    [(l/membero a [0 6])
      (l/membero c [2 0])
      (l/membero b (remove #{2 0 6} (range 10)))]
    [(l/membero b [2 6])
      (l/membero c [2 0])
      (l/membero a (remove #{2 0 6} (range 10)))]
  ;; 3 8 0 one digit is right but in the wrong place
    [(l/membero a [8 0])]
    [(l/membero b [3 0])]
    [(l/membero c [3 8])])
  ;; 7 3 8 all the digits are wrong
  (l/membero a (remove #{7 3 8} (range 10)))
  (l/membero b (remove #{7 3 8} (range 10)))
  (l/membero c (remove #{7 3 8} (range 10))))
;; => ([0 4 2])

Advent of Code

14 December 2019

For the second year I’m taking part in the Advent of Code with friends and coworkers. I’m using Clojure again this year.

The Advent of Code is a story and series of puzzles released as 2 parts daily. There’s a community of people competing at various levels to complete the puzzles faster than others. I was keeping up fine for the first 7 days or so, but I eventually fell behind like many people. Fortunately, everyone can continue to work at our own pace. The puzzles from previous years continue to be available.

I’m happy to find that I’m having an easier time with Clojure this year, and I’m more easily able to use it to describe the algorithms instead of struggling with the language. I publish my code to Github.

All the Posts

October 2020

August 2020

May 2020

December 2019

November 2019

October 2018

May 2018

March 2018

February 2018

January 2018

November 2017

September 2017

June 2017