Qsf – a small fast accurate spam filter

There are plenty of spam filters available for OpenBSD and other BSD systems such as bogofilter or spambayes, but these tend to be overkill for a single user system like mine. Another possibility is bmf, which is described as aiming to be faster, smaller and more versatile than similar Bayesian filters. However, it doesn’t seem to have been updated since 2002 and I didn’t like it too much when I tried it out..

I prefer Quick Spam Filter (QSF), which I have used for a good many years – in fact, since before I changed from Linux to OpenBSD in 2014. Its last update was in 2015. I find that after training it is reliable, with only occasional false positives or negatives. It hasn’t been ported to OpenBSD but it compiles easily. It is available from its author.

The qsf documentation describes how to integrate it with procmail. I have a separate post with details of doing this with fdm.

Network printer with CUPS: problem (Solved)

I don’t like CUPS but it’s a necessary evil on OpenBSD, at least if you want to be able to print from Firefox. It’s OK when it works but I’ve found that printing sometimes stops working for no apparent reason, and CUPS is so complex that you can chase the solution for hours or days.

On this occasion I was still able to put the data to be printed into the queue but CUPS wouldn’t print it. The solution I found was to reinstall the printer (Brother HL-5030DN) and to use the Backend resource to set the printer’s local IP address as backend:

http://xxx.xxx.xxx.xxx

I could then print from the command line but printing from Firefox still didn’t work. To fjx that I needed to modify about:config.

Method: Type about:config into the address bar of the browser. Accept the warning and promise to be careful. Once you are in about:config, type ‘printer’ in the search panel at the top of the screen. This brings up an entry where you can type the same IP address that you used in CUPS. This shoud give you printing in Firefox.

Four Tiling Window Managers Compared

Introduction

I’m an enthusiast for tiling window managers. I’ve tried out quite a few over the years, and here I offer my assessment of the four I’ve liked best: spectrwm,  i3, xmonad and dwm.

 

Summary for the impatient

My outright favourite is Spectrwm because I find that it offers all the features I want without making things over-complicated. Configuration via the text file is easy and the commands quickly become intuitive and automatic. Dwm is almost as good as Spectrwm but lacks some features that I want. i3 seems to be a popular WM and is better known than Spectrwm, I like it quite a lot but I find Spectrwm more intuitive to use. Xmonad is an attractive WM but is irretrievably let down by requiring Haskell to configure it.

The window managers in more detail

Note: For further details about WMs other than spectrwm, please follow the links below each entry.

 

1. Spectrwm
This is currently my favourite. Configuration by a plain text file is simple.   I should say that it is the most flexible and intuitive WM that I’ve tried.

Here are some screenshots.

Firefox in master position; two other windows open
Screenshot 2

Enlarge master window (Mod + L)
Screenshot 3


Change to horizontal split (Mod + Space)

Screenshot 4


Make a window fullscreen.(Mod + E)

Screenshot 5

Switch to Workspace 2 containing xsane (Mod +2 or Mod + R. arrow)
Screenshot 6

Note: xsane was started from xterm; the xsane windows  are floating (set via Quirk in ~/.spectrwm.conf)

More information

My Spectrwm configuration file

Get spectrwm here

Detailed comparison of Spectrwm and i3 .

 

2. i3
I liked i3 quite a lot and used it for a time. Configuration is simple since it is done in a plain text file. In many ways it is similar to spectrwm but  the windows are arranged i differently. i3 seems to be better known than Spectrwm with a larger following However, it has some slighly irritating idosyncracies, and  having tried out both of them fairly extensively I find I prefer Spectrw.. For my reasons see the detailed comparison of Spectrwm and i3 .

More information

My i3 configuration file

3. Xmonad
This has a large user base and a helpful mailing list. It has many of the features I want and is quite similar to Spectrwm but is let down by its being configured in Haskell, which makes any configuration beyond the most basic a major undertaking requiring hours of research on the internet. There is also a large disk space overhead required to house the libraries needed for said configuration. For these reasons Xmonad loses out to its competitors, at least for me.

More information

Setting up xmonad

4. Dwm
Dwm is the forerunner from which many other tiling WMs forked. There is still a lot going for it: it’s simple and functional and easy to learn. Configuration is via C, but don’t be put off; it’s easier than it looks even if you don’t know C (I don’t). If you are not willing to embark on learning Haskell, dwm would be an attractive alternative. If Spectrwn were not available I’d use Dwm.

More information

Setting up dwm

Continue reading “Four Tiling Window Managers Compared”

Vim – how to avoid hjkl confusion in Insert mode

 

 

Are you a Vim user? Do you like to use the hjkl keys to move the cursor in Normal mode, like me? If you do, perhaps you’ve experienced the annoyance of forgetting that you are in Insert mode, only to find something like hhhhh or kkkkk appearing on the screen instead of the expected cursor movement. I have to admit that this still happens to me, even after many years. How can it be avoided?

Vim experts advise that you should stay in Normal mode most of the time; it should be the default. I agree, and I do try to remember to do this.  Another idea, which I’ve tried in the past, is to make key mappings such as Alt+h and Alt+l  to move the cursor in both Insert and Normal modes and disable the defaults. But then you’ve lost the simplicity of the one-key hjkl which was the main reason to go down this route in the first place.

The solution I’ve adopted is based on <https://stackoverflow.com/questions/7614546/vim-cursorline-color-change-in-insert-mode>. Here is the code I’m using in .gvimrc with a dark colour scheme (Murphy). (The last character in the bottom line is a zero.)

set cursorline
autocmd InsertEnter * highlight CursorLine guifg=white guibg=grey25
autocmd InsertLeave * highlight CursorLine guifg=white guibg=red
set guicursor+=n-v-c:blinkonO

This gives a light grey cursor line in Insert mode which stand out on the dark background but not too starkly.

Insert mode

In Normal mode the cursor line becomes red.

Normal mode

I use the default cursor, which is block in Normal mode and 25% in Insert mode. Both are white; I’ve set the Normal mode cursor not to blink.

I find that this set-up acts as an effective reminder of which mode I’m in.

i3 and Spectrwm compared

Introduction

I’ve long heen an enthusiast for tiling window managers and have blogged about them previously. I last used i3 a number of years ago (perhaps version 4.11). At that time I said that I liked it but preferred Spectrwm. Now i3 is at version 4.6 and its popularity seems to be expanding, so I thought it was time to give it a fresh look to see whether I still prefer Spectrwm. I find I do although i3 is certainly impressive.

Here I summarise what seem to me to be the main differences between the two WMs. Obviously this is a subjective comparison but I shall give the reasons for my preferences.

Community and support

Here i3 has the clear advantage. It has a large user base and lots of online support (mailing list, IRC etc.), which makes it easy for newcomers to get help.

For Spectrwm this element is pretty much lacking. It has good documentation but there isn’t an online community of the kind that i3 enjoys. But it is still actively maintained; the most recent version (3.3.1) was released on 25/06/2020, and you can chat with the developers at OFTC channel #spectrwm.

Winner: i3

Design differences

The main way in which the two WMs differ is in how they arrange their tiled windows (both offer floating windows if wanted).

Spectrwm is similar to Dwm and Xmonad. The first window you create occupies the whole screen. Subsequent windows are created in a stacking area on the right. The area on the left of the screen is known as the “master” area.

Spectrwm screenshot
Spectrwm screenshot

This isn’t as rigid as it may sound. You can swap the master window with one of the others and you can work in any window you have open, whether it is in the master area or not. You can have more than one window in the master area if you want.

i3 doesn’t have the concept of a master area. It places its windows either side by side (horizontally) or one above the other (vertically). All the windows are of equal status.

i3 screenshot
i3 screenshot

Each of these methods has its advantages and disadvantages.

i3 can produce more complex patterns than Spectrwm; you can mix vertical and horizontal windows in the same workspace, as shown above. Spectrwm can’t do this; the windows are either horizontal or vertical but not both in the same workspace.

However, in i3 you have to decide which layout, horizontal or vertical, to use before you create a new window, and as far as I know you can’t alter this later without deleting and recreating the windows concerned. In Spectrwm  you can alternate between these layouts on the fly with Mod + Space.

In practice I hardly ever need the complexity that i3 offers because I seldom have more than two or three windows open in any one workspace. On the other hand I prefer the working window to be on the left of the screen; this is easy to achieve in Spectrwm, simply by swapping the stacked and master windows with Mod + Return. Swapping two windows is possible in i3 but more complicated (you have to change the “mode”).

Winner: Spectrwm

Altering the size of the windows

In Spectrwm you can increase or decrease the size of the master area by pressing Mod + l or Mod + h. I find this extremely useful and I do it a lot. In i3 you are encouraged to use the mouse to alter the size of windows, which is quite fiddly. I prefer to use the keyboard whenever possible; there is a way of doing this in i3 but it’s not very straightforward (change the “mode”).

Winner: Spectrwm

Miscellaneous

A peculiarity of i3 is that instead of using the vi key bindings (hjkl) for cursor movement it uses jkl; by default. This annoys me. You can of course change it, but then you have to find an alternative for Mod + h which by default is used to set the horizontal window layout. This seems to me an unnecessary and eccentric complication – one of several ways in which I find i3 less intuitive than Spectrwm.

Winner: Spectrwm

Available commands

As far as I can see, all the commands that i3 offers are also present in Spectrwm apart from those that are i3-specific. On the other hand, a useful feature of Spectrwm is the option to “iconify” a process, which means that it is no longer on-screen but doesn’t stop working. For example, suppose you start mplayer or mpv in an xterm to play some music. If you iconify the window the music will continue playing. When it finishes or if you want a different piece you simply un-iconify the window to make the changes. This command is also useful if you want to start a second browser temporarily or compile a large program. (Actually i3 can do something similar via its scratchpad – see comment below – but it doesn’t work out of the box and has to be set up by the user.)

Winner: Spectrwm

Conclusion

As you can see, for me Spectrwm comes out on top for all comparisons except community support.

Making this analysis of the differences between i3 and Spectrwm has been a useful exercise. It’s shown me why I prefer Spectrwm. But I don’t want to knock i3; it’s an excellent tiling WM and deciding which is better comes down to personal preference and priorities.  Newcomers to the world of tiling WMs would probably find it easier to use i3 initially because it allows for more hand-holding. But even if that’s your case I’d suggest trying Spectrwm later as well.

Fortunately experimentation is easy. Both i3 and Spectrwm work well out of the box with their default settings; perhaps the only immediate change that may be needed is to assign the Windows key (Mod4) as modifier in place of Alt (i3 has a wizard which offers you this choice as part of its setup process.) Anyway, both have configuration via plain text files so there is no need to learn a new programming language in order to configure them.

How to replace procmail with fdm

 

 

 

Procmail is still widely used although it is no longer maintained. Its former maintainer on OpenBSD, Philip Gunther, has said that it should be removed from the ports list because of security vulnerability, although it is still there. A suggested alternative is fdm, which both fetches the mail from a POP3 server and filters it, thus replacing both fetchmail and procmail.

I’d been using procmail with fetchmail for a long time but I thought perhaps I should switch to fdm. The main difficulty was that the documentation I found was less complete than what is available for procmail and it took me a fair amount of time to configure it to use my spam filter, which is qsf.

Here is my fdm.conf for anyone who is thinking of making the same switch.  Qsf writes “SPAM” in the subject line of suspect emails so that’s what I filter on.

My fdm.conf


# fdm.conf – see the fdm manual for explanations of the code.

# Set the maximum size of mail:
set maximum-size 128M

# connection settings for my ISP’s mail server:
account “<my POP3 account>”
pop3 server “<my POP3 server>”
user “<my email address>”
pass “<my password>”

# filtering rules (adapted from my .procmailrc):
match “^(To|Cc):.*lyx-users@lists.lyx.org” action mbox “%h/Mail/lyx-users”
match “^(To|cc|Cc|Sender): .*misc@openbsd.org” action mbox “%h/Mail/openbsd”

# forward some mail to a different account (see “My forward file” below):
match “^From:.*Facebook” action pipe “%h/.forward”

# Spam filter rules:
action “spamfilter” rewrite “/home/ac/bin/qsf -s”
match all action “spamfilter” continue
match “^Subject:.*SPAM” action mbox “%h/Mail/spam”

# Set spoolfile for incoming mail:
action “inbox” mbox “/var/mail/ac”
match all action “inbox”


My .forward file

smtp <user@example.com>

How to make a sitemap.xml for a medium-sized site

Revised 31 October 2020

In the past I’ve recommended various ways to produce a sitemap.xml for free but all of them ceased to work after a time. However, I do now have a solution which has worked well for about a year. See:

https://freesitemapgenerator.com/

This allow you to make three large sitemaps that work perfectly.

For WordPress I’ve installed a plugin which provides a sophisticated sitemap.xml system which seems to be working well (google-sitemap-generator.4.1.0).

My Spectrwm Configuration File (with comments)

Actually, the default spectrwm.conf works pretty well, apart perhaps from changing the Mod key. It’s easy to try out changes on the fly; just edit the file with the help of the man page and test it with Mod+q. If you make a mistake spectrwm will tell you by printing an error message in the bar.

Just one caution: some mistakes may prevent spectrwm (and therefore X)  from starting, so be careful about using Mod+Shift+q. If that happens you will have to edit .spectrwm.conf without using X. This doesn’t apply to Mod+q.

Note: to improve readability I mostly don’t show unused (commented out) options. See the man page for these.
____________________________________________________________

# PLEASE READ THE MAN PAGE BEFORE EDITING THIS FILE #

# Important
# Mod key, (Windows key is Mod4) (Apple key on OSX is Mod2)
modkey = Mod4

# Workspaces and Layout
workspace_limit = 5 # I don’t need more than this.

# Changes to Defaults
# The next two entries replace the default Mod+Space. Why? By default, this command cycles between the different layouts (vertical, horizontal, full screen). I seldom need to do this whereas I very frequently need to alternate the focus between main and stack. So I set Mod+Space to toggle focus_main and use Mod+c to cycle the layout.
bind[focus_main] = Mod+space
bind[cycle_layout] = Mod+c

# Other (minor) changes to defaults
bind[] = Mod+Shift+Delete # I don’t need to lock the screen and I want to avoid doing so accidentally, so disable the default.

# Window Decoration
border_width = 2
color_focus = red
color_unfocus = blue
tile_gap = 2

# Bar Settings
bar_enabled = 1
bar_border_width = 2
bar_border[1] = yellow
bar_border_unfocus[1] = yellow
bar_font_color[1] = white
bar_font = -*-courier-*-r-*-*-*-160-*-*-*-*-*-*
bar_format = %a %b %d %R +S +F +L +V
bar_at_bottom = 1

# Miscellaneous
iconic_enabled = 1 # occasionally useful

# Programs
program[term] = xterm

# Quirks
quirk[Xsane:xsane] = FLOAT + ANYWHERE
quirk[Gimp:gimp] = FLOAT + ANYWHERE

Firefox fonts too small in toolbars

For a long time I’ve been using userChrome.css to adjust the size of the fonts in the toolbars in FF. Then for some reason it stopped working (FF 72.0.2 on OpenBSD).

After some digging on the internet I found a solution. You need to use “about:config”.

Type this in a new tab. Accept the warning. Then search for “devp”. This has a line:

layout.css.devPixelsPerPx

In my case the default value for this was -1.0. To get acceptable-size fonts I needed to make it 1.8  (i.e. increase it from a negative to a positive value).

To change this, click the pencil symbol on the right and make the change. Then close the tab. (The symbol to the right of the pencil, which is two curved arrows, returns the value to default. At least it does in the current version but all this keeps changing in different versions of Firefox so you may need to experiment.)

Note 1: doing this will change ALL the fonts in FF, so you will probably need to adjust your font size setting in Preferences.

Note 2: As an alternative to all this you can make the fonts bigger in ALL your programs, including Lyx, Gimp, Lowrtier etc. This is probably the best solution if you are using the X-Window system in Unix or linux. To do this add the following lines to ~/.xsession and ~/Xresources:

Xft.dpi: 120 in ~/.Xresources
xrandr --dpi 120 in ~/.xsession
(Use different values instead of 120 if you prefer.)

[Courtesty of Mark Patruck on misc:openbsd.org.]

`

Why are some of your books free?

 

 

 

Introduction

This question is really part of a larger one, which is why do I self-publish? Let’s get one thing out of the way immediately: it isn’t because I can’t get published by mainstream commercial publishers.

In the past I’ve had seven books published in this way, both fiction and non-fiction, but I’ve abandoned that route now, as have many other writers.

Why self-publish?

In a word, disillusionment. The science writer John Horgan explains why he decided to self-publish his latest book. “After I got the idea for Mind-Body Problems in 2015, I pitched it to a few agents and editors and got chilly responses. Fuck ‘em, I thought, and wrote the damn book anyway.” My feeling precisely. Mainstream publishing ain’t what it used to be.

In recent years I’ve gone down the self-publishing route entirely, for similar reasos, with eight books produced so far. All are available electronically as e-books and most are also in hardcopy as paperbacks (on Amazon and Lulu).

Why free?

But why are some of them free? Don’t I want to make money from my writing? (‘No man but a blockhead ever wrote except for money’ – Samuel Johnson,) I certainly don’t dislike receiving the payments I get for these books from various sources.

Still, pace Dr Johnson, there are other motives for writing, such as being read. This has prompted Horgan to make his latest book free, and I’ve done the same with three of mine.

This isn’t as quixotic as it may appear. The sad fact is that you are very unlikely to make much money from any of the books you self-publish unless you are extremely lucky or willing and able to invest a lot of time and effort in marketing your work, which I’m not.

That may be discouraging, but don’t think that you’ll do a lot better if you take the commercial route. Mainstreame publishers these days make little if any attempt to publicise and market your book, and the cbances that you will make even a modest income from writing is small unless you have a specific audience in view (as in the case of a standard textbook, for example).

The changing face of publishing

Money always mattered to publishers, of course, but they often also wanted to feel they were doing something for literature.  That attitude is as dead as the mechanical typewriter (something else I grew up with).  The independent publishers who used to exist have virtually all been swallowed up by giant international conglomerates, which don’t even make a pretence of altruism.

Things were different when my first book, a novel, was published by Chatto & Windus in 1967. My editor was one of the directors, Cecil Day Lewis, who shortly afterwards was appointed Poet Laureate. After my book was accepted I went to see him in his Central London office and he asked me if I would allow him to edit my manuscript for publication, assuring me that I could trust him to do a good job! He also said he thought I had married too young (something which I think he had done himself).

Two decades later things had changed a lot but some of the original publishing houses still maintained their independence. One of these was Victor Gollancz Ltd, which published a book of mine in the 1980s.

I got to meet the Managing Director, Livia Gollancz, the daughter of Victor Gollancz, the founder of the firm. She had been a fine concert musician and became a publisher reluctantly, when her musical career ended owing to ill-health. She was a tall imposing woman who I think ran the firm rather imperiously. She took the decision to publish my book herself, but that wouldn’t happen today. Such decisions are now made on strictly commercial grounds by accountants.

If you have a book published commercially today you are most unlikely to meet any of the directors. In fact, you may not even get an editor, which explains the shoddy standard of some of the books I read nowadays.

Conclusion

The moral of the story is that if you want to write, go ahead and do so, but don’t count on its making you a fortune or even a modest income.