dimanche 2 septembre 2018

Test if your microphone input is working from the command line on Linux

arecord -vv /dev/null

That's it. Now clap your hand and observe the ascii vumeter.

mercredi 25 juillet 2018

Inspecting an Atari ST hard disk image with Unix / Linux tools

GNU libparted has Atari partition table support since two years ago. For this you will need the disktype and parted programs. Any good Unix should have those (I use Debian GNU/Linux)

Let us try this with a disk image I used for my Ultrasatan device, for example st_mint
wget http://www.subsole.org/static/retrocomputing/st_mint-0.7.img.zip
Unzip the disk image
unzip st_mint-0.7.img.zip
 Inspect the diskimage with the disktype program, an excellent disk analysis tool.
disktype st_mint-0.7.img

--- st_mint-0.7.img
Regular file, size 600 MiB (629145600 bytes)
ATARI ST partition map
Partition 1: 128.0 MiB (134201344 bytes, 262112 sectors from 4, bootable)
  Type "BGM" (Big GEMDOS)
  FAT16 file system (hints score 3 of 5, ATARI ST bootable)
    Unusual sector size 4096 bytes
    Volume size 127.9 MiB (134119424 bytes, 16372 clusters of 8 KiB)
Partition 2: 384.0 MiB (402666496 bytes, 786458 sectors from 262116)
  Type "MIX" (Unknown)


Notice the two partitions, first one is of type BGM, the second one is a Minix partition.

Print the partition table parted (this will output some warnings if running as non-root)
parted st_mint-0.7.img print
Partition Table: atari
Disk Flags: 

Number  Start  End    Size   Type     File system  Flags
 1      2048B  134MB  134MB  primary               boot
 2      134MB  537MB  403MB  primary

 Print the partition table with the begin and end of each partition being printed in bytes we will need this to create the loopback devices
parted  st_mint-0.7.img -- unit b print
Partition Table: atari
Disk Flags: 

Number  Start       End         Size        Type     File system  Flags
 1      2048B       134203391B  134201344B  primary               boot
 2      134203392B  536869887B  402666496B  primary

 Now using the beginning and end of each partition in bytes from the line above, create the /dev/loop devices corresponding to each partition:
sudo losetup --find --offset 2048 --sizelimit 134201344 --verbose st_mint-0.7.img

This should give a loopback device
losetup --all
/dev/loop3: []: (/home/manu/Téléchargements/st_mint-0.7.img), offset 2048, sizelimit 134201344
Now let us do a file check on the partition
sudo fsck.vfat /dev/loop3 
fsck.fat 4.1 (2017-01-24)
/dev/loop3: 217 files, 966/16372 clusters
and mount it
sudo mount /dev/loop3 /mnt

looks an Atari ST system inside
ls /mnt
APPS  CBHD502   CLIPBRD  FSELECT.INF  MICO  MULTITOS     TOOLS
AUTO  CBHD.SYS  CRIPPLE  HUSHI.SYS    MINT  NEWDESK.INF 
 
file /mnt/APPS/QED/QED.APP 
/mnt/APPS/QED/QED.APP: Atari ST M68K contiguous executable (txt=189972, dat=16234, bss=103214, sym=0)

when your work is finished, unmount the partition and detach the loop device from the disk image
sudo umount /mnt
sudo losetup --detach /dev/loop3 

vendredi 20 juillet 2018

Generating a visual history of a git repo

If you haven't met it yet the gource programm really rocks: it generates a OpenGL rendered graph of all the commits of a git project.

You can see the video on real time just by calling the command gource in your git repo, or generate a video of it by piping to ffmpeg

This is the command line I used to generate my own video:

gource --hide filenames --hide files --title "the history of pmc" -s 0.1 --highlight-users -1280x720 -o - | ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i - -vcodec libx264 -preset ultrafast -pix_fmt yuv420p -crf 1 -threads 0 -bf 0 gource.mp4

lundi 26 juin 2017

Java DOM from XML is not namespace aware by default

Something which costed me a couple of headaches using getElementsByTagNameNS with a DocumentBuilderFactory from the java.xml.parsers package.

You find in the class properties:

    private boolean namespaceAware = false;

and I thought XML namespaces where the bread and butter of XML ...

So when building a DOM from an XML document you need to change the defaults of the factory like:

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder docBuilder = factory.newDocumentBuilder();

vendredi 23 juin 2017

Shell looping vs xargs

For a very long time I was using the following construct to execute a command on foo, bar, and baz (all typed into an interactive shell prompt)

for F in foo bar baz; do command $F ; done

Now I finally got the -n option of xargs (or --max-args if you're using GNU) which limits to number of parameters to pass to the next command. So i can replace the previous command with:

echo foo bar baz | xargs -n 1 command

Here the -n option tells xargs to give at max one parameter to proceed, and create a new command with the next parameter.

As a bonus, instead of constructing an array of numbers with

seq 1 10

don't forget bash and zsh brace expansion

{1..10}

vendredi 16 juin 2017

Tomcat7 not starting after Jessie->Stretch ugrade

I was wondering why the tomcat7 debian package would not start after the upgrade.

systemctl status tomcat7 output would look quite OK

systemctl status tomcat7
● tomcat7.service - LSB: Start Tomcat.
   Loaded: loaded (/etc/init.d/tomcat7; generated; vendor preset: enabled)
   Active: active (exited) since Fri 2017-06-16 10:10:34 CEST; 29min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 536 ExecStart=/etc/init.d/tomcat7 start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/tomcat7.service

Jun 16 10:10:34 new-ada systemd[1]: Starting LSB: Start Tomcat....
Jun 16 10:10:34 new-ada systemd[1]: Started LSB: Start Tomcat..
Jun 16 10:10:34 new-ada tomcat7[536]: Starting Tomcat servlet engine: tomcat7start-stop-dae…tory)
Jun 16 10:10:34 new-ada tomcat7[536]:  (already running).
Hint: Some lines were ellipsized, use -l to show in full.

But not java process was created

pgrep -lf java
echo $?

so something was obviously wrong.

But the devil is in the details, can you see this truncated line ?

Jun 16 10:10:34 new-ada tomcat7[536]: Starting Tomcat servlet engine: tomcat7start-stop-dae…tory)

If you run it in full with systemctl status -l tomcat7 it expends to

Jun 16 10:10:34 new-ada tomcat7[536]: Starting Tomcat servlet engine: tomcat7start-stop-daemon: unable to stat /usr/lib/jvm/java-7-openjdk-amd64//bin/java (No such file or directory)

Now I get it, the upgrade removed the openjdk-7-jre-headless package.Time to switch to openjdk8 ! The package openjdk-8-jre-headless was already installed, so I justed needed to set JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/ in /etc/default/tomcat7

Note for the future:

  • Why was this package removed ?
  • Should I configure the systemctl status to show ellipsized lined by default ?

jeudi 15 juin 2017

Render HTML from standard input with w3m

From a very long time, I was using the links browser as my default browser. It allows quick testing of a web site with a simple

links -dump debian.org

Alas links does not support rendering html from standard input, so I finally switched to w3m, handles that well. So I could do:

cat bla.html | w3m -T text/html -dump

Using curl and any member of the Unix Toolkit gang, you see which possibilities it opens. Oh and UTF-8 works well too !

links -dump https://www.debian.org/index.ru.html | grep свободная
Debian — это свободная операционная система (ОС) для вашего компьютера.

свободная that’s Russian for Free.