Category Archives: geek

Oops report: Moving from i386 to amd64 on my server

I was trying to install Docker on my Linode virtual private server so that I could experiment with containers. I had a problem with the error “no supported platform found in manifest list.” Eventually, I realized that dpkg --print-architecture showed that my Ubuntu package architecture was i386 even though my server was 64-bit. That was probably due to upgrading in-place through the years, starting with a 32-bit version of Ubuntu 10.

I tried dpkg --add-architecture amd64, which let me install the docker-ce package from the Docker repository. Unfortunately, I didn’t review it carefully enough (the perils of SSHing from my cellphone), and installing that removed a bunch of other i386 packages like sudo, ssh, and screen. Ooops!

Even though we’ve been working on weaning lately, I decided that letting A- nurse a long time in her sleep might give me a little time to try to fix things. I used Linode’s web-based console to try to log in. I forgot the root password, so I used their tool for resetting the root password. After I got that sorted out, though, I found that I couldn’t resolve network resources. I’d broken the system badly enough that I needed to use another rescue tool to mount my drives, chroot to them, and install stuff from there. I was still getting stuck. I needed more focused time.

Fortunately, I’d broken my server during the weekend, so W- was around to take care of A- while I tried to figure things out. I had enough free space to create another root partition and install Ubuntu 16, which was a straightforward process with Linode’s Deploy Image tool.

I spent a few hours trying to figure out if I could set everything up in Docker containers from the start. I got the databases working, but I kept getting stymied by annoying WordPress redirection issues even after setting home and siteurl in the database and defining them in my config file. I tried adding Nginx reverse proxying to the mix, and it got even more tangled.

Eventually, I gave up and went back to running the services directly on my server. Because I did the new install in a separate volume, it was easy to mount the old volume and copy or symlink my configuration files.

Just in case I need to do this again, here are the packages that apt says I installed:

  • General:
    • screen
    • apt-transport-https
    • ca-certificates
    • curl
    • dirmngr
    • gnupg
    • software-properties-common
    • borgbackup
  • For the blog:
    • mysql-server
    • php-fpm
    • php-mysql
    • php-xml
  • For Quantified Awesome:
    • ruby-bundler
    • ruby-dev
  • For experimenting:
    • docker-compose
  • For compiling Emacs:
    • make
    • gcc
    • g++
    • zlib1g-dev
    • libmysqlclient-dev
    • autoconf
    • texinfo
    • gnutls-dev
    • ncurses-dev
  • From external repositories:

I got the list by running:

zgrep 'Commandline: apt' /var/log/apt/history.log /var/log/apt/history.log.*.gz

I saved my selections with dpkg --get-selections so that I can load them with dpkg --set-selections << ...; apt-get dselect-upgrade if I need to do this again.

Symbolic links to old volume:

  • /var/www
  • /usr/local
  • /home/sacha
  • /var/lib/mysql (after installing)

Copied after installing – I’ll probably want to tidy this up:

  • /etc/nginx/sites-available
  • /etc/nginx/sites-enabled

Lessons learned:

  • Actually check the list of packages to remove.
  • Consider fresh installs for major upgrades.

When things settle down, I should probably look into organizing one of the volumes as a proper data volume so that I can cleanly reinstall the root partition whenever I want to.

I also want to explore Docker again – maybe once I’ve wrapped my mind around how Docker, Nginx, WordPress, Passenger, virtual hosts, and subdirectories all fit together. Still, I’m glad I got my site up and running again!

Decision review: Samsung Note 8

It was quite a big jump going from a Moto G (2nd gen, bought in 2015) to a Samsung Note 8 this year, mostly on my dad’s insistence. Here’s how I’ve been working on making the most of my new phone’s capabilities.

  • Camera: Way more pictures of A-, since the camera works decently even in low light. I like how it reminds me to clean the camera lens.
  • Better battery life, quick charge: This is great. I used to keep W-‘s old Moto G handy so that I could swap to it if my phone battery ran low while I wrote in bed. Now I don’t even worry about charging overnight, since I can charge my phone while having breakfast with A-.
  • More storage: It’s nice not having to decide which apps I have space for on my phone. I even used the SD card to copy thousands of archived photos into Google Photos.
  • Pen: Screen-off notes are really quick to scribble down, since all I need to do is take out the pen and start writing. I trust writing more than typing for taking fast notes. I also really like the ability to select part of the screen and extract text, because sometimes apps don’t make it easy to select and copy text. I’ve used the pen to draw and colour illustrations for a book for A-. It’s more awkward than using my tablet PC or the iPad, but it lets me use phone time to get more things done, so it’s worth it.
  • Fingerprint scanner: Surprisingly handy way of reducing the friction of using my phone. I keep my phone locked when the screen is off so that A- doesn’t play with it, and tapping the fingerprint sensor to unlock the phone saves me a bit of fumbling around.
  • Voice and gesture control for pictures: Great for taking pictures, since it’s not easy to hold and shoot with one hand.
  • Speech recognition in general: I’ve been getting the hang of this now that battery life means I’m a little less worried about leaving my phone listening all the time. I have a few shortcuts for tracking activities, and I often set timers and add grocery items by voice too. It’s still not quite reliable, but it’s worth a shot. A- occasionally parrots “Okay Google” and “Command sent,” so I try to model saying “please” when I ask my phone to do things. I haven’t used Bixby as much, since voice wake-up for Bixby interferes with voice control of pictures.
  • Larger screen: This was a little hard to get used to, since the bigger screen makes it hard to put my phone in my pocket or hold in bed. But it does make it a little more manageable to ssh into my server and do things, although working with a virtual keyboard is still annoying. I’ve also used the split screen feature a few times.
  • Edge apps: I’ve used the clipboard and the ruler a few times.
  • Live focus: I’ve used this a few times, but I usually don’t have much time to compose a picture of A-. Maybe when she’s a bit older, or if I think about it more.

I want to explore more of the camera’s features, figure out a good workflow for photos, learn more about what I can do with speech recognition, and get better at workflows for notes (thoughts, images, and e-books).

I wonder if it makes sense to draw more on my phone than on paper even when A- is around. I haven’t been keen on doing so because she usually wants to imitate me, and she gets more out of drawing on paper than on my phone. Maybe I’ll draw on paper and take quick pictures on my phone instead.

I probably won’t upgrade for a while, since it’s likely to be a bit of a hassle selling this phone and upgrading to a new one. I might be tempted by an even better camera in the next phone. After all A- is only this age once. I really like the stylus. That means keeping an eye on the Samsung Note line and figuring out when it makes sense to upgrade. I hope this phone is sturdier than the Samsung Galaxy S3 I experimented with years ago. This one has survived life with a toddler so far, so that’s good. I spend more time on my phone than on my laptop these days, so it’ll be interesting to see how I can make the most of it.

2018-03-19 Emacs news

Links from reddit.com/r/emacs, /r/orgmode, /r/spacemacs, Hacker News, planet.emacsen.org, YouTube, the changes to the Emacs NEWS file, and emacs-devel.

Making an 8-page 7″x4.25″ captioned photo book with Org Mode and LaTeX

Here’s another technique that makes a simple photo book. I wanted to
make an 8-page book that could be printed 4 pages to a 8.5″x14″ sheet
(duplex, flip along the short edge), with a final page size of
7″x4.25″.

Sample with my own photos:

out.jpg

Prerequisites

  • ImageMagick
  • Texlive (probably)
  • latex-beamer
  • Org Mode and Emacs

Process

We can define the labels and their captions in a named table like this:

Let’s Go for a Walk  
   
Caption for photo 1 placeholder.png
Caption for photo 2 placeholder.png
Caption for photo 3 placeholder.png
Caption for photo 4 placeholder.png
Caption for photo 5 placeholder.png
   

Note that the first page is row #1 this time, instead of starting with
the last page.

Then we generate the LaTeX code with some Emacs Lisp, like so:

#+begin_src emacs-lisp :var pages=story :results value latex :exports results
(mapconcat (lambda (row) (format "\\graphicframe{%s}{%s}" (cadr row) (org-export-string-as (car row) 'latex t))) pages "\n")
#+end_src

I put that in a subtree for easier exporting with C-c C-e C-s l b (org-export-dispatch, subtree, LaTeX, Beamer).

Story

Process

  • Set up Org Mode export to Beamer
    (eval-after-load "ox-latex"
      ;; update the list of LaTeX classes and associated header (encoding, etc.)
      ;; and structure
      '(add-to-list 'org-latex-classes
                    `("beamer"
                      ,(concat "\\documentclass[presentation]{beamer}\n"
                               "[DEFAULT-PACKAGES]"
                               "[PACKAGES]"
                               "[EXTRA]\n")
                      ("\\section{%s}" . "\\section*{%s}")
                      ("\\subsection{%s}" . "\\subsection*{%s}")
                      ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))
    
  • Set up the header.tex

    This file gets included in the LaTeX file for the children’s book.
    Tweak it to change the appearance. In this example, I use black serif
    text text on the left side of a picture, both occupying roughly half
    of the page. I also experimented with using a different font this time, which you might need to install (for me, I did apt-get install texlive-fonts-extra).

    \geometry{paperwidth=7in,paperheight=4.25in,left=0.5in,right=0.5in}
    \beamertemplatenavigationsymbolsempty
    \usepackage{etoolbox}
    \usepackage[T1]{fontenc}
    \usepackage{Alegreya}
    \usefonttheme{serif}
    \setbeamercolor{normal text}{fg=black,bg=white}
    \setbeamercolor{structure}{fg=black,bg=white}
    %% \setbeamertemplate{frametitle}
    %% {
    %%   \begin{center}
    %%   \noindent
    %%   \insertframetitle
    %%   \end{center}
    %% }
    \newcommand{\graphicframe}[2] {
       {
       %% \if #1\empty 
       %% \usebackgroundtemplate{}
       %% \fi
       \ifstrempty{#1}{
       \begin{frame}[plain]
         \begin{center}
         \noindent
         \textbf{\huge{#2}}
         \end{center}
       \end{frame}
       }{
       \begin{frame}[plain]
          \begin{columns}
          \begin{column}{0.48\textwidth}
          \huge{#2}
          \end{column}
          \begin{column}{0.48\textwidth}
          \includegraphics[height=\textheight,width=\textwidth,keepaspectratio=true]{#1}
          \end{column}
          \end{columns}
       \end{frame}
       }
       }
    }
    \usepackage[noframe]{showframe}
    \renewcommand{\maketitle}{}
    
  • Create the PDF
    pdflatex index.tex
    
  • Create one PNG per page
    mkdir pages
    convert -density 300 index.pdf -quality 100 pages/page%d.png
    
  • Create the 4-up imposition

    The diagram at https://pressnostress.com/iw/howto/booklets/1.html was helpful.

    montage \( page4.png -rotate 180 \) \( page3.png -rotate 180 \) page7.png page0.png -tile 2x2 -mode Concatenate front.png
    montage \( page2.png -rotate 180 \) \( page5.png -rotate 180 \) page1.png page6.png -tile 2x2 -mode Concatenate back.png
    convert front.png back.png -density 300 ../print.pdf
    

Other notes

Placeholder image from https://en.wikipedia.org/wiki/File:Portrait_placeholder.png – public domain.

Using exiftool to put date, rating, and title in photo filenames

Now that we have a Synology backup server, I want to get better at keeping and organizing photos. I’ve got lots of pictures and videos of A- in Google Photos, but I don’t want to rely only on that. When Google eventually decommissions the service (no signs of this now, but you can never tell), I’d like to already have copies of my favourite photos and videos all prioritized and backed up instead of spending days wading through accumulated cruft.

I had previously added significant moments to a “Weekly highlights” album in the Google Photos app. I had also tried to select a number of those for “Level 2 highlights” and “Level 3 highlights” roughly approximating monthly and yearly filters. This was awkward, though, since Google Photos didn’t let me see which photos were already in an album or which timespans weren’t well represented. I wanted a five-star rating system so that I could gradually winnow images I liked, and I wanted tags for more flexibility.

The F-Stop Gallery app on Android seemed to be a quick way to sort through images, rate them, and tag them. I liked how it stored the metadata in the file instead of in a separate database. The bulk management tools were decent, although of course it would be even better to do things with fewer taps.

I downloaded ZIPs of my highlight albums and extracted them to a Samba share so that I could access them from my phone. I rated the level 3 highlights as 5 stars, level 2 as 3 stars, and weekly highlights as 2 stars, leaving the 4-star level for finer distinctions if I need to fiddle with things. Then I used cp -n (no clobber; don’t overwrite existing files) to copy the 5-star photos, then the 3-star photos, and lastly the 2-star photos. That way, even if a photo was in multiple albums, the file would have just the highest rating I assigned.

I can’t always rely on apps to index and search by the metadata in a file, so I like putting that information in the filename. A good filename might look like this:

2016-08-01-20-14-44 ### Relaxing on the deck #family.jpg

It starts with a date and time, since timelines make sense. I add one to the number of stars and convert that to # so that I can easily search for, say, ### to show me all entries that have at least two stars. This also creates a neat ASCII bar chart effect when looking at lists of filenames. I want to include the title if available, and any tags for easy searching as well.

Here’s the Bash script that takes an image file and renames it accordingly:

#!/bin/bash
exiftool -m \
  -"Filename<\${DateTimeOriginal;s/[ :]/-/g} \${Rating;s/([1-5])/'#' x (\$1 + 1)/e} \${Title} \${Subject;s/^/#/;s/, / #/g}.%e" \
  "[email protected]"

This probably has bugs, but it seems to be a decent start.

It was great to find out that I can pass Perl expressions to exiftool to modify the field value. I figured out that I could combine that with the /e flag for executable replacements so that I could generate a string of N+1 characters. While tinkering with the code, I accidentally used \1 instead of \$1 in my Org Mode block. That made a number such as 5 turn up as a scalar with a six-digit value, so I ended up with a really long line of #####... in my Org file. Emacs was definitely not happy. I ended up opening my Org file in vi so that I could delete the offending line. Anyway, I managed to recover from that and figure out what I needed to put in. Yay!

It would be pretty neat to have some kind of inotify thing watching my NAS inbox and processing files accordingly. In the meantime, I don’t mind running another script. We’ll see how this goes!

2018-03-12 Emacs news

Links from reddit.com/r/emacs, /r/orgmode, /r/spacemacs, Hacker News, planet.emacsen.org, YouTube, the changes to the Emacs NEWS file, and emacs-devel.