Archive | Computing RSS for this section

What services don’t you need on your Debian Linux box? sysv-rc-conf

Note to self:

On my Debian box there’s a bunch of stuff installed by default that I don’t need ‘cos it’s a workstation not a server. Anything that allows remote access, anything that talks to bluetooth, all that can be turned off, and it’s better to turn it off if you don’t need it, both for security reasons and boot time reasons. The easiest way to manage that on a Debian-based system is to install sysv-rc-conf, then run it as root and uncheck the boxes you don’t need by hitting the space bar. Anything beginning with ‘r’ is worth looking at, since that often means ‘remote’ and is likely to offer security issues. A lot of Linux stuff kind of assumes you’re running as a server, so there’ll be tools that allow access to network drives (nfs) and manage ports (portmap), and if your machine is a workstation in a home office, like mine, some or all that stuff is pointless and ought to be removed. I don’t need a webserver. Sometimes a good way to do it is uninstall the relevant packages. For example

$ sudo apt-get --purge remove nfs-kernel-server nfs-common portmap
$ sudo apt-get autoremove

But as noted, things can be left installed and just turned off. One easy way to do this is by installing sysv-rc-conf. This will control whether things get activated at startup. Makes it easy to manage services and only run what you want.

$ sudo apt-get install sysv-rc-conf
$ sysv-rc-conf
Arbitrary screen grab.

Arbitrary screen grab.

Anyway, you choose what you want to be activated at each different runlevel. It might be worth reading about runlevels a little but, but if there’s something you know you don’t want, just turn it off at all runlevels. (They are the 1 2 3 4 5 0 6 S labels across the top.)

You can also check out rcconf.

End reminder.

A VGA font in a terminal emulator

How’d I do it? It was quite a while ago and I can’t remember, I can’t recall. I’m trying to reconstruct it…

I grew up in the IBM compatible, DOS era. That VGA font that you got by default in DOS still, to this day, looks ‘right’ to me on a terminal screen, even after years of using Linux and Mac OS X and what not. I know it is not a great font in numerous ways, but I am so familiar I don’t even see it. It’s invisible, like a good writing tool should be. So I wanted to use it in my terminal window on Debian. It’s not very hard, maybe. I can’t remember if these were all the things I needed to do…

I am using mrxvt because I like the simplicity of it. This is my very simple mrxvt configuration file, .mrxvtrc:

Mrxvt.sl: 65535
MRxvt.ps: true

Mrxvt.xft:                      1
Mrxvt.xftFont:                  Perfect DOS VGA 437 Win
Mrxvt.xftSize:                  16
Mrxvt.xftAntialias:             1

Mrxvt.saveLines:                10000

And I have aliased the command mrxvt to this string:

alias mrxvt='mrxvt-full -fade 50 -ps -title " " -tn rxvt'

So to get the VGA font, I first went and found a good X windows font, called “Perfect DOS VGA 437 Win”, which is a ttf (TrueType font) when I unzip the archive. I put the file (called Perfect_DOS_VGA_437_Win.ttf) in a subdirectory of my .fonts directory; I put it under ‘p’ for perfect:

$ ls ~/.fonts/p
Perfect_DOS_VGA_437_Win.ttf

And, on a modern Linux system, that seems to be all that is required. Except I do notice that my .fonts.conf file looks like this (also serves as an example of what the font looks like in action):

Perfect DOS VGA 437 Win font used in mrxvt managed by FLWM.

Perfect DOS VGA 437 Win font used in mrxvt managed by FLWM.

Notice that the <dir> line at the end lists my local ~/.fonts directory? I think that might be important, but like I said it was a long time ago and I’m not sure.

So there you have it. Finding Perfect_DOS_VGA_437_Win.ttf somewhere on the web and putting it in your ~/.fonts directory and making sure that that directory is listed in your ~/.fonts.conf file and then changing the font selection line in the config file for whichever terminal emulator you are using might or might not let you use a font you don’t like.

 

 

Fonty McFontface.

Is it better to go off-line when teaching?

Students, just like most of us including me, are too distractible, especially younger ones lacking self discipline, and by younger I mean first year university, not genuinely young. These days we put the content and the tutorial questions on the Learning Management System (LMS, really just a website) and we tell them to use the LMS to access the questions and the supporting materials and such. Once upon a time they’d just get a bunch of photocopies (‘photostats’) or before that roneos (mimeographs) or just “copy this down off the board.” I’m not pining for the past, I’m trying to work out how we can combine the best of then and now.

What happened then was we’d come to class having not looked at anything beforehand, we’d copy down a bunch of questions or question numbers off the blackboard (it wasn’t a whiteboard) like ‘Ch 8 Q 12-18’) then we’d have the book open in front of us and we’d whisper to each other while we were supposed to be working out the answers. Hmm.

What happens now is this:

They come to class having not looked at anything beforehand (just like in the old days), because the know they can access it when they get there (we knew we’d be given it when we got there, back in the day, so no difference there). But, and this is different now, they then spend ten minutes getting onto the university network and getting distracted by Facebook or whatever and don’t download the questions until the tutorial is half over. Then they get out their notebook (or tablet and stylus) and read the question and… check their messages. Then they show the guy sitting next to them a cat video. Then they laugh and eat some Skittles (fine, fine, that is not the internet’s fault), then they look at Pinterest or for all I know Tinder, and then I ask them how they’re going and they mumble and we’re over half way through now and they have written down a few bits of data pertaining to the first question and that’s it.

Okay, maybe I’m overstating, but I have seen it happen that way. I’m not just fighting any innate apathy or disinterest (or depression or sense of futility) to get them to do the work, I am fighting the single most interesting thing the human race has ever constructed — a world wide distraction machine that has everything on it and available at the touch of a screen.

At best, even when they are doing some physics or mathematics, their attention is divided — they are always ready to pounce on an alert from whatever bit of social media they use, so their brain is never really thinking about the questions we give them to (we hope) help them learn.

Now, in the past when you copied a question off the board, it went in your eyes, through your brain and out your fingers onto the paper. I’m not sure that’s much better than not engaging with it at all, but it can’t be worse. You could only really talk to the people either side of you, just as students can now, so there were by definition fewer distractions because now there are all the ones I had as a student plus smart phones, so at the very least students now have more distractions. Do they deal with them better than I used to? Valid question. Maybe these days they have extra information, extra connectivity, and the ability to use that without being consumed by it.

I’m not sure.

I started thinking about this post while I stood there watching students flick away from Snapchat (or whatever it was) and back to the LMS whenever they saw me coming. A few were able to use the ‘net to find useful information, or a website with some helpful content, and that’s good because a working scientist or problem solver (engineer, IT, whatever) does just that, calling on the info around them as well as what they know. But those students were a small minority.

I recall thinking how I would really, really like to given them all a paper copy of the questions or, better, ask them to bring their own copies (then at least they would have looked at it to the extent of downloading and printing it off and getting it from the printer with their own actual physical fingers before they got there — does that count as ‘engagement’?), and then use just their notebook, their bog basic calculator and their textbook (they still exist, they do!) to tackle the problems.

I don’t say the web is useless. It is great for communication, for extra activities and resources. They can use the web to access the material easily and flexibly when they are not in my class. I use it to distribute videos to buttress the material, to direct them to external resources, though Britney Spears’ Guide to Semiconductor Physics is getting a little behind the zeitgeist now… The WWW ought to be great for collaboration, for ready access to what the students have not internalised. For simulations, for VR, for virtual laboratories, for Skype visits to major laboratories, for feedback, for interaction, for… the sky is the limit.

But not if you can’t sit still long enough to actually do it.

We’ve tried to engage the students to make them want to be there. I mean, that should solve everything. And there’s always a few who do want to be there and  that’s great, they learn almost regardless of what the teachers do. But some students are in the class because they have been told to be there, because the subject is a prerequisite for what the really want, because they thought they would like it and now it’s too late to drop out without recording a fail, whatever. By giving them the option to more easily be mentally elsewhere when they have not developed the self-discipline to choose to do what needs to be done, I’m not sure we’re helping. I wonder if more distraction-free classroom time would have its benefits as part of a broader suite of learning opportunities? Some of the environments would use all the tech at our disposal, and some would just have the student and their brain and the stuff to be tackled.

I just want the best of both worlds; is that too much to ask?

 

Old fart, I am.

Update and Shutdown; sudo, halt, stuff like that.

So I sometimes run the script stop.sh to shut down my Debian machine (it lives in ~/bin).

$ stop.sh
[sudo] password for username:

It asks me for my root password then does an update to get the new file version information, then an upgrade and dist-upgrade, then halts the machine. It’s a one-liner:

cat stop.sh
#!/bin/bash
sudo apt-get update  && sudo apt-get -y upgrade && sudo apt-get -y dist-upgrade && sudo halt

Now, what’s bad about this?

  1. Well, sudo ‘remembers’ that I’ve typed my password for (by default) five (or is it fifteen?) minutes, so if the early steps (update, for example) take a long time, the latter ones won’t work.
  2. Also, if my intent is to let it update and shut down without me, I’ll be walking away from a machine in which root access is available for that five (or is it fifteen?) minutes, so I probably want to lock the screen before I go. Not a big deal if it’s a home machine or you can lock the office, and probably not a big deal anyway unless you deal with sensitive information (or work with untrustworthy people…).
  3. The -y flag tells apt-get to say ‘yes’ to any queries the installer might ask. Could be a problem if I have a non-standard install or specific needs.
  4. I don’t see any information that the installer might give me, and I don’t find out if it worked till I come back and boot up.
  5. Some packages give information screens and ask the user to input a choice or acknowledge some information. They can mean it does not complete the task and so does not shut down.

The apt-get man page says:

-y, --yes, --assume-yes
           Automatic yes to prompts; assume "yes" as answer to all prompts and run
           non-interactively. If an undesirable situation, such as changing a held
           package, trying to install a unauthenticated package or removing an
           essential package occurs then apt-get will abort. Configuration Item:
           APT::Get::Assume-Yes.

So that should be borne in mind too.

Still, I use it anyway.

 

Lazy.

Audible.com — device activation problems — location matters

Note to self: Audible activation of devices — it matters where your computer thinks you are.

I don’t much like the service provided by audible.com — lots of DRM, inconvenience, and so on. But there is not much choice in the audiobook space. Librivox is excellent but perforce limited in what it can provide (I highly recommend anything read by Mark Nelson or Karen Savage).

So I recently wanted to activate an mp3 player — a Philips GoGear Raga, one of the earlier ones with the power button on top, much better than the crippled later ones (‘Raga 3’) which use the main stop/start button for power and are too slow in responding to button pushes to be fit for purpose. The earlier ones (this one is a ‘Raga 2’) were a useful, cheap, audible-enabled player.

Some background; I have an Audible username, not an Amazon account (the account is from before they were merged) and I am based in Australia.

  1. Updated Audible manager. This is Windows software. I use it about once a year so I always need a new version.
  2. Plugged in mp3 player. Selected it within Manager and selected ‘Activate’ from the Devices menu.
  3. Was sent to a webpage where I was to log in to Audible, but there was no option to put in an Audible username, only an Amazon account.
  4. Read lots of (so-called) ‘Help’ information. Nothing.
  5. Began a Chat with Audible staff.
  6. An hour was spent installing software, changing the default web browser from Firefox to IE, scratching heads, and so on.
  7. Turned out that this is the story: My Audible account is from before they had a presence in Australia and before they merged with Amazon. As a result, I need to log in to the US site, because the Australian one has no link for logging in via an Audible username. So…
  8. Went into computer settings and changed the location (and language, though probably not necessary) to ‘United States’. At this point the default browser was still changed to IE, though that is not important unless IE and Firefox use the locale information differently.
  9. Now tried to activate device. Was forwarded to a US website that did have the ‘log in with username’ (or whatever it was) option.
  10. Did so, and the device was activated.
  11. Changed computer settings back to what they were.

So, the upshot is that if you are trying to do something with an Audible username from outside the USA, but you are getting directed to a webpage that does not let you log in that way, pretending you are in the USA might be the solution to your problem.

Cheerio.

 

Backing up Audible content to mp3.

Getting lp, lpq and lpstat to work…

I want to be able to use lp and print from command line, not just from gui. My Linux box (Debian, running FLWM as window manager), prints fine from applications with print dialogues, for example LibreOffice or evince, but I want to be able to use lp, a2ps, maybe print from xFig, and these all use the lp command line interface, and that is not set up.

I know I can go ($ is command line prompt)

$ lpadmin -d [printer-name]

but what is ‘printer-name’? I have a couple of printers attached by USB, not network.

It’s actually very simple.

$ lpstat -a

FUJI_XEROX_DocuPrint_CP305_d accepting requests since Wed 02 Nov 2016 13:26:34 AEDT
HL5340D accepting requests since Wed 14 Dec 2016 17:33:54 AEDT
Stylus-TX100 accepting requests since Tue 13 Dec 2016 20:19:20 AEDT

$ lpadmin -d HL5340D

Bingo.

Wacom tablet, Debian, shenanigans.

Getting Wacom tablet to work…it ought to work out of the box, though my system is getting a little old… anyway, the details…

Wacom PTH-851 (Intuos Pro).

$ uname -a

Linux machinename 3.2.0-4-amd64 #1 SMP Debian 3.2.82-1 x86_64 GNU/Linux

Debian 7.xx, always kept pretty much up to date.

Don’t usually use gnome, but opened a gnome session and ran the ‘Wacom’ control panel GUI thing. Got:

‘No Tablet Detected’

OK.

$ lsusb | grep Wacom

Bus 002 Device 006: ID 056a:0317 Wacom Co., Ltd

So the USB device showed up (I am not using bluetooth).

$ xinput list

⎡ Virtual core pointer                        id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                    id=4    [slave  pointer  (2)]
⎜   ↳ Mouse USB Laser Mouse                         id=8    [slave  pointer  (2)]
⎣ Virtual core keyboard                       id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard                     id=5    [slave  keyboard (3)]
    ↳ Power Button                                    id=6    [slave  keyboard (3)]
    ↳ Power Button                                    id=7    [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard                    id=9    [slave  keyboard (3)]
    ↳ ACPI Virtual Keyboard Device                    id=10   [slave  keyboard (3)]

$ lsmod | grep wacom

No result.

So no kernel module.
Why not? All the Wacom packages are installed, according to apt-get…. Probably just not loading the module, but… Anyway…

$ cd installs/
$ mkdir wacom
$ cd wacom

Browsed to:

https://sourceforge.net/projects/linuxwacom/files/xf86-input-wacom/input-wacom/

and download the latest version.

$ tar xjvf input-wacom-0.32.0.tar.bz2
$ cd input-wacom-0.32.0/
$ ./configure
$ make
$ sudo make install

It said:

Warning: you may need to install module-init-tools

$ sudo apt-get install module-init-tools
Reading package lists... Done
Building dependency tree
Reading state information... Done
module-init-tools is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

OK, rebooted.

$ lsmod | grep acom
wacom                  56840  0
power_supply           13475  2 nouveau,wacom
usbcore               128741  6
ehci_hcd,xhci_hcd,usb_storage,usbhid,wacom

$ xinput list

⎡ Virtual core pointer                        id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                    id=4    [slave  pointer  (2)]
⎜   ↳ Mouse USB Laser Mouse                         id=8    [slave  pointer  (2)]
⎜   ↳ Wacom Intuos Pro L Pen stylus                 id=9    [slave  pointer  (2)]
⎜   ↳ Wacom Intuos Pro L Finger touch               id=10   [slave  pointer  (2)]
⎜   ↳ Wacom Intuos Pro L Pen eraser                 id=13   [slave  pointer  (2)]
⎜   ↳ Wacom Intuos Pro L Pen cursor                 id=14   [slave  pointer  (2)]
⎜   ↳ Wacom Intuos Pro L Pen pad                    id=15   [slave  pointer  (2)]
⎣ Virtual core keyboard                       id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard                     id=5    [slave  keyboard (3)]
    ↳ Power Button                                    id=6    [slave  keyboard (3)]
    ↳ Power Button                                    id=7    [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard                    id=11   [slave  keyboard (3)]
    ↳ ACPI Virtual Keyboard Device                    id=12   [slave  keyboard (3)]

And it worked!

And gone.

Using sed to crop bits of a PostScript file (Lord knows why)

I wanted to get the exact same bit from a lot (over 1000) of ps files. I’m sure there are better ways to do this — called ‘pscrop’, probably — but for some reason I did it as outlined below. First I converted all my ps to eps:

$ cat auto/pstoeps.sh
for f in *.ps;
do
ls $f
ps2epsi $f
done

then I created a little ‘new header’ with the bounding box I wanted (got bounding box coords from opening the file in gv):

$ cat auto/header.txt
%!PS-Adobe-2.0 EPSF-1.2
%%BoundingBox: 370 263 420 319
%%HiResBoundingBox: 370.0 263.0 420.0 319.0

Then I used sed to remove the old bounding box and header from all the many eps files, and then I replaced it with new bit

$ cat auto/extract.sh
for f in *.epsi;
do
ls $f
sed -i '/Bounding/d' $f
sed -i '/EPSF/d' $f
cat header.txt $f > extract_$f
done

(Note that this screws up the original eps(i) files, since ‘-i’ overwrites. Also, it deletes all lines with ‘Bounding’ or ‘EPSF’ in them; I checked that the ones I wanted to remove were the only ones in the file that had that text, but another file might coincidentally have that text in an important line, so care is required!)

so the top of the epsi file went from this:

%!PS-Adobe-2.0 EPSF-1.2
%%Title: 0.02_p02000.ps
%%Creator: Ghostscript ps2epsi from 0.02_p02000.ps
%%CreationDate: Oct 26 11:42
%%For:dgoossensdgoossens dgoossens
%%Pages: 1
%%DocumentFonts: Courier
%%BoundingBox: 5 6 566 565
%%HiResBoundingBox: 5.460047 6.860039 565.739983 564.339991
%%EndComments

%%BeginProlog

to this:

%!PS-Adobe-2.0 EPSF-1.2
%%BoundingBox: 370 263 420 319
%%HiResBoundingBox: 370.0 263.0 420.0 319.0
%%Title: 0.02_p02000.ps
%%Creator: Ghostscript ps2epsi from 0.02_p02000.ps
%%CreationDate: Oct 26 11:42
%%For:dgoossensdgoossens dgoossens
%%Pages: 1
%%DocumentFonts: Courier

%%BeginProlog

and rather than get the whole file, when I gv it I get a little window…

From this.

From this.

 

To this.

To this.

So yes, I’m sure there a better ways do do this, but this works pretty well. I can use various tools to them convert the eps file to some other format. All good. The handy thing about this method is you can fiddle with other bits of the file, like the metadata, duplexing instructions, font commands, and so on. A small change to the sed commands and rather than overwriting it is possible to create a new eps file, such that multiple bits could be cut from one file. And of course the whole point is that this is scriptable so I can do oodles of files. FWIW.

Avec.

Making movies using ppmtompg or whatever it is called.

Science and movies. A classic combination. I’m not talking science fiction, but actual science. As datasets get bigger and more and more imaging and modelling is done in three dimensions, being able to represent data graphically is more and more important. This is a problem for me because I am not really into computer graphics and the like — my scientific programming is all done in a text-based interface, with text files as inputs and outputs, and I do not have the time to spend learning GUI programming.

But, I do have some old PostScript routines that I use for printing stuff out when I have a simulation that is highly geometric in nature, for example something that involves atomic coordinates.

These routines are just old Fortran 77 subroutines, and I have bunged them up on the web for reference and because they are still kind of useful. [[I have also created a small program that uses them as a bit of a demo, but that is a story for another post, and not yet on the web.]]

So I can draw simple diagrams easily enough. But what if I want to make a movie? Well, there are two tools that I use for this, gifsicle and ppmtompeg. Here, I will outline how I use them.

Systematic naming of the input files is very important. Let’s say all my files have names of the form pXXXXX.ps, where XXXXX goes from 00001 to 99999. Now, the subroutine outputs them as PostScript files, so first I do some conversions. I use two steps. I’m sure you can do better. Here is my script, movieB.sh:

for f in *.ps;
do
ls $f
ps2epsi $f
done
for f in *.epsi;
do
ls $f
convert -alpha opaque $f $f.gif
convert $f $f.pnm
done
gifsicle --delay=10 --loop *.gif > myanimatedgif.gif
ppmtompeg mpeg.inp

So what happens here is that I convert all the PostScript files to encapsulated PostScript, then I convert them to GIF and also to PNM. I use two loops and keep all the intermediate files, for no good reason. Then I run gifsicle and produce my animated GIF, and I run ppmtompeg, which takes its input from mpeg.inp. Let’s have a look at that magical incantation:

PATTERN IBBPBBPBBPBBPBB
OUTPUT mympeg.mpg
INPUT_DIR .
INPUT
p*.epsi.pnm  [00001-02000]
END_INPUT
BASE_FILE_FORMAT PNM
INPUT_CONVERT *
GOP_SIZE 15
SLICES_PER_FRAME  1
PIXEL HALF
RANGE 3
PSEARCH_ALG LOGARITHMIC
BSEARCH_ALG SIMPLE
IQSCALE 3
PQSCALE 3
BQSCALE 3
REFERENCE_FRAME ORIGINAL
ASPECT_RATIO 1

Okay, so this is reading in PNM files, and note the wildcard format for the filenames, which is why I chose such a simple input filename format, and with a fixed number of characters. It is usually a lot easier if files are named ‘p00001.ps‘ to ‘p99999.ps‘ than ‘p1.ps‘ to ‘p99999.ps‘.

Most of the fields I don’t change. They may not be optimal but they work. I am not embedding an example because the files are too big and I don’t want to waste your bandwidth and mine.

Good advises. Real movies.

My Fortran rotating star and cost of screen output.

Ignore this post.

Got a Fortran program that does some numerical work and I just have it outputting a single character (‘-‘) to the screen each cycle, so I know it’s ticking along. It looks like this, sort of:

--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------> done
Whoa! Exciting.

Whoa! Exciting. This was made using gifsicle.

But I thought that was ugly, so I’ve got something much nicer now. You know how in some text-based programs the fact that it has not completely locked up is shown by having little rotating bar, made just by printing |, /, -, and \ in the same place one after the other? Well, this is one way to do it in Fortran (note, just a snippet, not a working program):

! declare array 'star()'

       character,dimension(1) :: star(4)     

       star(1) = '|'
       star(2) = '/'
       star(3) = '-'
       star(4) = '\'

!.
!.
!other code...
!.
!.

       do iloop=1,nloop
          write(6,'(a,a)',advance='no')achar(8),star(mod(iloop,4)+1)
!.
!.
!content of loop...
!.
!.
       end do

So all that this does is write an ‘achar(8)’ character to make the output backspace, use “advance=’no'” to avoid adding a line return, and use ‘mod’ to run through the four characters in the array over and over again.

‘achar(13)’ also works but only if you want to return to the beginning of the line and overwrite everything.

While thinking about this, I wondered: The loop is fairly big (searches some big arrays, does some calculations, works out an energy in a Monte Carlo simulation, that sort of thing) and so since this starry thing is the only screen output, I was wondering — how much does it cost in runtime?

using Gfortran, with -O2 optimisation. With and without the above ‘write’ statement, times are:

With:

 $ time ./Dom2016G_tests < inputsG 

real	2m50.757s
user	1m57.032s
sys	0m1.616s

Without:

real	2m49.191s
user	1m56.895s
sys	0m1.587s

So there we have it, a time cost (looking at the ‘user’ time) of less than 0.2s, and only about 0.1%. So I think I’ll keep it. It looks nice.

Oh, and making the animated gif: I made four little bitmaps by screen grabs from LibreOffice, all the same size, and called them a1.gif, a2.gif a3.gif and a4.gif. Then just this command line (I put loopcount in to stop it after a finite number of loops. –loop and it goes forever…):

gifsicle --loopcount=100 -d 30  a?.gif > star.gif

a2
a4a3
a1

 

 

 

 

 

Rubbish.