Saturday, 13 December 2008

Винни-Пых

Читал сейчас в википедии статью про Винни-Пуха. В частности, там рассказывается про звучание имени на разных языках. Например, в английском языке «h» в имени Pooh не произносится, это имя рифмуется постоянно с who или do.

В белорусском переводе некоего Виталя Воронова — Віня-Пых. Вторая часть имени переведена как «Пых», якобы потому, что это созвучно с белорусскими словами пыха (высокомерие и гордость) и запыхацца.

Sunday, 7 December 2008

Как скрыть рекламу в Live Journal

Я читаю несклько блогов в Live Journal и мне мешает громадный рекламный баннер на пол экрана, который Live Journal вставляет в блоги бесплатных аккаунтов.

AdBlock плагин к Firefox в данном случае не помог, он скрывает картинку, но тогда остается большое белое пространство, что не намного лучше картнинки.

В Google быстро нашлось решение.

Для Firefox

Создаем файл userContent.css:


/* Removes LJ Ads from pages. */
/* Code From ambience8 */

@-moz-document domain("livejournal.com") {

div.adv {display: none !important; visibility: hidden !important;}
div.ljad {display: none !important; visibility: hidden !important;}
div.ljadleaderboard-bottom {display: none !important; visibility: hidden !important;}
div.ljadleaderboard {display: none !important; visibility: hidden !important;}
div.ljadwrapper-journal-after-post-c {display: none !important; visibility: hidden !important;}
div.ljadwrapper-app-home {display: none !important; visibility: hidden !important;}
div.ljadmedrect {display: none !important; visibility: hidden !important;}

}
Этот файл нужно положить в директорию chrome вашего профиля. На Widows XP это будет C:\Documents and Settings\<Имя Пользователя>\Application Data\Mozilla\Firefox\Profiles\xxxxxxxx.default\chrome\userContent.css. В Windows Vista: C:\Users\<Имя Пользователя>\AppData\Roaming\Mozilla\Firefox\Profiles\xxxxxxxx.default\chrome\userContent.css

Теперь перезапускаем Firefox. В результате реклама в блогах Live Journal должна исчезнуть.

Для Internet Explorer

Создаем файл userContent.css:

/* Removes LJ Ads from pages. */
/* Code From ambience8 */

div.adv {display: none !important; visibility: hidden !important;}
div.ljad {display: none !important; visibility: hidden !important;}
div.ljadleaderboard-bottom {display: none !important; visibility: hidden !important;}
div.ljadleaderboard {display: none !important; visibility: hidden !important;}
div.ljadwrapper-journal-after-post-c {display: none !important; visibility: hidden !important;}
div.ljadwrapper-app-home {display: none !important; visibility: hidden !important;}
div.ljadmedrect {display: none !important; visibility: hidden !important;}

В меню Internet Explorer выбираем Tools -> Internet Options -> General -> Accessibility -> User style sheet. Здесь указываем путь к созданному файлу.

Как можно заметить из кода, решение для Internet Explorer будет скрывать элемены div с классом adv на любых страницах, а не только в livejournal.com, так что... это не страшно :)

Источник: http://wiki.noljads.com/Hiding_LiveJournal_ads_with_user_stylesheets

Friday, 5 December 2008

Hunchentoot on ECL

It was reported that all Hunchentoot dependencies are already ported to ECL and a patch exists for Hunchentoot itself to make it running on ECL.

I am glad to hear this, because ECL is the only free Common Lisp on Windows with multithreading support (at the same time an active work on multithreading for CLISP is in progress, Clozure CL has beta port for Windows, and a lot of work was also done for threading in SBCL Windows port, although the work is not finished).

I tried Hunchentoot on ECL and for those who are interested too, I reproduce here the steps I took. My environment: Windows XP + Microsoft Visual Studio.

  1. You need the latest versions of Hunchentoot and all the dependencies. If you are lazy, you may get all them at once from this archive I prepared.
  2. Apply the patch from this post (already done in my archive): save the port-ecl.lisp to the hunchentoot directory and add #+:ecl (:file "port-ecl") to hunchentoot.asd as here.
  3. Checkout fresh ECL from CVS:
      cvs -z3 -d:pserver:anonymous@ecls.cvs.sourceforge.net:/cvsroot/ecls checkout ecl
    
    I recommend fresh checkout because I had problems building ECL from sources already existing on my computer after update with cvs update -dAP.
  4. Configure ECL. Open ecl\msvc\Makefile and set
    ECL_THREADS  = 1
    ECL_UNICODE  = 1
    ECL_ASDF     = 1
    ECL_SOCKETS  = 1
    
  5. Build ECL. Run Visual Studio command prompt: menu Start->All Programs -> Microsoft Visual Studio 2005 -> Visual Studio Tools -> Visual Studio 2005 Command Prompt. This script sets up environment variables so that C compiler cl.exe, nmake.exe and other things are in your PATH, all includes and libraries are available, etc. In this console window type:
     > cd <DIR_WITH_ECL_SOURCES>\ecl\msvc
     > nmake
    
    After the build completes, copy resulting binaries somewhere:
      > nmake install prefix=c:\somewhere\ecl
    Now you have working ECL, lets test it:
    > c:\somewhere\ecl\ecl.exe
    ECL (Embeddable Common-Lisp) 0.9l (CVS 2008-07-12 18:54)
    Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
    Copyright (C) 1993 Giuseppe Attardi
    Copyright (C) 2000 Juan J. Garcia-Ripoll
    ECL is free software, and you are welcome to redistribute it
    under certain conditions; see file 'Copyright' for details.
    Type :h for Help.  Top level.
    > (+ 2 2)
    4
    > (quit)
    
    Works.

    Do not close the Visual Studio command prompt, we will need it soon.

  6. As Hunchentoot uses ASDF, we need Hunchentoot with all its dependencies to be registered in ASDF:*CENTRAL-REGISTY*. For this I have a special lisp file, setup-asdf-registry.lisp (already included in the archive from the step 1):
    ;; this file must be stored in the same directory
    ;; where all the lisp libraries are stored 
    ;; (but libraries, of course, have their own subdirectories)
    
    (require 'asdf)
    
    (flet
        ((reg (relative-lib-dir)
           (let ((lib-dir
                  (directory-namestring 
                   (merge-pathnames relative-lib-dir
                                    (load-time-value
                                     (or #.*compile-file-pathname* 
                                         *load-pathname*))))))
             (pushnew lib-dir
                      asdf:*central-registry*
                      :test #'equalp))))
      (reg "alexandria\\")
      (reg "asdf-binary-locations\\")
      (reg "babel_0.2.0\\")
      (reg "cffi-080926\\")
      (reg "chunga-0.4.3\\")
      (reg "cl-base64-3.3.2\\")
      (reg "cl-fad-0.6.2\\") 
      (reg "cl-ppcre-2.0.1\\")
      (reg "cl-who-0.11.0\\")
      (reg "cl+ssl\\")
      (reg "flexi-streams-1.0.7\\")
      (reg "hunchentoot-0.15.7\\")
      (reg "md5-1.8.5\\")
      (reg "rfc2388\\")
      (reg "trivial-features_0.1\\")
      (reg "trivial-gray-streams\\")
      (reg "url-rewrite-0.1.1\\"))
    
    (asdf:operate 'asdf:load-op :asdf-binary-locations) 
  7. Compile and load Hunchentoot. For this go back to the Visual Studio command prompt.
    > c:\somewhere\ecl\ecl.exe  
    > (load "c:/archive-from-the-step-1/setup-asdf-registry.lisp") 
    > (pushnew :hunchentoot-no-ssl *features*)
    > (asdf:operate 'asdf:load-op :hunchentoot-test)
    
    ECL must be started from Visual Studio command prompt because it uses C compiler when compiling Lisp. (pushnew :hunchentoot-no-ssl *features*) is only necessary if you do not have OpenSSL installed (get it here for Win32).
  8. Start Hunchentoot:
    > (hunchentoot:start-server :port 4242) 
    

Now you may open http://localhost:4242/hunchentoot/test and see Hunchentoot test site.

At the moment of this post writing, almost all examples from the test site work, except for two: "UTF-8 demo (writing UTF-8 characters directly to the stream)" and "UTF-8 demo (returning a string)". The reason is already found and I am sure it will be fixed very soon.

Wednesday, 3 December 2008

Simpler Clojure/SLIME Embedding

Thanks to Craig McDaniel's hint, I know a simpler way to embed Clojure/SLIME than I used before. Since Clojure svn revision 1127, macro clojure.main/with-bindings makes the embedding as trivial as this jsp page.

Friday, 28 November 2008

Clojure at Work: Interactively Control Running Java System

We are developing a system on Java. It must call another system and at some point the other system calls our system back via web service. Therefore I can not test this interaction in a stand-alone test, our code must be executed in an HTTP container (we use Tomcat).

In case if the code does not work as desired, I need to stop Tomcat, fix and rebuild Java sources and try again. And what is worse, before the code I am working on can be tested, it performs initialization that takes about a minute. These stumbles are little bit annoying for those who are used to fully dynamic development environments as Lisp.

I decided to embed Clojure into the system during development and connect to it with SLIME to create interactive testing/development environment.

First, I followed Bill Clementson's instructions for usual (not embedded) Clojure/SLIME setup.

After it worked, I started to look for a way to embed Clojure/swank into existing Java system, but didn't find any conventional way to do this. Therefore I torn out a piece of code from the clojure.lang.Repl class and instead of standard input, feed it with commands to start swank (which I found in the *inferior-lisp* buffer when Clojure/SLIME is started "normally", from Emacs).

All this is packed into simple clojure.jsp page in my web application directory. And clojure.jar is placed into WEB-INF/lib.

When the JSP is opened in browser it displays: "swank has been stared".

After that, I use M-X slime-connect from Emacs. The port number, as you can see from the code, is 7777.

What is the result?

I can inspect and control the running system, for example invoke functions I need to test or change object states.

But I must admit that the level of flexibility is lower than I hoped for. The point is that I can not interactively change Java code (which constitutes all the system). To be more flexible, the system must be written on Lisp entirely.

Links

Thursday, 23 October 2008

slime-over-http update

I've just updated my slime-over-http code to work with the current SLIME.

Friday, 29 August 2008

Poor Man's Anti-Virus или Doctor Web на халяву

Что делать, если нужно проветить файл на наличие вирусов, а покупать лицензионный атнивирус душит жаба; пользоваться крэкнутым не позволяет совесть или то, что при обновлении баз он перестает работать?

Мысль развивалась так:

А что, если купить один лицензионный и поставить в локалке на всю организацию или в инете сервак такой завести: сабмитишь файл и тебе говорят, есть там вирусы или нет.

Потом дошло, такое уже есть, причем совершенно бесплатно. Большинство бесплатных почтовых служб, например gmail и yandex, проверяют всю полученную почту на вирусы.

Т.е. чтобы проверить файл на вирусы, отправляешь его себе по почте. Если вирусы есть - в пришедшем письме будет предупреждающее сообщение.

Gmail в этом смысле неудобен (во всяк. случае для отправки). Потому, что отправить письмо с файлом .exe не разрешает, и даже не разрешает отправлять архивы содержащие .exe внутри.

А yandex позволяет отправлять .exe. Когда письмо придет, там даже есть такая удобная кнопочка "Проверить на вирусы", чтобы явно увидеть ответ: "Проверено антивирусом Doctor Web. Вирусов не обнаружено!".

Thursday, 14 August 2008

Классно почитал Тура Хейердала

Блуждая в википедии увидел Тура Хейердала и узнал, что он писал книги о своих путешествиях. Открыл для любопытства здесь: http://www.lib.ru/ALPINISM/HEJRDAL/heierdal_kontiki.txt, начал со случайного места. И прочитал целиком (не за один день; кажется, дня три подряд читал: на выходных и помню будний день тоже был: прихожу с работы и сажусь читать).

Давно не читал художественную литературу, что-то неинтересно, не получаю удовольствия. Эта, правда, не художественная (в том смысле, что описывает реальные события). Может потому и понравилась.

Saturday, 9 August 2008

О чем думали люди 4-5 тысяч лет назад

Эпос о Гильгамеше: http://www.russianplanet.ru/filolog/epos/gilgamesh/text.htm.
Пересказ сюжета и историю можно найти на этом же сайте или в википедии.

Tuesday, 15 July 2008

GUI для SMS банкинга

http://smsbanking.googlepages.com/ - удобная программа для пользователей карточек Беларусбанка.

Репозитарий подверсий

http://www.livejournal.com/code/. Если язык интерфейса русский, то на этой странице
можно прочитать: "Вы можете получить код сервера Живого Журнала из репозитария подверсий."

В английском варианте - "the Subversion repository".

Monday, 7 July 2008

Good News

Tetris in emacs is customizable, so I can play starting right at the interesting speed :)

Here is my value for the tetris-update-speed-function:
(lambda (shapes rows) (/ 20.0 (+ 180.0 rows))

Monday, 30 June 2008

Если любишь ты футбол - 50 за каждый гол!

Самый забавный из 5-6 рекламных роликов водки, которые показывали в перерыве между таймами футбольного полуфинала.

Совсем офигели, бухло рекламировать. Уже почти что в рот тебе его наливают. "50 за маму, 50 за папу, 50 за дедушку, 50 за бабушку..."

Thursday, 26 June 2008

Fix Oracle Output

Customers recently sent us for analysis results of several queries from their Oracle database. The output produced by SQL*Plus or TOAD with the default value of the LINESIZE system variable is quite nasty. Similar to the following:

SQL> select * from users;

        ID
----------
NAME                                                                            
--------------------------------------------------------------------------------
SURNAME                                                                         
--------------------------------------------------------------------------------
LOGIN                                                                           
--------------------------------------------------------------------------------
PASSWORD                                                                        
--------------------------------------------------------------------------------
REGISTRATION_TIME            
-----------------------------
         1
ivan                                                                            
ivanov                                                                          
vanya                                                                           
123                                                                             
26.06.08 21:16:12,000000     
                                                                                
         2
petr                                                                            
petrov                                                                          
petya                                                                           

        ID
----------
NAME                                                                            
--------------------------------------------------------------------------------
SURNAME                                                                         
--------------------------------------------------------------------------------
LOGIN                                                                           
--------------------------------------------------------------------------------
PASSWORD                                                                        
--------------------------------------------------------------------------------
REGISTRATION_TIME            
-----------------------------
qwerty                                                                          
26.06.08 21:16:12,000000     
                                                                                
         3
sidor                                                                           
sidorov                                                                         
sid                                                                             
password                                                                        
26.06.08 21:16:12,000000     
                                                                                


3 rows selected.

SQL> spool off;

 
I created a little tool to convert such an output to a pretty thing like this:
ID         NAME                                                                             SURNAME                                                                          LOGIN                                                                            PASSWORD                                                                         REGISTRATION_TIME             
---------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ----------------------------- 
         1 ivan                                                                             ivanov                                                                           vanya                                                                            123                                                                              26.06.08 21:16:12,000000      
         2 petr                                                                             petrov                                                                           petya                                                                            qwerty                                                                           26.06.08 21:16:12,000000      
         3 sidor                                                                            sidorov                                                                          sid                                                                              password                                                                         26.06.08 21:16:12,000000      

Lisp source is here. Usage instructions are at the top of the file.

Monday, 28 April 2008

Learning Flex

I'm learning Adobe Flex now. Surprisingly, I have much better impression than I expected about it (my expectations are derived from one or two evening experience with Flash).
I dislike ajax/comet etc, because IMHO web browsers are not suitable for desktop-like UI and it is high time for a new cross-platform client technology.
Flex Builder resembles old good Borland Delphi or MS VisualStudio. Flex libraries and tools have "open design" (my intuitive definition for this: if there is no standard TreeView class, we could write it ourselves because all base classes/interactions are understandably defined and the sources are available).
BTW, interesting facts about the language. Adobe claims that ActionScript is based on ECMAScript Edition 4. The ECMAScript 4 language is in some sense progressive, has interesting (in particular lisp-like) features: http://www.ecmascript.org/es4/spec/overview.pdf. Also funny is that the reference implementation of ECMAScript is created on Standard ML.

Thursday, 6 March 2008

Junit 4.4 new assertion mechanism is a very clear demonstration of java limitation comparing to lisp.

It is obvious that ASSERT A > 2 OR B < 3 when failed should print a message "assertion failed: a > 2 or b < 3. This is trivial to implement with lisp macros, but when the language does not provide programmatic access to the program source code, our ASSERT receives only result of expression calculation - a boolean.

Therefore people must create new expression specification language and duplicate expression evaluation that is already present in java compiler.

Thursday, 7 February 2008

Interesting lisp (or scheme) project

There was a post in the lispjobs blog - a part time job for a freelance lisp programmer (I even applied).

The project in question is quite interesting - a website where open source software may be funded collectively by the software users.

Also interesting is that the project is going to be open source and to be created on lisp (they already started and use PLT Scheme).

The guy running this project - Christopher Rasch - wrote quite detailed article almost seven years ago about how such a system may work.

In two words it is approximately following.

Some people wish some soft to be created and are ready to pay some money for it. These people may be called "donors". Other people may do the work required. They may be called "performers". The goal is to allow donors to collect in common sufficient money for performer(s) to do the work. After that performer(s) do the work and get the money.

The mechanism suggested to achieve this goal is similar to equity market. Central object is obligation to do the required work - it is called "software completion bond". The bond is "backed" by money of donors - this means that bond owner may exchange the bond to the money when the job completion criteria are met (as determined by the judge indicated in the work specification).

Bond owner is the performer - he acquires the bonds by some small price before starting work. He may even do only part of the work and sell the bonds to someone else. It is supposed that in this case the bond price will be higher than the initial because less work is left to do to receive the money escrowed for this job.

Christopher Rasch describes his project as a "wish trading market". Read the article for more details.

Although implementation may vary, there are people that want something in this fashion. See at least this thread in the sbcl-devel mailing list.

As for me, I think it is a very interesting idea. There are several projects that I would fund by few dollars, especially taking into account that the money are protected until the job is done. And in particular the "wish trading market"- I hope a kind of bootstrapping may be applied here: after some initial version, this project development may be funded via the described mechanism too.

How comprehensive this initial version should be? Maybe most of things may be done manually at the beginning.

I hope the project will succeed. Unfortunately there is not so much progress last time (AFAICS there were no changes at all in the project svn repository for at least several last weeks).

Links

Tuesday, 1 January 2008

Web development in single threaded lisp with slime and hunchentoot

It is problematic at first sight to use SLIME for web development in a single threaded lisp with swank:*communication-style* = nil (as it happens with CLISP and SBCL on Windows). The problem is the impossibility to modify application while it is running.

In very informal pseudo code this configuration of swank may be simplified represented as:

(loop
   (read-slime-request)
   (exec-slime-request))
When our next SLIME request starts hunchentoot, hunchentoot enters its own request handling loop (for HTTP requests):
(loop
   (read-slime-request)
   (exec-slime-request :
      (loop
         (read-http-request)
         (handle-http-request)))
This means exec-slime-request will not exit and subsequent slime requests will not be handled until the web server is stopped. SLIME isn't functioning.

The solution is to use web server to invoke SLIME. When in the emacs we are going to talk to swank, send special HTTP request and its handler will enforce swank to handle emacs request.

(loop
   (read-slime-request)
   (exec-slime-request :
      (loop
         (read-http-request)
         (handle-http-request :
            (read-slime-request)
            (exec-slime-request))))
It requires only few lines of code in emacs lisp and in common lisp. The code is here, it's simple, see it for more details.

One note is needed to help fully understand the code. When emacs side sends a request to swank, swank is not always blocked by hunchentoot. As far as I understand it, one slime request may lead to a sequence of communications between swank and emacs.

01: (loop
02:   (read-slime-request)
03:   (exec-slime-request :
04:      (loop
05:         (read-http-request)
06:         (handle-http-request :
07:            (read-slime-request)
08:            (exec-slime-request :
09:               ...
10:               (read-slime-request)
11:               ...))))
In the emacs we should not make an HTTP request before sending the slime request that is to be read on the line 10.

To distinguish this situation on the emacs side I check whether the socket of HTTP request read by swank on the line 05 is still connected. In this case new HTTP request isn't performed.

This solution isn't 100% correct (the socket may be still not closed, but swank isn't going to read anything). But it works almost good. Sometimes a glitch appears - when you execute an expression, you get result of previous expression instead of the just executed. If you execute expressions en, en+1, en+2, you get results of executing expressions en-1, en, en+1. This "phase displacement" is most likely caused by the fact that we not performed HTTP request when it was necessary and the slime request remained not read by swank. When next time we do HTTP request for the next slime request, the previous unread request is read and executed by swank.

In principle, I know how to fix this problem (we may annotate HTTP requests and slime requests with some IDs and do synchronization - ignore unnecessary HTTP requests - on the common lisp side; socket checking on the emacs side will became unnecessary). But I do not want to spend time on it, it is easier to enforce reading enqueued expressions by the "special HTTP request" directly from browser: fetch http://localhost:4343/slime-http-send-handler needed count of times.

How to use it.

Very easy.

Add the following line into your .emacs file:

(load "c:/some/path/slime-over-http.el")
The line should follow the normal slime setup.

Here is an example of common lisp web site:

;; this line may vary in you case; just make
;; sure that asdf is loaded and all the needed
;; libraries are available
(load "c:/usr/unpacked/lisp-libs/setup-asdf-registry.lisp")

(asdf:operate 'asdf:load-op :hunchentoot)
(use-package :hunchentoot)

(defun want-slime-over-http-p ()
  "This predicate indicates whether we
are in the development environment and have no
threading"
  #+:win32 t)

(when (want-slime-over-http-p)
  (load "C:/usr/projects/slime-over-http/slime-over-http.lisp")
  (defun hunchentoot::keep-alive-p ()))

(setq *dispatch-table*
      `(dispatch-easy-handlers
        ,@(when (want-slime-over-http-p)
                (list (create-prefix-dispatcher
                           "/slime-http-send-handler"
                           (find-symbol "SLIME-HTTP-SEND-HANDLER"
                                        "SLIME-HTTP"))))
        default-dispatcher))

(define-easy-handler (hello :uri "/hello")
    ()
  "Hello, change me!")
After executing the above code run emacs command slime-start-hunchentoot. Now you may open http://localhost:4343/hello in the browser and see the phrase "Hello, change me!".

You may change it because you have fully functioning slime with repl, debugger, etc.

To stop the server execute common lisp function (slime-http::stop-instance).

Note how we redefined hunchentoot::keep-alive-p to return nil. Single threaded server can't provide keep-alive, because while it is handling alive connection it can't accept any other connections (in particular from slime; also, IE is often unable to fully open a page with several images or frames in this case; looks like it opens several connections and schedules downloading different parts of the page to different connections; connections other than "kept alive" are not handled by hunchentoot).

In addition to redefining keep-alive-p I also use reverse proxying apache for sure.

Resume

So we see quite simple way (despite the long explanation) to do web development with hunchentoot in free lisps available on windows.

It isn't the only way to develop web applications with common lisp if you are on windows. For example you may install linux virtual machine. Edi Weitz - the hunchentoot author - uses this approach.

PS

My code is called "slime-over-http" because initially I delivered slime requests over the TCP connection used by the HTTP request and only some time later I realized that it is unnecessary. I'd like another name (preferably short), but can't contrive it.

If you have any questions about this configuration - ask, I'll be glad to help.