Thursday, May 08, 2008

Ironclad hashes in SBCL

Getting a SHA1 digest from Ironclad turned out to be a quite bumpy ride; its “convenience functions” are not convenient enough to take a string, they only operate on octets.

There’s a helper function that converts an ASCII string to octets, but I needed to be able to supply Unicode strings as well. I ended up finding STRING-TO-OCTETS:

(defun sha1 (str)
  (ironclad:byte-array-to-hex-string
    (ironclad::digest-sequence :sha1 (SB-EXT:STRING-TO-OCTETS str))))

If someone knows an easier or more portable way, I’m all for it. I’m also interested in other free implementations’ functions to convert their strings to octets.

Monday, May 05, 2008

Arch Linux Newsletter for May 5, 2008 Discussion

Once again this thread is created to discuss any topic that is covered on the Arch Linux Newsletter. And if you have suggestions, please share them with us here.

The Arch Linux Newsletter team has been reduced, consisting of Dusty Phillips, Ronald Van Haren, and me (Eduardo Romero). This simplifies our work and makes us better organize our thoughts, ideas and newsletter improvements. Later on, we might start looking for Translators again.

I hope the next newsletter have more stuff on it, I am on a tight schedule since I am on finals, hopefully, next week is the last one of University.:D

Non visible improvements in this newsletter is the usual code cleanup, fo better performance, I know it isn't a heavy page, but still is better to have a clean code to work with, removing obsolete HTML code.

-- posted by kensai

AUR Cleanup

From the TUs: The AUR has a large number of obsolete packages which could use cleaning up. Examples of packages that may be cleaned up are: - packages that have been renamed or replaced - old and unmaintained developmental (cvs/svn/etc) packages This is where you can help. Post suggestions of packages in the AUR Cleanup wiki page (http://wiki.archlinux.org/index.php/AUR_CleanUp_Day). TUs will get together and go though the list in a couple of weeks and confirm which packages should be removed. Please do not remove suggestions from the wiki page but add a comment on why it should be kept instead. TUs will take great care not to delete any useful package.

AUR Cleanup

The AUR has a large number of obsolete packages which could use cleaning up.  Examples of packages that may be cleaned up are:
  - packages that have been renamed or replaced
  - old and unmaintained developmental (cvs/svn/etc) packages

This is where you can help.  Post suggestions of packages in the AUR Cleanup wiki page (http://wiki.archlinux.org/index.php/AUR_CleanUp_Day) or as a reply to this thread.  TUs will get together and go though the list in a couple of weeks and confirm which packages should be removed.  Please do not remove suggestions from the wiki page but add a comment on why it should be kept instead.  TUs will take great care not to delete any useful package.

-- posted by Allan

Sunday, May 04, 2008

Function encapsulation in SBCL

The advice functionality allows the programmer to replace or encapsulate an existing function binding (akin to :AROUND methods in the CLOS). See Gary King’s “What is advice” for some useful links and explanations on this.

CLISP and SBCL, my favourite Common Lisp implementations, do not seem to supply this functionality. I haven’t checked whether CLISP has advice under its hood, but SBCL does, and it’s termed “Function encapsulation” there. Once you know how to do it, it’s surprisingly simple to use.

This is the definition of SB-INT:ENCAPSULATE in SBCL’s src/code/fdefinition.lisp:

;;; Replace the definition of NAME with a function that binds NAME's
;;; arguments to a variable named ARG-LIST, binds name's definition
;;; to a variable named BASIC-DEFINITION, and evaluates BODY in that
;;; context. TYPE is whatever you would like to associate with this
;;; encapsulation for identification in case you need multiple
;;; encapsulations of the same name.
(defun encapsulate (name type body)
  (let ((fdefn (fdefinition-object name nil)))
    (unless (and fdefn (fdefn-fun fdefn))
      (error 'undefined-function :name name))
    ;; We must bind and close over INFO. Consider the case where we
    ;; encapsulate (the second) an encapsulated (the first)
    ;; definition, and later someone unencapsulates the encapsulated
    ;; (first) definition. We don't want our encapsulation (second) to
    ;; bind basic-definition to the encapsulated (first) definition
    ;; when it no longer exists. When unencapsulating, we make sure to
    ;; clobber the appropriate INFO structure to allow
    ;; basic-definition to be bound to the next definition instead of
    ;; an encapsulation that no longer exists.
    (let ((info (make-encapsulation-info type (fdefn-fun fdefn))))
      (setf (fdefn-fun fdefn)
            (named-lambda encapsulation (&rest arg-list)
              (declare (special arg-list))
              (let ((basic-definition (encapsulation-info-definition info)))
                (declare (special basic-definition))
                (eval body)))))))

From this we can figure out that basic advice can be gotten from SBCL like this:

CL-USER(19): (defun gorm (x) (1+ x))
GORM
 
CL-USER(20): (SB-INT:ENCAPSULATE 'gorm 'identity '(apply sb-int:basic-definition sb-int:arg-list))
 
#<closure (SB-C::&OPTIONAL-DISPATCH SB-IMPL::ENCAPSULATION) {ACE428D}>
CL-USER(21): (gorm 10)
11
 
CL-USER(22): (SB-INT:ENCAPSULATE 'gorm 'add-five '(+ 5 (apply sb-int:basic-definition sb-int:arg-list)))
#</closure><closure (SB-C::&OPTIONAL-DISPATCH SB-IMPL::ENCAPSULATION) {ACEE31D}>
 
CL-USER(23): (gorm 10)
16
 
CL-USER(24): (SB-INT:ENCAPSULATE 'gorm 'add-seven '(+ 7 (apply sb-int:basic-definition sb-int:arg-list)))
 
#</closure><closure (SB-C::&OPTIONAL-DISPATCH SB-IMPL::ENCAPSULATION) {ACF84ED}>
CL-USER(25): (gorm)
23
</closure>

We have built a pretty onion, each layer of which calls the next inner layer via BASIC-DEFINITION (the analog to CALL-NEXT-METHOD). Let’s peel specific layers from it:

CL-USER(26): (SB-INT:UNENCAPSULATE 'gorm 'add-five)
T
 
CL-USER(27): (gorm 10)
18
 
CL-USER(28): (SB-INT:UNENCAPSULATE 'gorm 'add-seven)
T
 
CL-USER(29): (gorm 10)
11

Saturday, May 03, 2008

Programming, Do I have what it... [Revisited]

Well, lets revisit this subject and see how I have progressed. Since I first wrote that I was going to begin learning programming, I did really started to learn programming using Ruby. Alongside with a great tutorial/book by Chris Pine (he names his kids after programming languages), programming seemed just fine for me. I got pretty good with Ruby, well not good enough to write a complicated program but I did understood most of the tutorial and even accomplished the exercises.

read more

Friday, May 02, 2008

A kind of magic

One often has to checking file uploads for correctness, for example with respect to size, file type or file name.

Here’s a sketch for checking the type of image files:

(defun matches-magic (file magic &optional (offset 0))
    (with-open-file (s file :element-type '(unsigned-byte 8))
      (file-position s offset)
      (loop for c across magic
            unless (eql c (code-char (read-byte s)))
            do (return-from matches-magic))
      t))
 
(defun jpeg-p (file) ; won't catch Exif files with JPEG inside
  (matches-magic file "JFIF" 6))
 
(defun png-p (file)
  (matches-magic file "PNG" 1))
 
(defun gif-p (file)
  (matches-magic file "GIF89a"))
 
(defun canonical-image-extension (file)
  (cond
    ((png-p file) "png")
    ((gif-p file) "gif")
    ((jpeg-p file) "jpeg")))
 
(defmacro any-predicate (preds &rest args)
    `(or ,@(loop for p in preds
                 collect `(,p ,@args))))
 
(defun valid-image-p (file)
  (any-predicate (jpeg-p png-p gif-p) file))

ANY-PREDICATE could also be written as a function (with a slightly different form of arguments), here’s another quick draft:

(defun any-predicate (preds &rest args) ; largely untested
  (some #'identity (mapcar (lambda (x) (apply x args))  preds)))
 
(defun valid-image-p (file)
  (any-predicate (list #'jpeg-p #'png-p #'gif-p #'exif-p) file))

Of course, you could also chain SYMBOL-FUNCTION to get rid of the sharp-signs in the call. Whatever suits you.
I like the macro better, though, since it’s clearer and probably more efficient. Update: see below for a comment by Zach Beane on this.

Homework would be writing a simple DSL to jot down file type data:

(define-file-type "jpeg" JFIF 6)

Alternatives from the outer world would be calling file(1) or parsing magic(4).

Thursday, May 01, 2008

gpm 1.20.3-1 in Core

In case you haven't seen the front page news: https://dev.archlinux.org/news/391/

When attempting to update to gpm 1.20.3-1, you will most likely get the following error message:

Code:

error: could not prepare transaction
error: failed to commit transaction (conflicting files)
gpm: /usr/lib/libgpm.so.1 exists in filesystem
Errors occurred, no packages were upgraded.

This error arises because the /usr/lib/libgpm.so.1 symlink became disassociated from the package (FS#9949). This is fixed in gpm 1.20.3-1 but its upgrade needs to be forced:

Code:

# pacman -Syf gpm
# pacman -Syu
-- posted by Snowman

gpm 1.20.3-1 in Core

When attempting to update to gpm 1.20.3-1, you will most likely get the following error message: error: could not prepare transaction error: failed to commit transaction (conflicting files) gpm: /usr/lib/libgpm.so.1 exists in filesystem Errors occurred, no packages were upgraded. This error arises because the /usr/lib/libgpm.so.1 symlink became disassociated from the package (FS#9949). This is fixed in gpm 1.20.3-1 but its upgrade needs to be forced: # pacman -Syf gpm # pacman -Syu

Wednesday, April 30, 2008

Gtk Engines Benchmarks - What’s the fastest?


There is a program that benchs every kind of gtk engine…

The name is GTKPERF.

Have you ever asked: “What’s the fastest gtk engine?” (in everyday actions…)

I used gtkperf to bench some of the most famous gtk engines:

  • Clearlooks (from gnome-themes-svn)
  • Nodoka ——-> 0.7 (updated)
  • Human (from Ubuntu)
  • Murrine (thanks to CIMI (like new Clearlooks) :))
  • Aurora
  • Mac4Lin
  • Clearlooks Classic
  • Crux
  • Glossy
  • Glider
  • Mist
  • Nova
  • Simple
  • ThinIce
  • Rezlooks (gilouche)
  • Industrial
  • Experience
  • QtCurve (Added)

Updated with xfce-gtk-engines

  • Xfce
  • Xfce-4.0
  • Xfce-4.2
  • Xfce-b5
  • Xfce-basic
  • Xfce-cadmium
  • Xfce-curve
  • Xfce-dawn
  • Xfce-dusk
  • Xfce-kde2
  • Xfce-kolors
  • Xfce-light
  • Xfce-orange
  • Xfce-redmondxp
  • Xfce-saltlake
  • Xfce-smooth
  • Xfce-stellar
  • Xfce-winter

My Pc:

  • Athlon64 3000+ @ 2300 Mhz
  • 1 Gb RAM
  • Nvidia 7600GT (169.09)
  • ArchLinux with kernel: 2.6.24-zen3
(See Pages numbers on the right to change pages)

Monday, April 28, 2008

Tupac - A great utility that completes Pacman (not only a famous rapper)


“A cached pacman implementatioin”

Pacman Description

Tupac (rapper) R.I.P.

(click on the numbers on the right to change pages)

New Pronto Snapshot: 20080428

I've been busy lately, but still steadily working on the ol' web framework.  I'm starting to reorganize the core components to maintain a loose coupling between layers.  Behold an incremental improvement!  Huzzah!

Changes:

  • Change in nomenclature: "template plugins" are now also known as "helpers", and "page plugins" are now also known as simply "plugins"
  • Added a datetime widget to the Form helper
  • Moved template logic into a separate class so it can be accessed outside of page controllers (eg, a commandline client can now use it to render email content)
  • CSS fixes for IE6 and IE7 (oh how I hate thee)
  • Changed Mailer plugin to use SwiftMailer instead of PHPMailer. PHPMailer is still available via ppPHPMailer for the time being.
  • Upgraded TinyMCE to 3.0.7
  • Changes to display callback functions in tpGrid::build_grid()
  • More bugfixes

Now that input validation and templates are where they should be, I'd like to focus on URL mobility a bit more.  Mapping URLs to controller/action pairs is dead easy, but templates and controllers still hardcode URLs in many cases.  For example, if an action redirects to another controller/action after it has finished its business, then it hardcodes that URL.  Works most of the time, but if I want to move a controller to a new URL location (eg, move /blog/post/edit to /admin/blog/post/edit) then I have to actually go through the code and change all instances of that URL.

My answer is going to be basically the reverse of the current URL->Controller mapping that's currently found in app/config/urls.php.  So instead of rendering a hardcoded URL like /blog/post/edit, you would ask to render the controller Blog_Post and the action Edit.

Sounds good in theory.  I'll let you know how it works out.

Thursday, April 24, 2008

Holux M-241 and playing with Google Maps

Another thing I can delete from my wishlist. I have ordered a Holux M-241 which should be delivered in few days. :) In the meantime I have played with Google Maps and their API. After playing with the API of OpenLayers last week, I decided to take the Google API for my geologging mapping. You can find my first result of geologging here. There will be more tracks, more photos and more description of the single hiking tracks. But first, I must receive the M-241 and get it run under ArchLinux. I will post my experience in a later post and try to explain step by step the download procedure of the track information from the logger and generating maps like the one I linked above.

Tuesday, April 22, 2008

Escaping from higher-order functions

Among the different ways to tackle iterative processes I consider to be the higher-order function route the one I use most often. Especially in conjunction with function composition and list predicates it makes great filtering-style code.

A problem that came up several times is interrupting the list processing at an arbitrary point. For example, how do I stop MAPCAR at the third item if I see it fit? Something like that:

(let ((i 0))
  (mapcar (lambda (x)
            (when (eql (incf i) 3)
              (STOP-HERE)))
    '(a b c d)))

Sometimes, one can take alternative routes using FIND or other functions. And there’s always LOOP, DOLIST, recursion and other solutions; after all we’re working in a language that really implements the “there’s more than one way to do it” paradigm.

Using TAGBODY and GO:

(tagbody (mapcar (lambda (x) (go X)) '(a b c)) X)

Using BLOCK/RETURN-FROM:

(block X (mapcar (lambda (x) (return-from X))(a b c)))

I originally posted another version using CATCH/THROW, but as pointed out in the comments this wasn’t all well for several reasons.

Delimited continuations with CL-CONT unfortunately won’t work.

A good alternative solution would be writing your own version of MAPCAR; this has the advantage of being able to return the partially processed list. But there’s the disadvantage of having to rewrite the whole family of mapping functions, though, so for quick prototyping or occasional usage I prefer the above solution.

If you have other neat solutions or see problems with this approach, please leave a comment.

Sunday, April 20, 2008

Update to Drupal 6.2

Well, once again, the web log was off line for most of the day because it was being upgraded to the latest version of Drupal 6.x series. I hope you didn't had any inconvenience because of this, sorry and thanks for your patience. Again the update was just a security update, but introduces some performance enhancements. Lets hope this all works out well.

Saturday, April 19, 2008

Tuesday, April 15, 2008

Comments Enabled

So I sat down and slapped together some comment-ability for this blog. Not that it's really needed, or anything.

I am using disqus because it allows me to push all the comment management stuff offsite. Hooray!

New Compiz-Fusion Plugins


New Compiz-Fusion Plugins

I’ve just updated compiz fusion (git) in the repo… You can install it from there adding this and then:

sudo pacman -S compiz-fusion-git

2008.04-RC Images are out

http://www.archlinux.org/news/389/

A new batch of install images is currently syncing to mirrors.
FTP images have been made available tonight, while CORE images
will be pushed tomorrow night in order to distribute the load.

This marks the first release (well ok... release candidate)
based on a true live Arch system. That is, what's on the
images is just a plain old base installation which just
happens to boot off of a CD or USB stick.

Whoah... did you just say USB stick? Why yes I did! That's
right, from here on out we'll be offering bootable USB disk
images that can act as a live system or installer.

The installer script itself is roughly the same as it's always
been. The most noticable change is the use of UUIDs instead of
sdX/hdX entries by default. A more detailed changelog
should be visible on projects.archlinux.org soon-ish.

If you get the chance, please give the images a spin. You can
find them on our mirrors, in the
iso directory. Please file bugs if you encounter any problems.

By the way, the "RC" status of these images should not be a
turn-off if you're looking to install Arch, there's a very
good chance they'll work just fine for you.

Ready. Set. Go!

-- posted by neotuli

ABS 2.0 In Core

With version 2, ABS has moved to an rsync method for pulling the ABS tree, as part of the changes that needed to be made for our internal move from CVS to SVN as our source control mechanism. This means a few things: 1) cvsup/csup are no longer required, rsync is used instead 2) Configuration moved from /etc/abs/abs.conf to /etc/abs.conf - /etc/abs/* are no longer required Also, since category information (ie. base, devel, editors) is no longer stored in the repo, makeworld has been updated - check makeworld -h for more info.

Archlinux 2008.04-RC

A new batch of install images is currently syncing to mirrors. FTP images have been made available tonight, while CORE images will be pushed tomorrow night in order to distribute the load. This marks the first release (well ok... release candidate) based on a true live Arch system. That is, what's on the images is just a plain old base installation which just happens to boot off of a CD or USB stick. Whoah... did you just say USB stick? Why yes I did! That's right, from here on out we'll be offering bootable USB disk images that can act as a live system or installer. The installer script itself is roughly the same as it's always been. The most noticable change is the use of UUIDs instead of sdX/hdX entries by default. A more detailed changelog should be visible on projects.archlinux.org soon-ish. If you get the chance, please give the images a spin. You can find them on our mirrors, in the iso directory. Please file bugs if you encounter any problems. By the way, the "RC" status of these images should not be a turn-off if you're looking to install Arch, there's a very good chance they'll work just fine for you.

Saturday, April 12, 2008

Analyzing return values with a recursive macro

Printing the argument and return values of a set of nested or sequential expressions is a common debugging tactic.

In Common Lisp we can make use of a recursive macro instead of manually inserting printing statements. Specifically, we want our macro (let’s call it WALK for want of a better name since it’s a simple code walker) to print all the return values it encounters along its way:

(walk (list (+ 5 (* 3 3))
            "Welcome to earth, third rock from the sun!"))
 
(* 3 3) => 9
(+ 5 (* 3 3)) => 14
(LIST (+ 5 (* 3 3)) "Welcome to earth, third rock from the sun!")
  => (14 "Welcome to earth, third rock from the sun!")

The following macro does that job.

(defmacro walk (form)
    (etypecase form
       (atom ; terminating base case
         form)
       (cons
         `(let ((result (,(first form) ,@(mapcar (lambda (arg) `(walk ,arg))
                                               (rest form)))))
            (format t "~S => ~S~%" ',form result)
            result))))

Modifying the output so it prints

(* 3 3) => 9
(+ 5 9) => 14
(LIST 14 "Welcome to earth, third rock from the sun!")
  => (14 "Welcome to earth, third rock from the sun!")

instead is left as an exercise to the reader (bad puns come easily in English…), as is the addition of an optional DEPTH argument.

It would also be nice to make use of the pretty printer for appropriate indentation, but I have severe problems grokking it, so maybe someone familiar with this facility can help.

In other programming languages the same problem requires a bit more effort.

Friday, April 11, 2008

Escape key alternatives in Vim

The Daily Vim blog shows a bunch of ways to replace the time-consuming escape key with a faster binding. You can try all of them at once, if you’re not sure what suits you best.

Unfortunately the most attractive method — remapping CapsLock — is already assigned to the window manager on my box, so this one wasn’t really an option for me.

Thursday, April 10, 2008

Gnome 2.22 Released


gnome222.png

Let’s see how to install it on ArchLinux…

Update 10/04/2008

  • Gnome 2.22 in [extra]
  • Gnome 2.22.1 released

(click on the numbers on the right to change pages)

Planet Archlinux

Planet Archlinux is a window into the world, work and lives of Archlinux hackers and developers.

Last updated on May 09, 2008 11:30 PM. All times are normalized to UTC time.

Subscribe

Feeds

Arch Worldwide

Other Archlinux communities around the world.

brain0 maintains a google earth map showing where in the world arch users live. Add yourself!

Colophon

Brought to you by the Planet aggregator, cron, and Python. Layout inspired by Planet Gnome. CSS tweaking and rewrite thanks to Charles Mauch

Planet Archlinux is edited by Jason Chu. Please mail him if you have a question or would like your blog added to the feed.