Caution: my English is far from perfect. (Русский тоже не всегда хорош).

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.

Wednesday, 12 December 2007

ECL - multi threaded, free lisp, supporting Windows

Until yesterday I thought that there are no free multithreaded Common Lisp implementations for Windows.

But it turned out that ECL supports multithreading.

Yesterday I downloaded, build it and tried simple test: (mp:process-run-function 'zu (lambda () (loop (format t "zu~%") (sleep 3))))

Seems working.

Also ECL may be build with Unicode support. Although it doesn't support external formats in streams, strings and characters are represented as 24-bit values. It should be sufficient to have support for various external formats in IO using flexi-streams.

Good news for me. I pin great hopes on ECL.

P.S.

I discovered ECL via Common Lisp Survey linked from the xach's post. Thanks ... all.

Blog Archive