BSDaemon
2006-02-27
  Gone... This blog has been superseded by http://keramida.wordpress.com/

See you all there... 

2006-02-12
  Disabling boot0 stage beeps I don't really like hearing the loud PC-speaker 'beep' my laptop emits when I boot into FreeBSD's boot0 stage (the partition menu, with the F1, F2, ... F5 selection). Here's a little patch I use locally to disable this, in case someone else likes it too:
Index: sys/boot/i386/boot0/boot0.S
===================================================================
--- sys/boot/i386/boot0/boot0.S (revision 6)
+++ sys/boot/i386/boot0/boot0.S (revision 7)
@@ -199,11 +199,9 @@
                decw %si                        #  default
                callw putkey                    #  key
 /*
- * Start of input loop.  Beep and take note of time
+ * Start of input loop.  Take note of time
  */
-main.10:       movb $ASCII_BEL,%al             # Signal
-               callw putchr                    #  beep!
-               xorb %ah,%ah                    # BIOS: Get
+main.10:       xorb %ah,%ah                    # BIOS: Get
                int $0x1a                       #  system time
                movw %dx,%di                    # Ticks when
                addw _TICKS(%bp),%di            #  timeout
Use the link to download the patch from people.FreeBSD.org, but if you cannot do this and absolutely have to copy the patch from the listing above, then please remember to use the -l or --ignore-white-space option of the patch(1) utility (that's a lowercase "el" option), otherwise it may fail to apply cleanly. After you apply the patch in /usr/src/sys/boot/i386/boot0, rebuild the boot loaders, install them in /boot, and run boot0cfg to re-install the boot0 part in the MBR of your disks:
# cd /usr/src/sys/boot/
# make clean && make && make install
# boot0cfg -v -B ad0
That's all. You should be free from that annoying beep now :-) 
2006-01-27
  Will the Greek Government Sell out to Microsoft?

Kerdos (Κέρδος) on 27 Jan 2006 posted an article about a potential deal of the Greek government with Microsoft.

The article describes a "framework agreement" between the two parties involved, and implies that "such an agreement does not imply an obligation of the Greek government regarding the acquisition of software". Yeah right...

With a long history of Microsoft's closed, proprietary, unfree software that forces the users to compromise and deal with a vast array of problems (including, but not limited to, susceptibility to viruses, trojans, security problems, privacy problems and a lot more), the best thing we need right now is to force all the Greek people to buy Microsoft's software when they need to read official Greek government and state-related documents.

We, the Greek people, are already forced to use Microsoft's proprietary, closed documents formats if we want to gain access to important documents (like the results of the ASEP exams (διαγωνισμοί ΑΣΕΠ), which are distributed in Microsoft Excel format). This trend will only tend to increase if there's a deal between the Greek government and Microsoft.

We don't need any of that stuff. Public documents should be in open, freely distributable formats, that anyone can read. Access to public documents is not a privilege of only a percentage of the Greek people that have paid a hefty amount to Microsoft for buying their buggy, insecure word processors and spreadsheet applications. It is a right of every Greek citizen.

Can the Greek government guarantee that, even if it does strike a deal with Microsoft, public documents, web sites, and any other source of information of interest to Greek citizens will be available in open formats? I highly doubt it, but I'll be glad to be proven wrong.

 
2006-01-25
  Handling EOL whitespace in Emacs

One of the most useless artifacts of many text "editors", if I may call them "editors" at all, is that the hide things from you. Very often, one of the usual "bugs" is that their incomplete implementation of a proper line-wrapping algorithm depends on stupid hacks like spaces at the end of a line. To mask this fault in the editor's logic they complement this bug with more bugs, that inhibit the display of whitespace characters (SPACE and TAB) when they are the final characters of a line of text.

Emacs can be configured to display these trailing whitespace characters with a special "face" (font, size, color combination or one of a host of other attributes). My default .emacs file, for instance, enables this option too, with:

(setq show-trailing-whitespace t)

This shows the trailing whitespace characters in terminal or X11 sessions of Emacs. Here's what an example looks like:

The black rectangle at the line of f_sortacross is a lone SPACE character at the end of a line.

In text files that have been created by me, I usually trim these spaces, by hitting C-c w, implemented by the following Elisp snippet in my .emacs file:

(global-set-key "\C-cw" 'delete-trailing-whitespace)

The delete-trailing-whitespace function is a standard Emacs function, that has been a part of Emacs at least since version 21.X was released. It's just another one of those points that prove Emacs' developers have given a great deal of thought to implementing all the features a text editor should really have :-)

For those that are not already implemented in Emacs, a little Elisp goes a very long way too. For instance, how would one toggle between the display of eol whitespace characters, without affecting the file currently edited? There's no toggle-show-trailing-whitespace or similar function, even in the CVS version of Emacs.

No problem. Emacs is an extensible editor. This means we, its users, can actually add any features we find handy; very easily, seamlessly, as if they were part of Emacs since forever. After getting too tored of typing M-: (setq show-trailing-whitespace nil) RET or its inverse, I wrote my own:

;; A function for quickly toggling the display of trailing whitespace.
(defun toggle-trailing-whitespace-display ()
  "Toggle the display of trailing whitespace, by changing the
buffer-local variable `show-trailing-whitespace'."
  (interactive)
  (save-excursion
    (if show-trailing-whitespace
        (setq show-trailing-whitespace nil)
      (setq show-trailing-whitespace t))
    (force-window-update (current-buffer)))
  (message (concat "Display of EOL spaces "
                   (if show-trailing-whitespace
                       "enabled" "disabled"))))
;;
(setq show-trailing-whitespace t)
(global-set-key "\C-ce" 'toggle-trailing-whitespace-display)

Still, setting the default value of show-trailing-whitespace to my own personal preference, I can now toggle between showing the annoying eol whitespace characters and hiding it, by hitting a keyboard sequence that I find easy to remember: C-c e. Being very close to C-c w, the C-c e keyboard sequence can be found very quickly too. Just what I wanted all along.

The (message) invocation near the end of the toggle-trailing-whitespace-display function is not really necessary, but it still provides a nice way of notifying me that eol spaces are on or off when I hit C-c e, so I think I'll keep it there.

Update [30 Jan 2006]: Since show-trailing-whitespace is always bound to something, the toggling function can be simplified a bit, by replacing this part:

(if show-trailing-whitespace
    (setq show-trailing-whitespace nil)
  (setq show-trailing-whitespace t))

with a much cleaner version:

(setq show-trailing-whitespace
      (not show-trailing-whitespace))

which I now find easier to read. Just in case anyone wants to copy/paste this into their .emacs file, the full Elisp source for this is now:

;; A function for quickly toggling the display of trailing whitespace.
(defun toggle-trailing-whitespace-display ()
  "Toggle the display of trailing whitespace, by changing the
buffer-local variable `show-trailing-whitespace'."
  (interactive)
  (save-excursion
    (setq show-trailing-whitespace
          (not show-trailing-whitespace))
    (force-window-update (current-buffer)))
  (message (concat "Display of EOL spaces "
                   (if show-trailing-whitespace
                       "enabled" "disabled"))))
;;
(setq show-trailing-whitespace t)
(global-set-key "\C-ce" 'toggle-trailing-whitespace-display)
 
  Yet Another Emacs Tip

By default, when Emacs 22.X starts up inside an xterm (which is usually what I do), something like the following is displayed:

After typing some text with long lines, Emacs will wrap the text, adding a backslash to the end of the lines that have been continued on the next line:

Sometimes, i.e. when I'm reading log files, I don't want lines to mix and wrap like this:

A small snippet of Elisp in my Emacs startup file takes care of these very nicely:

;; Truncating of long lines is turned off by default, but I may want to
;; quickly toggle it back on with C-c t.
(setq truncate-lines nil)
(global-set-key "\C-ct" 'toggle-truncate-lines)

The default is unconditionally set to not wrap the text, but I can use C-c t to quickly toggle between the two modes, as necessary :-)

 
2006-01-09
  Rot-13 in Common LISP This weekend's LISP experiment was to implement a rot-13 function that would let me type things like:
(rot-13 "Hello world")
(rot-13 (map 'vector #'identity "Hello world"))
(rot-13 (map 'list #'identity "Hello world"))
I started out trying to build an expression that would return an association-list of all the lowercase characters and their rot-13 equivalent:
* (let ((alpha "abcdefghjiklmnopqrstuvwxyz"))
           (let ((len (length alpha)))
             (loop for x below len
                   collect (list (char alpha x)
                                 (char alpha x)))))

((#\a #\a) (#\b #\b) (#\c #\c) (#\d #\d) (#\e #\e) (#\f #\f) (#\g #\g)
 (#\h #\h) (#\j #\j) (#\i #\i) (#\k #\k) (#\l #\l) (#\m #\m) (#\n #\n)
 (#\o #\o) (#\p #\p) (#\q #\q) (#\r #\r) (#\s #\s) (#\t #\t) (#\u #\u)
 (#\v #\v) (#\w #\w) (#\x #\x) (#\y #\y) (#\z #\z))
But this isn't right. We want for every element of "alpha" to find the value of the character 13 positions after it, wrapping around at the end of "alpha". I wrote a little #'foo function to test this for one character:
* (defun foo (x)
    (let ((alpha "abcdefghjiklmnopqrstuvwxyz"))
      (list (char alpha x)
            (char alpha (mod (+ x 13) (length alpha))))))

FOO
Testing that (foo NUM) works is easy:
* (foo 0)

(#\a #\n)
* (map 'list #'foo (loop for x below 26 collect x))

((#\a #\n) (#\b #\o) (#\c #\p) (#\d #\q) (#\e #\r) (#\f #\s) (#\g #\t)
 (#\h #\u) (#\j #\v) (#\i #\w) (#\k #\x) (#\l #\y) (#\m #\z) (#\n #\a)
 (#\o #\b) (#\p #\c) (#\q #\d) (#\r #\e) (#\s #\f) (#\t #\g) (#\u #\h)
 (#\v #\j) (#\w #\i) (#\x #\k) (#\y #\l) (#\z #\m))
*
So, it seems we have the beginnings of a function that can map #\a to #\n, #\b to #\o, etc. But our current #'foo needs to be passed the index of the character in a string that we don't know anything about. Using this particular #'foo function would "leak information" about its internal implementation details. The best thing would be to embed something like the (map) call shown above into #'foo itself and let it do all the work of iterating over "alpha". After a bit of experimentation, until I got the loop statement right, the following seemed to be good enough:
* (defun foo ()
    (let ((alpha "abcdefghjiklmnopqrstuvwxyz"))
           (let ((len (length alpha)))
             (loop for x below len
                   collect (list (char alpha x)
                                 (char alpha (mod (+ x (/ len 2)) len)))))))

FOO
* (foo)

((#\a #\n) (#\b #\o) (#\c #\p) (#\d #\q) (#\e #\r) (#\f #\s) (#\g #\t)
 (#\h #\u) (#\j #\v) (#\i #\w) (#\k #\x) (#\l #\y) (#\m #\z) (#\n #\a)
 (#\o #\b) (#\p #\c) (#\q #\d) (#\r #\e) (#\s #\f) (#\t #\g) (#\u #\h)
 (#\v #\j) (#\w #\i) (#\x #\k) (#\y #\l) (#\z #\m))
* 
Excellent. Now can we do the same for caps? Sure thing :)
* (defun bar ()
    (let ((alpha "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
           (let ((len (length alpha)))
             (loop for x below len
                   collect (list (char alpha x)
                                 (char alpha (mod (+ x (/ len 2)) len)))))))

BAR
* (bar)

((#\A #\N) (#\B #\O) (#\C #\P) (#\D #\Q) (#\E #\R) (#\F #\S) (#\G #\T)
 (#\H #\U) (#\I #\V) (#\J #\W) (#\K #\X) (#\L #\Y) (#\M #\Z) (#\N #\A)
 (#\O #\B) (#\P #\C) (#\Q #\D) (#\R #\E) (#\S #\F) (#\T #\G) (#\U #\H)
 (#\V #\I) (#\W #\J) (#\X #\K) (#\Y #\L) (#\Z #\M))
* 
Combining these two in a single (defparameter) call that sets up a special map we can use later can then be very easy:
* (defparameter *rot-13-map* (nconc (foo) (bar)))

*ROT-13-MAP*
* *rot-13-map*

((#\a #\n) (#\b #\o) (#\c #\p) (#\d #\q) (#\e #\r) (#\f #\s) (#\g #\t)
 (#\h #\u) (#\j #\v) (#\i #\w) (#\k #\x) (#\l #\y) (#\m #\z) (#\n #\a)
 (#\o #\b) (#\p #\c) (#\q #\d) (#\r #\e) (#\s #\f) (#\t #\g) (#\u #\h)
 (#\v #\j) (#\w #\i) (#\x #\k) (#\y #\l) (#\z #\m) (#\A #\N) (#\B #\O)
 (#\C #\P) (#\D #\Q) (#\E #\R) (#\F #\S) (#\G #\T) (#\H #\U) (#\I #\V)
 (#\J #\W) (#\K #\X) (#\L #\Y) (#\M #\Z) (#\N #\A) (#\O #\B) (#\P #\C)
 (#\Q #\D) (#\R #\E) (#\S #\F) (#\T #\G) (#\U #\H) (#\V #\I) (#\W #\J)
 (#\X #\K) (#\Y #\L) (#\Z #\M))
* 
Now, let's check if it works...
* (assoc #\a *rot-13-map*)

(#\a #\n)
* 
Of course it does :-) A short while later, combining what I had found out about *rot-13-map*, the way it can be created and a few MAP/TYPE_OF calls, I had the following implementation of ROT-13:
(defparameter *rot-13-map*
  (nconc (let ((alpha "abcdefghjiklmnopqrstuvwxyz"))
           (let ((len (length alpha)))
             (loop for x below len
                   collect (list (char alpha x)
                                 (char alpha (mod (+ x (/ len 2)) len))))))
         (let ((alpha "ABCDEFGHJIKLMNOPQRSTUVWXYZ"))
           (let ((len (length alpha)))
             (loop for x below len
                   collect (list (char alpha x)
                                 (char alpha (mod (+ x (/ len 2)) len))))))))

(defun rot-13 (sequence)
  (when sequence
    (map (type-of sequence)
         #'(lambda (ch)
             (let ((ch13 (assoc ch *rot-13-map*)))
               (if ch13 (cadr ch13) ch)))
         sequence)))
A trick that I also learned while writing this is TYPE-OF, which the top-level MAP call uses to makes sure that this function will return a sequence of the same type as the input sequence, i.e.:
* (rot-13 "Hello world")

"Uryyb ibeyq"
* (rot-13 (map 'vector #'identity "Hello world"))

#(#\U #\r #\y #\y #\b #\  #\i #\b #\e #\y #\q)
* (rot-13 (map 'list  #'identity "Hello world"))

#(#\U #\r #\y #\y #\b #\  #\i #\b #\e #\y #\q)
* 
(#\U #\r #\y #\y #\b #\  #\i #\b #\e #\y #\q)
* 
Now, if you had as much fun reading this, as I had writing it, go forth and #'rot-13 :-) 
2006-01-05
  Which Discworld Character Are You Like?

You scored as Lord Havelock Vetinari.

Which Discworld Character are you like (with pics)
created with QuizFarm.com
 
  I have LISP Thanks to the absolutely fantastic help of Fred Gilham, I have a CMUCL binary that runs (with 32-bit emulation) on FreeBSD/amd64. Magnificent! Astounding!
keramida@flame:/home/keramida$ file ‘which lisp‘
/usr/local/bin/lisp: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), for FreeBSD 6.0 (600100), dynamically linked (uses shared libs), not stripped
keramida@flame:/home/keramida$ lisp
CMU Common Lisp 19c Release (19C), running on flame.pc
With core: /usr/local/lib/cmucl/lib/lisp.core
Dumped on: Wed, 2005-11-30 01:04:28+02:00 on boomerang
See <http://www.cons.org/cmucl/> for support information.
Loaded subsystems:
    Python 1.1, target Intel x86
    CLOS based on Gerd's PCL 2004/04/14 03:32:47
* (let ((msg "Thanks Fred!"))
    (format t "~&~A" msg))

Thanks Fred!
NIL
* 
 
2006-01-04
  Recent Emacs CVS changes Recently, two Emacs changes were committed that improve the state of CVS-Emacs on FreeBSD. My patch for building Emacs on FreeBSD/amd64 was approved by RMS and committed. Then a second patch, by Stefan Monnier, inspired by a thread in the emacs-devel list, made it possible to run Emacs in FreeBSD console terminals without a block cursor. Now, CVS-Emacs can run on a FreeBSD console tty using the system setting for the cursor, by setting visible-cursor to nil in the startup file of Emacs:
(setq visible-cursor nil)        ;Don't force a block cursor
This removes the last set of diffs I had to maintain locally for CVS-Emacs, and I can build everything using a clean checkout from savanna.gnu.org. Hurray! 
  Iterating in LISP There are countless ways to iterate with the loop macro of Common LISP. I am only beginning to learn how it all works, but it's fun seeing that I can almost without a second thought type loops like the ones below in an Emacs buffer and have them immediately work in SLIME/CMUCL:
* (loop for x below 10
       with e = nil
       with o = nil
       do (if (evenp x)
              (push x e)
            (push x o))
       finally (return (values (nreverse o)
                               (nreverse e))))

(1 3 5 7 9)
(0 2 4 6 8)
* (loop for x from 0 to 10 by 2
       for y from 1 to 10 by 2
       with e = nil
       with o = nil
       do (push x e)
       do (push y o)
       finally (return (values (nreverse o)
                               (nreverse e))))

(1 3 5 7 9)
(0 2 4 6 8)
*
Here's another slightly more complex example:
* (loop for x below 100
        with fours = nil
        with fives = nil
        with tens = nil
        do (when (= 0 (mod x 4))
             (push x fours))
        do (when (= 0 (mod x 5))
             (push x fives))
        do (when (= 0 (mod x 10))
             (push x tens))
        finally (return (values (nreverse fours)
                                (nreverse fives)
                                (nreverse tens))))

(0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96)
(0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95)
(0 10 20 30 40 50 60 70 80 90)
* 
and a more compact way to achieve the same result can be written by combining "when" with "collect .. into":
* (loop for x below 100
        when (= 0 (mod x 4)) collect x into fours
        when (= 0 (mod x 5)) collect x into fives
        when (= 0 (mod x 10)) collect x into tens
        finally (return (values fours fives tens)))

(0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96)
(0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95)
(0 10 20 30 40 50 60 70 80 90)
* 
 

Όνομα: keramida
Τοποθεσία: Patras, Greece
ARCHIVES
2005-10 / 2005-11 / 2005-12 / 2006-01 / 2006-02 /


I READ

Powered by Blogger