: ) wonderful world ( :

the metasyntactic variable

Archive for December 2008

removing Hungarian accents with sed on XP

without comments

I’m up to create a backup from the family photo collection. To avoid further issues with character encoding I decided to remove accents from characters in file names. This is the sed file I wrote:

s/\o341/a/g
s/\o355/i/g
s/\o373/u/g
s/\o365/o/g
s/\o374/u/g
s/\o366/o/g
s/\o372/u/g
s/\o363/o/g
s/\o351/e/g
s/\o301/A/g
s/\o315/I/g
s/\o333/U/g
s/\o325/O/g
s/\o334/U/g
s/\o326/O/g
s/\o332/U/g
s/\o323/O/g
s/\o311/E/g

Written by grault

December 26, 2008 - 2:47 pm at December 26, 2008 - 2:47 pm

Posted in command line, linux

this week’s tobacco

without comments

General Portion

General Portion

Written by grault

December 23, 2008 - 1:59 pm at December 23, 2008 - 1:59 pm

Posted in snus, tobacco

algorithmic drawing with ImageMagick

without comments

Recently I had to do the following. I had a file full of object lifecycles. One line contains an y coordinate, which corresponds to the address the object was placed at, and two x coordinates, the time of allocation and the time of relocation/deallocation. With ImageMagick I was able to generate an image which is useful to see memory fragmentation and garbage collection performance. I had use only the following two syntaxes:

% convert -size 300x200 xc:white foo.pbm
% mogrify -draw 'line 4,30 102,30' foo.pbm
% mogrify -draw 'line 11,31 80,31' foo.pbm
% mogrify -draw 'line 29,32 180,32' foo.pbm
% mogrify -draw 'line 90,33 280,33' foo.pbm

 

Obviously I computed the min and max for all the coordinates. Commands above produced the following:

pbm converted to gif

pbm converted to gif

Written by grault

December 19, 2008 - 9:45 pm at December 19, 2008 - 9:45 pm

Posted in command line, script

infinite long lisp lists

without comments

CL-USER> (setf *print-circle* t)
T
CL-USER> (defparameter =inf-list= '#1=(1 . #1#))
=INF-LIST=
CL-USER> (car =inf-list=)
1
CL-USER> (cdr =inf-list=)
#1=(1 . #1#)
CL-USER> (cadr =inf-list=)
1
CL-USER> (caddr =inf-list=)
1
CL-USER> (cadddr =inf-list=)
1
CL-USER> (defparameter =inf-tree= '#1=(#1# . #1#))
=INF-TREE=
CL-USER> =inf-tree=
#1=(#1# . #1#)
CL-USER> (car =inf-tree=)
#1=(#1# . #1#)
CL-USER> (cdr =inf-tree=)
#1=(#1# . #1#)
CL-USER>

 

Please feel free to read about this here.

Written by grault

December 19, 2008 - 9:21 pm at December 19, 2008 - 9:21 pm

Posted in lisp

simple asdf pack with unit test

without comments

% ls
foo.lisp  mypack.asd  mypack-test.asd  tests.lisp
% cat mypack.asd
(defsystem "mypack"
  :components ((:file "foo")))
% cat foo.lisp
(defpackage mypack
  (:use :cl)
  (:export #:f))
(in-package :mypack)
(defun f () 5)
% cat mypack-test.asd
(defsystem "mypack-test"
  :components ((:file "tests"))
  :depends-on (:mypack :ptester)
  :perform (load-op :after (op c)
                    (funcall
                     (intern (symbol-name '#:run-tests)
                             (find-package :mypack-test)))))
% cat tests.lisp
(defpackage mypack-test
  (:use :cl :mypack :ptester)
  (:export #:run-tests))
(in-package :mypack-test)

(defun run-tests ()
  (with-tests (:name "all-in-one aggregated")
    (test 5 (f))))
%

 

You can read about ptester here

Written by grault

December 19, 2008 - 12:07 am at December 19, 2008 - 12:07 am

Posted in lisp

lisp/cars/religions

without comments

If programming languages were cars…

Lisp: At first it doesn’t seem to be a car at all, but now and then you spot a few people driving it around. After a point you decide to learn more about it and you realize it’s actually a car that can make more cars. You tell your friends, but they all laugh and say these cars look way too weird. You still keep one in your garage, hoping one day they will take over the streets.

If programming languages were religions…

Lisp would be Zen Buddhism – There is no syntax, there is no centralization of dogma, there are no deities to worship. The entire universe is there at your reach – if only you are enlightened enough to grasp it. Some say that it’s not a language at all; others say that it’s the only language that makes sense.

Written by grault

December 17, 2008 - 7:58 pm at December 17, 2008 - 7:58 pm

Posted in lisp

freeblog.hu to wordpress move

without comments

I’ve decided to import all my old kotee.freeblog.hu entries here. The way I did it is not the best. I don’t care about exact times (I dropped time zone information for example). First of all I’ve exported my blog into a file, which is some kind of unknown (at least for me) format xml. I transformed it to LiveJournal xml with an xslt file. WordPress understands LiveJournal files. Let’s see the file:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
  <xsl:template match="/">
    <livejournal>
      <xsl:for-each select="rss/channel/item">
        <entry>
          <itemid />
          <eventtime>
            <xsl:call-template name="FormatDate">
              <xsl:with-param name="DateTime" select="pubDate"/>
            </xsl:call-template>
          </eventtime>
          <logtime>
            <xsl:call-template name="FormatDate">
              <xsl:with-param name="DateTime" select="pubDate"/>
            </xsl:call-template>
          </logtime>
          <subject />
          <event><xsl:value-of select="description"/></event>
          <security>public</security>
          <allowmask>0</allowmask>
          <current_music />
          <current_mood />
        </entry>
      </xsl:for-each>
    </livejournal>
  </xsl:template>

  <xsl:template name="FormatDate">
    <xsl:param name="DateTime" />
    <xsl:variable name="mo">
      <xsl:value-of select="substring($DateTime,9,3)" />
    </xsl:variable>
    <!-- year -->
    <xsl:value-of select="substring($DateTime,13,4)"/>
    <xsl:value-of select="'-'"/>
    <!-- month -->
    <xsl:choose>
      <xsl:when test="$mo = 'Jan'">01</xsl:when>
      <xsl:when test="$mo = 'Feb'">02</xsl:when>
      <xsl:when test="$mo = 'Mar'">03</xsl:when>
      <xsl:when test="$mo = 'Apr'">04</xsl:when>
      <xsl:when test="$mo = 'May'">05</xsl:when>
      <xsl:when test="$mo = 'Jun'">06</xsl:when>
      <xsl:when test="$mo = 'Jul'">07</xsl:when>
      <xsl:when test="$mo = 'Aug'">08</xsl:when>
      <xsl:when test="$mo = 'Sep'">09</xsl:when>
      <xsl:when test="$mo = 'Oct'">10</xsl:when>
      <xsl:when test="$mo = 'Nov'">11</xsl:when>
      <xsl:when test="$mo = 'Dec'">12</xsl:when>
    </xsl:choose>
    <xsl:value-of select="'-'"/>
    <!-- day -->
    <xsl:value-of select="substring($DateTime,6,2)"/>
    <xsl:value-of select="' '"/>
    <!-- time without timezone -->
    <!-- (discarding timezone for the first time) -->
    <xsl:value-of select="substring($DateTime,18,8)"/>
  </xsl:template>
</xsl:stylesheet>

 

I’ve used it as:

afroid-laptop% xalan -in entries.xml -xsl freeb2wordp.xslt > livej-out.xml
afroid-laptop%

 

When was loaded (livej-out.xml) into WordPress, it said I should have fun : ))

Written by grault

December 7, 2008 - 8:51 pm at December 7, 2008 - 8:51 pm

Posted in command line

this week’s tobacco

without comments

Ettan

Ettan

Written by grault

December 7, 2008 - 4:16 pm at December 7, 2008 - 4:16 pm

Posted in snus, tobacco