Some random code of mine you may find useful or amusing. All this code is either GPLed or LGPLed. Although some bits of this code are updated rather frequently, no effort is made to keep everything up to date, thus a lot of what follows may suffer from byte decay, a desease more common than tooth decay.
;;; ;;; Sample milter that gathers statistics about number of messages and ;;; their size. Add this line to your sendmail.mc: ;;; ;;; INPUT_MAIL_FILTER(`myfilter', `S=inet:20025@localhost, F=T') ;;; (use-package :milter) ;; in our own cosy private lexical scope we keep track of the overall ;; statistics (let ((message-counter 0) (byte-counter 0)) ;; we specialise the context to add the byte count per message (defclass my-context (milter-context) ((byte-count :accessor ctx-byte-count))) ;; here we add up the byte count per message (defmethod handle-event ((e event-body) (ctx my-context)) (incf (ctx-byte-count ctx) (length (event-body-data e))) keep-going) ;; at the beginning of each message we reset the counter (defmethod handle-event ((e event-mail) (ctx my-context)) (setf (ctx-byte-count ctx) 0) keep-going) ;; at the end of the message we update the global statistics and ;; print a brief report of the situation so far (defmethod handle-event ((e event-end-of-message) (ctx my-context)) (incf byte-counter (ctx-byte-count ctx)) (incf message-counter) (format t "~ ~:R message of ~A byte~:P~%~ the messages seen so far total ~A byte~:P~%~ for an average of ~A byte~:P per message~%" message-counter (ctx-byte-count ctx) byte-counter (round byte-counter message-counter)) (finish-output) accept)) ;; we need to know about body events to get the body length (setf demyltify:*required-events* '(:mail :body)) ;; start the milter server loop (start-milter 20025 :context-class 'my-context))Tested on SBCL, CMUCL and CLISP. Requires net4cl.
CLPMR provides the same functionalities as procmail but with much more flexibility and simplicity due to the fact that the language you describe the rules with is Lisp and not some obscure sequence of characters looking like line noise. Using Lisp, it means that the implementation of things like mailing list servers and document servers becomes trivial and you don't even need external programs (see this example). MIME content is handled natively as well.
To compile CLPMR you need a handful of Common Lisp libraries
from this page
(mime4cl, net4cl,
smtp4cl and sclf)
and CMUCL. It doesn't depend on external C libraries.
getcap primitive. Some other common
primitives are provided (goto, put); see the end of the file.
pack-op which creates
an archive (by default a tar archive) of all the files in the
system
tag-op which creates an Emacs/Vi tags
file
stat-op which prints some figures about
the system files (from Unix wc)
make-exe-op which writes an executable file
containing all the necessary modules required to run the
system (it works on SBCL and CMUCL, but for the latter you
may need my executable.lisp)
revert-op which removes the files produced by
another operation; by default it reverts the compilation,
which means the x86f/fasl files
make-exe-op was broken until
recently.
CL-USER> (with-open-file (stream #P"./sample.tiff"
:element-type '(unsigned-byte 8))
(tiff::print-tiff-tags (tiff:parse-tiff stream)))
IFD 0:
COMPRESSION = :JPEG
ORIENTATION = 1
X-RESOLUTION = 72
Y-RESOLUTION = 72
RESOLUTION-UNIT = :INCH
JPEG-INTERCHANGE-FORMAT = 7060
JPEG-INTERCHANGE-FORMAT-LENGTH = 9665
Y-CB-CR-POSITIONING = :COSITED
IFD 1:
MAKE = "Panasonic"
MODEL = "DMC-FZ7"
ORIENTATION = 1
X-RESOLUTION = 72
Y-RESOLUTION = 72
RESOLUTION-UNIT = :INCH
SOFTWARE = "Ver.1.0 "
DATE-TIME = "2008:09:12 14:10:48"
Y-CB-CR-POSITIONING = :COSITED
EXIF-IFD:
EXPOSURE-TIME = 1/100
F-NUMBER = 4
EXPOSURE-PROGRAM = :NORMAL
ISO-SPEED-RATINGS = 80
EXIF-VERSION = (2 . 20)
DATE-TIME-ORIGINAL = "2008:09:12 14:10:48"
DATE-TIME-DIGITIZED = "2008:09:12 14:10:48"
COMPONENTS-CONFIGURATION = #(1 2 3 0)
COMPRESSED-BITS-PER-PIXEL = 4
EXPOSURE-BIAS-VALUE = 0
MAX-APERTURE-VALUE = 3
METERING-MODE = :PATTERN
LIGHT-SOURCE = NIL
FLASH = (:FLASH-DISABLED)
FOCAL-LENGTH = 12
FLASHPIX-VERSION = (1 . 0)
COLOR-SPACE = 1
PIXEL-X-DIMENSION = 2816
PIXEL-Y-DIMENSION = 2112
SENSING-METHOD = :ONE-CHIP-COLOR-AREA
FILE-SOURCE = :DSC
SCENE-TYPE = :DIRECT
CUSTOM-RENDERED = NIL
EXPOSURE-MODE = :AUTO
WHITE-BALANCE = :AUTO
DIGITAL-ZOOM-RATIO = NIL
FOCAL-LENGTH-IN-35MM-FILM = 72
SCENE-CAPTURE-TYPE = :STANDARD
GAIN-CONTROL = NIL
CONTRAST = :NORMAL
SATURATION = :NORMAL
SHARPNESS = :NORMAL
CL-USER> (format nil "~32B" (ie3fp:encode-ieee-float -123.456)) "11000010111101101110100101111001" CL-USER> (ie3fp:decode-ieee-float #B11000010111101101110100101111001) -123.456
.emacs file:
(defun cl-indent-be (path state indent-point sexp-column normal-indent) (let ((sexp-start (cadr state)) (current-position (point))) (save-excursion (let ((calculate-indentation (lambda (var-indent val-indent) (let ((i 0)) (+ sexp-column (catch 'return (condition-case nil (while (< (point) current-position) (while (forward-comment 1)) (cond ((and (= 1 (logand i 1)) (looking-at "[\t\n ]*\\s(")) (throw 'return 2)) (t (setq i (1+ i)) (forward-sexp)))) (error nil)) (if (= 1 (logand i 1)) val-indent var-indent))))))) (goto-char sexp-start) (forward-char) (let ((tag (symbol-at-point))) (cond ((eq tag 'be) (funcall calculate-indentation 4 6)) ((eq tag 'be*) (funcall calculate-indentation 5 7)) ;; I couldn't quite understand the logic of ;; common-lisp-indent-function-1 but for some reason ;; the current function can be called to indent forms ;; it wasn't written for. In those cases just return ;; NIL. (t nil))))))) (put 'be 'common-lisp-indent-function 'cl-indent-be) (put 'be* 'common-lisp-indent-function 'cl-indent-be) (put 'awhen 'lisp-indent-function 1) (put 'gcase 'lisp-indent-function 1) (put 'acase 'lisp-indent-function 1) (put 'acond 'lisp-indent-function 1) (put 'until 'lisp-indent-function 1)
iconv library
that lets Common Lisp programs translate byte sequences
from/to different character sets, like this:
(cliconv:iconv (map '(vector (unsigned-byte 8)) #'char-code
"François, piña, böse, skøl")
:ISO-8859-1 :UTF-8)
This package uses UFFI, so it should be fairly portable.
CL-USER> (asdf:oos 'asdf:load-op :currensea) ; [...] NIL CL-USER> (currency:get-quote "USD") 1.2057 CL-USER> (currency:exchange-rate "JPY" "USD") 0.0084 CL-USER> (currency:convert-currency 10000 "BMD" "CNY") 80623.0 CL-USER>
Here is an example:
(ods4cl:make-spreadsheet #P"/tmp/foo.ods" '(("My Sheet" (a b c) (1.2 3.4 5.6) ("foo" "bar" "baz"))))
daemon# ppplog.scm 24/9 01:59:57 12M 8M 25/9 00:26:10 3M 2M 26/9 01:02:01 13M 1M 27/9 02:18:18 14M 4M 28/9 00:31:47 5M 2M 29/9 00:54:41 8M 3M
.forward file will do:
"| /path/to/spmr"where spmr is the trampoline program.
spmr.image should be installed in the same
place as the trampoline.
*max-procs*.
See the .update-cvs file.
stty)
you get a neat summary of what's going on.
(map [/ _ 2] '(2 4 6 8 10)) (cond ((regexp-exec re str) => [match:substring _ 1]) ...)instead of
(map (lambda (x) (/ x 2)) '(2 4 6 8 10)) (cond ((regexp-exec re str) => (lambda (m) (match:substring m 1))) ...)Disclaimer: I am not advocating Perl-ish syntactic crypticism. This has been written just as a funny exercise in Scsh hacking.
(defun lisp-insert-lambda () "Insert lambda form at point asking for variables." (interactive) (insert "(lambda (" (read-string "Variables: ") ") ") (save-excursion (insert ")"))) (add-hook 'scheme-mode-hook '(lambda () (local-set-key "\C-cl" 'lisp-insert-lambda)))
NODUMP flag set. The behaviour is selectable
at run time via the nodump_coredump sysctl
variable.
usbd daemon, as it is, is not suitable to
handle devices implementing multiple features, like
USB->PS/2 converters, docking stations, or such. Here is
a patch that changes this behaviour
and will make usbd match multiple entries
in usbd.conf. The original behaviour is still
there, you just have to use the -s flag.
ums.c kernel module to make MCT and possibly
other PS/2->USB devices work properly under FreeBSD.
apm_event POWERSTATECHANGE {
exec "/bin/sh /usr/local/bin/handle-power-change";
}
and do fancy things like dimming the back light of the LCD
screen to save energy when you are not connected to the mains.
setbrightness. I recommend to bind
increase-brightness to the
Super-Button4-Click event
and decrease-brightness to
the Super-Button5-Click event. Tested on a
PCG-XG9.
Igorplug was written mainly because LIRC, which supports this device, is blatantly Linux-centric and thus is poorly supported under *BSD. Igorplug intends to be a replacement for LIRC, but limited to this device; you may notice that most of what you need is already implemented.
Igorplug is not much documented but it should be quite straightforward to use.
igor_broadcast broadcasts the received
infrared sequences via UDP to a specific host and port.
Default is localhost on
port 5253.
igor_echo prints on standard output the IR
sequences it receives from a device. This is useful to
compile a configuration file for the following programs.
igor_inject converts IR sequences into
X-events and sends them to a specific window or any
window currently in focus. This uses a configuration
file containing the association of sequences and events.
igor_pty converts IR sequences into
keystrokes that are sent to a child program, which is
specified as argument. This uses a configuration file
containing the association of sequences and keystrokes.
abcd + cdef = abcdef.
-o is given, files are concatenated
after the end of the first (modifying it).
Copyright © Walter C. Pelissero, all rights reserved