November 2009 Archives

For quote some time I have been using x2x to have single keyboard and mouse for multiple machines (EeePC or third monitor at work), but I had problem with selection buffers. x2x was written for scenario where all X servers are listening to network connections, so if you had two machines klin and t42 and you wanted to use keyboard and mouse on klin you would have to do something like this:

dpavlin@t42:~$ xhost klin

dpavlin@klin:~$ x2x -to klin:0 -west
However, recent Debian systems are not listening to TCP connections, so you will have to modify xserverrc for this to work:
dpavlin@t42:~$ cat /etc/X11/xinit/xserverrc 
#!/bin/sh

exec /usr/bin/X11/X #-nolisten tcp
However, it's much nicer to depend on ssh X11 forwarding to provide encryption using:
dpavlin@klin:~$ ssh -X t42 x2x -to :0 -west
To finish this post, I have to include small patch which allows to switch copy/paste direction (which I don't need any more, but it proved useful in at least one case):
diff -r 2ce6789a43da x2x.c
--- a/x2x.c     Tue Mar 18 22:47:34 2008 +0600
+++ b/x2x.c     Tue Nov 24 14:08:16 2009 +0100
@@ -1125,7 +1125,7 @@
       if (doSel) {
         // pDpyInfo->initialClipboardSeen = False;
         pDpyInfo->winSelText = NULL;
-        pDpyInfo->hwndNextViewer = SetClipboardViewer(pDpyInfo->edgewindow);
+        pDpyInfo->hwndNextViewer = SetClipboardViewer(pDpyInfo->bigwindow);
       }
 
       pDpyInfo->onedge = 0;

If you have any objection your X11 setup (especially if you are not running Gnome or KDE) it's probably: Firefox menu font size is too big! However, that's really not right complaint. If you create your own userChrome.css and install it in correct location, you will notice that rest of applications still won't look good. But, Firefox was biggest problem, so you move on...

But, solution is really simple:

dpavlin@t61p:~$ cat .gtkrc-2.0 
gtk-font-name = "Verdana 7"
This will change all GTK application's (including FIrefox, OpenOffice.org and others) to sane font size for huge monitors with high DPI settings. It's a single line fix to all your problems!, take a look: gtk-font-change.png

One of first differences when you start using X11 is that you can just select any text on screen and press middle mouse button to paste it back. But, after a while you end up in situation where you did ctrl+c in application, and somehow you expect that middle mouse button will paste it back.

X11 implementation of copy/paste is much more complicated, as you might read from excellent X Selections, Cut Buffers, and Kill Rings.

Most of the time, having two different clipboards is very useful. Think about copy/pasting url and title at the same time from one web page to another (like I do often when writing blog posts like this one).

So, how to we manage buffers more efficiently? First, install xclip and try it out:

dpavlin@t61p:~$ xclip -h
Usage: xclip [OPTION] [FILE]...
Access an X server selection for reading or writing.

  -i, -in          read text into X selection from standard input or files
                   (default)
  -o, -out         prints the selection to standard out (generally for
                   piping to a file or program)
  -l, -loops       number of selection requests to wait for before exiting
  -d, -display     X display to connect to (eg localhost:0")
  -h, -help        usage information
      -selection   selection to access ("primary", "secondary", "clipboard" or "buffer-cut")
      -noutf8      don't treat text as utf-8, use old unicode
      -version     version information
      -silent      errors only, run in background (default)
      -quiet       run in foreground, show what's happening
      -verbose     running commentary
Help output is probably a little verbose, but just remember following things:
  • -in is default
  • -out displays content
  • default selection is primary (which is content you marked on screen)
  • -selection clipboard is only other thing you need to rember
So, armed with that knowledge, here are couple of examples:
# display selected text
xclip -out

# display clipboard (copy/paste in applications)
xclip -out -selection clipbaord

# transfer selection into copy/paste buffer
xclip -out | xclip -selection clipboard

# transfer selection into copy/paste buffer
xclip -out -selection clipboard | xclip
Last example is useful if you want to paste something back in terminal and it somehow ended up in copy/paste buffer, following is Zotero example: zotero-copy-to-clipboard.png

Just let your imagination go wild: what if you have only textarea and you want to do some massive editing for which vi whould be better? You can install excellent It's All Text! Firefox extension but, you could also write something like this:

xclip -out > /tmp/$$.txt && vi /tmp/$$.txt && xclip -in -selection clipboard < /tmp/$$.txt
You could bind that to a key in your window manager or start different editor if you wanted to... or I guess live can be simple again if you just install autocutsel

Few days after I wrote this blog post, I had interesting problem. I was trying to decrease font size in firefox and I found instructions which included filename and content itself. I copied content with Ctrl+C and selected filename and used this little gem:

xclip -sel clipboard -out > `xclip -out`

MARC is binary structured file format used in libraries and occasionally you need a way to quickly edit records in it.

There are quite a few tools available for editing MARC records, but none of them are really easy to use. Few days ago, I overheard conversation in which somebody said you can't just edit in your editor, because you have to fix leader field afterward. That got me thinking...

MARC format is really quite interesting, designed to be easily used on tapes, so it has a bunch of pointers to exact record positions which change if size of field values change.

Editing binary MARC directly in editor isn't really possible because you would have to fix leader (which has size of whole record which allows easy skipping on tape) and all pointers to start of each field manually. I did some of that while writing MARC::Fast, but I wouldn't recommend that to anyone.

MARC::Record already has utility called marcdump which will convert MARC into human readable format:

dpavlin@t61p:/srv/webpac2$ marcdump t/data/marc.iso > dump.txt
t/data/marc.iso
dpavlin@t61p:/srv/webpac2$ head dump.txt 
LDR 01002nam0 2200289   45  
001     800328901
100    _a19800328d1999       y0hrvy0191    ba
101 1  _ahrv
102    _aHR
105    _aa   m   000yy
200 1  _aMjerne nesigurnosti rezultata mjerenja odstupanja od oblika i polo`aja
       _emagistarski rad
       _fZdravko Bar{i}
       _gvoditelj Vedran Mudronja

I can easily edit this in my favorite editor (which is vim if you really wanted to know) to replace CROASCII characters with utf-8 equivalents of something like that.

So, I wrote dump2marc which parse marcdump output and converts it back to MARC file format like this:

dpavlin@t61p:/srv/webpac2$ ./bin/dump2marc.pl dump.txt > dump.marc
It will also dump parsed records to STDERR which you can redirect to file using 2>dump.txt.parsed.

If you dump generated MARC with marcdump you can use diff to view changes:

dpavlin@t61p:/srv/webpac2$ ./bin/dump2marc.pl dump.txt > dump.marc \
  && marcdump dump.marc > dump.marc.txt \
  && diff -u dump.txt dump.marc.txt

If we wanted to track changes, add dump file (and MARC if needed) to git and using it to produce diffs would be one possible solution. I know that by this point, you are already rolling your eyes thinking: this is command line editing for MARC.

Same work-flow could be turned into web application using simple upload button to upload MARC, and then opening textarea with dump which is converted back to MARC ready to download after submit. It would be sane to automatically add every revision to git on server-side and provide some kind of rollback to some last version over git too, maybe over gitweb?

About this Archive

This page is an archive of entries from November 2009 listed from newest to oldest.

October 2009 is the previous archive.

December 2009 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Pages

  • pics
OpenID accepted here Learn more about OpenID
Powered by Movable Type 5.04