bash: Number of Days Between Today and Some Future Date

#!/bin/bash                                                        
                                                                   
printf -v date '%(%Y-%m-%d)T\n' -1                                 
echo $(( ($(date -d $1 +%s) - $(date -d $date +%s)) / 86400 )) days

Above is a bash script to output the number of days between today and some future date. Copy it into a file, e.g., diffdate.sh, into a directory, e.g., ~/bin/scripts. Then, enter the directory you saved it to and type to make it executable:

$ chmod +x diffdate.sh

Then, check your .profile to make sure something like this in it:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then                             
  PATH="$HOME/bin:$PATH"
fi                                                                   

Then, run the script.

$ diffdate.sh 2021-06-01
70 days

I have to figure out the difference between today and some future date all the time for forecasting, and today was the day I finally bothered to figure out how to do it from the command line. I have to start thinking of ways to make shell scripts to do this little tasks that I go to the web for.

Fun With Fortune in Linux

Fortune provides a random quote or aphorism every time you open a terminal in Linux. I wanted to have a personalized fortune using zuihitsu quotes posted on this site come up whenever I opened a terminal. If you want to do something similar, here’s the procedure.

To check if you have it installed, simply type fortune into the terminal.

$ fortune 

This either returned a fortune or an error message. If you got an error message, then install fortune using the package manager for your system.

$ sudo apt install fortune-mod

Let’s create our own file of fortunes. I want to use my zuihitsu quotes I have posted on this site. This file is a text file that looks like so:

%
quote 1
%
quote 2
%
quote ...

There is a copy of the file available online.

If you have just a file with lines of quotes, this is easy to get into this format using emacs. Simply type: M-%, followed by c-q c-j Enter then c-q c-j % c-q c-j Enter. I like to check the replacements, so just keep hitting y to do the replacement and move on to the next one if it looks good. Save the file to the appropriate directory, which on Debian systems is /usr/share/games/fortunes, but can vary. For explanation purposes, we are going to assume the file was named zuihitsu with no file extension.

Note: If you are using the file above, just save it as a text file in your directory. Then, copy it to the appropriate system directory without a file extension.

Now, create a .dat file for the file you just made.

$ sudo strfile zuihitsu

Set the same permissions on the new files as the others in the directory. This just makes the files readable to groups and others.

$ sudo chmod og+r zuihitsu
$ sudo chmod og+r zuihitsu.dat

Following the rest of the directory. I added a symbolic link.

$ sudo ln -s zuihitsu zuihitsu.u8

You should be able to test it now.

$ fortune zuihitsu

Assuming that worked. The final thing to do is to have your preferred shell call this when it runs. I use bash, so I added the command above to my bash_aliases file. From then on, it will pull a random quote from the zuihitsu file every time you bring up the terminal.

Bonus

Make a fortune come up automatically every time you login or open a new terminal by adding the following to .bashrc or .bash_aliases:

fortune zuihitsu 

Also, if you use mutt, you can add the following to your .muttrc file to have this fortune file generate a random signature for your emails:

set signature="fortune zuihitsu -s|"

The -s selects shorts quotes and the | pipes it to your email text.

Did you know the original fortune-mod fortune collection is available as a EPUB?

Revisiting the ASUS C201

Two and half years ago, I came across libreboot. I was looking for a linux laptop and came across this bit on the ASUS C201 page:

“This is unlike the other current libreboot laptops (Intel based). In practise, you can (if you do without the video/wifi blobs, and replace ChromeOS with a distribution that respects your freedom) be more free when using one of these laptops.”

ASUS Chromebook C201, libreboot.org. 2017

At the time, I was focused on exploring what it would mean to have the most free laptop available, and it led to the post: “Freedom & Limits: The ASUS C201 with libreboot and Parabola Linux.” The net: the machine did not have a reliable way to be free to the level of passing the requirements of the package of “your-freedom” and still be usable. The main problem is that it didn’t have a functional web browser and updates tended to bork the machine. I managed to get Arch, Parabola and Devuan linux installed on the machine. However, the installations kept breaking for various reasons, maybe half the time due to user error and half because ARM versions of the distributions were problematic for one reason or another.

In July 2019, I tried PrawnOS. It’s a nice distribution of Debian that actually was able to install to the computer’s onboard drive, which I couldn’t figure out how to do with the previous distributions. It provided a working system. Still, it really did not have a web browser that worked, I think it was still using Dillo. So, I left off at this point, happy to have learned something from the exercise.

A few days ago, I tried turning on the C201 again. I found that the distribution wouldn’t update. The documentation at github suggested I should reinstall PrawnOS. Easy enough.

I had already done the work of removing the security screw, upgrading the BIOS to libreboot, and had the machine in developer mode. If you aren’t there yet, then refer to the libreboot documentation and get to the point where it says Debian, Devuan or Parabola. Then, come back here and install PrawnOS instead.

To install PrawnOS, get the most recent release, which is available as a binary for people like me that don’t want to build from source. I tried using the browser Dillo on the C201 machine, but it kept timing out. So, I turned to wget.

$ sudo apt-get install wget
$ wget -c url_to_most_recent_release

Once you have the release, you need to copy it to the SD card. If you aren’t sure, you can always take out the SD card, run lsblk, then put the SD card back in and run lsblk again. The additional blk device is your SD card that you plug into /dev/$SD_CARD below..

$ sudo dd if=PrawnOS-*.img of=/dev/$SD_CARD bs=50M status=progress; sync

Then, you turn off the device, reboot and hit CTRL-U quickly at the menu to boot off the SD card. After booting, it gives you a prompt. Type in root, there is no password. Then, you are given a root prompt. Type:

# InstallPrawnOS

At this point, I was really blown away by how much this has been improved since the last time I have tried installing PrawnOS to this ASUS C201. PrawnOS is a Debian-derivative, with an encrypted partition. I typically do this with every linux install, and it was nice that it was built into the process. It offers sane defaults, such as using xfce4 over gnome, since gnome seems to have problems when used on an ASUS C201 machine. It also gets more pragmatic about freedom. Freedom is useless if it means you aren’t free to do something fundamental to using a computer, like browse the web.

So, PrawnOS includes Firefox-ESR, which the Free Software Foundation doesn’t consider free because it implements digital rights management technology. However, it is essentially required in order to use a computer normally. PrawnOS makes the pragmatic choice.

After I went through the set-up process, I was able to install emacs and add-ons. I did have some trouble updating the machine, whereas xorg threw configuration errors, but nothing that made the machine unusable like I have encountered in the past. I also continue to not be able to use the touchpad. However, for Chrome-level computer use, email, web browsing and so forth, the ASUS C201 seems like it could be a viable machine.

Emacs: Rebinding Caps Lock to Ctrl

I was reading this piece, The Beginners Guide to Emacs, which suggested making the Caps Lock Key into CTRL. I’ve been using emacs for years, and it never occurred to me to make this change. Lovely! Since it isn’t in the instructions, I’d thought I’d make a note here in case it comes up in the future. This version simply makes CapsLk into Ctrl.

$ sudo emacs /etc/default/keyboard

Then add: 

XKBOPTIONS="ctrl:nocaps"

$ sudo dpkg-reconfigure keyboard-configuration
$ shutdown -r now

GOG Games on Linux, Featuring Blade Runner

Blade Runner is a point-and-click adventure, a genre that was still very popular on PCs at the time of its release. Games like Beneath a Steel Sky had already used the format to tell Blade Runner-inspired cyberpunk stories. Given the usual state of movie adaptations, a Blade Runner adventure game wouldn’t necessarily have been anything to get excited about.‘Blade Runner’ really does make you feel like a detective

What Westwood did with the license, however, was inspired. The game isn’t a straight retelling of the movie. (Harrison Ford’s Deckard is nowhere to be seen.) You play a detective named Ray McCoy on the tail of replicants linked to vicious animal murders. While the story takes place at the same time as the movie and involves some of the same locations and characters, it plays out in parallel without intersecting too strongly. This was a great decision for a narrative adventure, allowing the game to evoke the movie without feeling predictable.

-Sam Byford, “The resurrected Blade Runner game is a genuine classic.” The Verge. December 18, 2019.

Blade Runner is currently on sale for $8.99 until January 2nd, 2020, at 2 PM UTC. And, if you are into free (as in beer!) games, and who isn’t, you could also download the previously mentioned Beneath a Steel Sky for nothing.

But, there’s a catch. GOG doesn’t provide much help getting these games installed on a Linux system. I didn’t see any instructions, but let me save you some time. I documented what I did to get it to work, and now, you have the very instructions that should be on the GOG website, but are somehow, inexplicably, not there. We’re going to use Blade Runner as our example, but while I was looking into how to get this thing running, it was apparent that these problems happen on the Linux platform with many of GOG’s games.

Installing & Getting the Games to Work

Before starting, let’s make life easy for ourselves and get an outdated audio library that is needed in order for the game to launch.

$ dpkg -i libsndio6.1_1.1.0-3_amd64.deb

You’re also going to need Simple DirectMedia Layer 2, which you can install the standard way, through the repository:

$ sudo apt-get install libsdl2-net-2.0-0

Now, with those preliminaries out of the way, let’s get to the task at hand, shall we? Download the Blade Runner file from the GOG website. Open a terminal:

$ cd Downloads
$ chmod +x blade_runner_1_0_varies.sh 
$ ./blade_runner_1_0_varies.sh 

After installation, it should be in your Show Applications, which is in the bottom right corner for people using the standard Gnome window manager, and then, select the game you’ve just installed, if it isn’t Blade Runner.

Or, maybe you’ve learned to love the terminal, you could launch the game from the command line by opening a terminal:

$ cd GOG\ Games/Blade\ Runner/
$ ./start.sh

The game should launch from this point. If not, contact GOG and …Good Luck!

An Introduction To Data Science On The Linux Command Line

…provide[s] the reader with a brief overview for a number of different Linux commands. A special emphasis will be placed on explaining how each command can be used in the context of performing data science tasks. The goal will be to convince the reader that each of these commands can be extremely useful, and to allow them to understand what role each command can play when manipulating or analyzing data.”

-Robert Elder, “An Introduction To Data Science On The Linux Command Line.” RobertElder.org. October 16, 2019.

A Quick Introduction to StumpWM on Linux

StumpWM is a tiling, keyboard driven X11 Window Manager written entirely in Common Lisp.”

Why Use It

StumpWM will likely cut down a lot of your use of a mouse. There’s many reasons to use the mouse less, such as speed (entering in a key combination is faster than using a mouse), carpal tunnel syndrome, and so forth.

I like StumpWM because it helps keep me on the command line. I’ve had some experience with it’s predecessor, Ratpoison, while trying to set up a C201 with free software last year, and I liked the focus on one application at a time and being able to type in a few keystrokes to move between them. So, I figured StumpWM was worth a try. Recommended, even if you don’t end up sticking with it.

Installing

Within Ubuntu, changing window managers is fairly easy. You just need to install StumpWM with the apt package manager.

$ sudo apt-get install stumpwm

Then, logout and select the gear icon near the enter button and select StumpWM from the drop-down menu and login as usual.

Quick Start

On logging in, you will notice StumpWM strips out most of what is standard in most window managers. There’s no clock. There’s no dock. There’s no background. There’s no list of apps. There’s nothing to navigate multiple desktops. There’s only a blank screen with a box in the upper right corner: “Welcome to Stump Window Manager. / Type C-t ? for help.”

The first thing you’ll want to do when you log in is type: Control-t together then the letter c and the Enter key (or abbreviated: C-t c, same style as in Emacs). This creates a console, and it takes up all the screen real estate. Like Emacs, it is possible to split the screen into a variety of configurations. For simplicity here and due to my preference for dealing with one application at a time, I’ll assume a single application in the screen.

So, if you want to use Firefox, type:

$ firefox &

The &; starts firefox as a background process. You can even change your .bash_aliases file to do this automatically for you.

Of course, there are command keys for other functions: C-t a will give you the time. C-t ; quit, then press Enter to quit.

If you want to switch back and forth between the console and Firefox, you type: C-t C-t. If you have multiple windows, you can see them all and chose them from a drop-down meny by typing: C-t ". Each window also has a number listed, which you can access directly, by typing: C-t 0 (assuming the window is 0).

That’s all you need to get up and running. If you want to start customizing your configuration, I’ve also included a straight-forward .stumpwmrc configuration file below, which among other changes includes replacing C-t with s-t (Windows key + t), which is useful if you want to continue using C-t to open new tabs in Firefox without having StumpWM supersede it.

Also, this configuration file will add back in a mode line, so you can have the time, battery level and option applications with numbers, which can be useful.

;; -*-lisp-*-                                                                  
;; .stumpwmrc                                                                                                                              
                                                                               
(in-package :stumpwm)                                                          
                                                                             
;;; Configuration                                                              
                                                                               
;; Change prefix key to Windows key                                            
(set-prefix-key (kbd "s-t"))                                                   
                                                                               
;; Changing to pointer from X default to standard left                         
(stumpwm:run-shell-command "xsetroot -cursor_name left_ptr")

;; Change prefix key to Windows key                                            
(set-prefix-key (kbd "s-t"))                                                   
                                                                               
;; Changing to pointer from X default to standard left                         
(stumpwm:run-shell-command "xsetroot -cursor_name left_ptr")                   
                                                                               
;; Turn-off start-up message                                                        
(setq *startup-message* nil)                                                   
                                                                               
(stumpwm:run-shell-command                                                     
 "feh --bg-scale ~/path/to/image.jpg")   
                                                                               
;; Start emacs daemon                                                          
; (run-shell-command "emacs --daemon")                                         
                                                                               
;; Start pulseaudio                                                            
(stumpwm:run-shell-command "pulseaudio --start") 

;; Disable system bell                                                         
(stumpwm:run-shell-command "xset b off")                                       
                                                                               
;; Start gnome keyring                                                         
(stumpwm:run-shell-command "gnome-keyring-daemon --start --components=gpg,pkcs\
11,secrets,ssh")                                                               
                                                                               
;; Mode line                                                                   
(defvar *battery-status-command*                                               
  "acpi -b | awk -F '[ ,]' '{printf \"%s%s\", $3, $5}' | sed s/Discharging/\-/\
 | sed s/Unknown// | sed s/Full// | sed s/Charging/+/")                        
                                                                               
(setf *screen-mode-line-format*                                                
      (list "[^B%n^b] %W^>"                                                    
      '(:eval (run-shell-command *battery-status-command* t))                  
      " | %d"))                                                                
                                                                               
(setf *window-format* "%m%n%s%c")                                              
                                                                               
(setf *mode-line-timeout* 1)  

;; Turn on the new mode line.                                                  
                                                                               
(toggle-mode-line (current-screen)                                             
        (current-head))                                                        
                                                                               
;; Launch Terminal at Start                                                    
(stumpwm:run-shell-command "gnome-terminal")                                   
                                                                               
;; Define keys                                                                 
(define-key *root-map* (kbd "c") "exec gnome-terminal")                        

; Emacs is commented out because I prefer to use                               
; it in the terminal.                                                          
;(define-key *root-map* (kbd "e") "exec emacs")  

(define-key *root-map* (kbd "f") "exec firefox")                               
(define-key *root-map* (kbd "v") "exec eog") ; Eye of Gnome                    
(define-key *root-map* (kbd "t") "exec thunderbird")                           
(define-key *root-map* (kbd "k") "exec keepassxc")                             
(define-key *root-map* (kbd "g") "exec gimp")                                  
(define-key *root-map* (kbd "r") "exec rstudio")                               
                                                                               
;; Functions                                                                   
                                                                               
(defun browse-url (url-string)                                                 
  "Browse url using WEB-BROWSER"                                               
  (check-type url-string string)                                               
  (run-shell-command (concat WEB-BROWSER "\"" url-string "\"")))

;; For connecting to emacs see:
;; http://www.kaashif.co.uk/2015/06/28/hacking-stumpwm-with-common-lisp/index.html

Tech Veganism

“One place where the veganism metaphor breaks down is that, although nearly anyone can be a vegan, tech veganism is mostly practiced by those who are expert enough or privileged enough to learn the elaborate workarounds to avoid the GAFAMs of the world. Setting up an Ubuntu laptop, a LineageOS phone, a Fastmail account, and wiring it all together so that you actually get calendar notifications is no easy feat. You will probably have to get your hands dirty on the command line.

I find that there’s a bit of a ‘let them eat cake’ attitude among tech vegan boosters, because they often discount the sheer difficulty of all this stuff. (‘Let them use Linux’ could be a fitting refrain.) After all, they figured it out, so why can’t you? What, doesn’t everyone have a computer science degree and six years experience as a sysadmin?”

-Nolan Lawson, “Tech Veganism.” nolanlawson.com. May 31, 2019.

Reposting my comment here:

The point that a lot of people miss is that there are two tech revolutions going on.

On one end, there’s the application, end-user technology that is designed to fit some specific need and be easy to use. Ideally, it’s just tapping buttons on a screen.

These tend to follow direct physical analogs of specific, single purpose tools: Search/Keep replaces the file cabinet, Maps replaces maps, YouTube is mobile television, Play is mobile board games, News replaces the newspaper, Gmail is mail, Contacts replaces the Rolodex, Drive replaces the suitcase, calendar replaces the Day Planner, Translate replaces the foreign language phrase book, Photos replaces the photo album, etc.

They do one thing. They do it well. They are useful. And they are all being combined in one device. But, they aren’t the standard by which every tool needs to be judged.

Some tools are general tools that can be applied to a wide variety of problems. Any idiot can pick up an arc welder or write a Python script. But, it takes time to learn how to use these general purpose tools well. They’re never going to be easy in the way that using email is easy. And there is no need to use Python or an arc welder on your phone.

Should TeX be compared to Word? It’s apples and oranges. How much does that Venn diagram overlap, regardless of definition?

Emacs is as different from a word processor as a word processor is from the legal pad. There’s inherent capability that doesn’t reduce down to the level of a pull-down menu or button. As soon as you make ease of use the defining feature, you narrow down capability to what a pull down menu can handle.

Most people aren’t solving problems that require training A.I.s, collaboratively writing programs with a tool like Git, making CGI movies with Renderman, etc. So, they have no need to learn these tools, and these tools do not need to simplified to suit them. They are what they are. OpenBSD is about security, not being “user-friendly” to the novice user. If you want “user-friendly,” use what everyone else uses.

“Tech vegans,” as you describe them, have different needs and different values. Some day, it would be nice if a LineageOS device were available at your telephone carrier’s store, Google didn’t mess with ad blocking extensions in their browser to make more money, and so forth. But, the incentives are what they are. Opting out of the default is hard by design. That’s not only a technology problem. It’s also an economic one.

Webster’s Revised Unabridged Dictionary (1913) on StarDict on Ubuntu/Debian

So, after reading “You’re probably using the wrong dictionary,” I thought I would give installing Webster’s Revised Unabridged Dictionary (1913) on a Debian-flavor of Linux a try and write it up the process and some observations of its use.

Installation on a Debian-flavor of Linux is straight-forward:

$ sudo apt-get install stardict
$ cd Downloads
$ wget https://s3.amazonaws.com/jsomers/dictionary.zip
$ unzip dictionary.zip
$ cd dictionary
$ tar -xvjf stardict-dictd-web1913-2.4.2.tar.bz2
$ cd stardict-dictd-web1913-2.4.2/
$ sudo mv *.* /usr/share/stardict/dic/
$ stardict

This launches the main application. There is also a mini-window that can be moved to where you like and then you can use it with other applications by highlighting text. Here’s a screenshot of this article:

When you highlight a word, it will automatically be searched for and displayed in the mini-window.

Entries include pronunciation, etymological origin, related words, definition and an example of usage, often from literature. I can imagine this being a very useful tool. It might be worth checking if my writing from this date changes in an appreciable way and whether it is an improvement or not.