Monday, 23 April 2007

Applying LEFT to UTF-8 string in MySQL 3

While applying LEFT function (MySQL built-in or Parser's) to the data encoded in UTF-8 in MySQL 3 database, you could get an charset dismatch error.

One chap at TeleType studio had written a quick workaround. This function chops the string by the first preceding space:


@subString[content;length]
$length(^length.int(0))
^while(^content.mid($length;1) ne ' ' && $i<^content.length[]){
^length.dec(1)
}
$result[^content.left($length)]
#/subString

Friday, 20 April 2007

Preloading images in JavaScript

Old trick to preload images so that they could change smoothly in rollovers.

Act like this in <head> section:

<script language="JavaScript">
camera1 = new Image();
camera1.src = "/p/common/camera1.jpg";
camera2 = new Image();
camera2.src = "/p/common/camera2.jpg";
camera3 = new Image();
camera3.src = "/p/common/camera3.jpg";
</script>

This is used on www.lean-m.ru/?intro=no

Friday, 13 April 2007

Virtual file structure with mod_rewrite

It is cool to use virtual directory structure. You could keep all your code in several files and all the content in the DB.

Here is trick with mod_rewrite that you can put into .htaccess file on the root of your site. The urls, that are not physically exist on the server will be passed into index.html and you could parse them yourself.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html?uri=/$1 [QSA,L]

Wednesday, 11 April 2007

Cursor types in CSS

Here is quick reference on cursor types in CSS

self-explaining:
style="cursor:auto;"
style="cursor:crosshair;"
style="cursor:default;"
style="cursor:hand;"
style="cursor:text;"
style="cursor:wait;"
style="cursor:help;"
style="cursor:move;"

arrow cursors "n", "w", etc. indicates "north", "west", and so on:
style="cursor:n-resize;"
style="cursor:ne-resize;"
style="cursor:nw-resize;"
style="cursor:s-resize;"
style="cursor:se-resize;"
style="cursor:sw-resize;"
style="cursor:e-resize;"
style="cursor:w-resize;"

Monday, 9 April 2007

Actual and requested server name

There are differences between requested server name and actual server name. Because of aliases this may vary, but you could get both by apache environment variables. In Parser 3 it is as easy as an apple.



Assume you have a website at at www.hoogabooga.com and a bunch of aliases pointing to it:



$env:SERVER_NAME will get you an www.hoogabooga.com (actually it's an value of ServerName apache directive).


$env:HTTP_HOST gets whatever.hoogabooga.com that was input into the address box of the browser.

Saturday, 7 April 2007

How to send HTML email with images

When you are sending an HTML email (you don't want this for spam, aren't you?) and want a picture to be shown in a message body, you need to do this:

- attach an image to the message
- each image should be given an id
- in message's HTML you use this counstruction


<img src="cid:image_id" />


In Parser 3 sending such an email is a really easy job.

Here is the self-explaining code:



^mail:send[
$.from[from@server.com]
$.to[user@server.com]
$.subject[enlarge your appetite]
$.charset[windows-1251]
$.html{
<html>
<img src="cid:logo" />
</html>
}
$.file[
$.value[^file::load[binary;/p/common/logo.gif]]
$.name[logo.gif]
$.content-id[logo]
]
]

Friday, 6 April 2007

Check for valid email regexp

Here is regular expression I use to check for valid email

#
# Check whether string seems like an email
@IsEmail[email]
$result(^if(def $email && ^email.match[^^\w+([.-]?\w+)+\@\w+([.-]?[^^@]\w+)*\.[a-z]{2,4}^$][i]){1}{0})
#/IsEmail

And example of use:
^if(!^IsEmail[user@aol.com]){Invalid email}

Wednesday, 4 April 2007

What is Parser 3?

Parser 3 is a web language developed by the Art.Lebedev Studio - the greatest Russian design studio, creators of Optimus keyboard and Vilcus plug dactyloadapter. They use it in their web projects as long as some other russian studios. It's simply designed, cgi- or apache-module thing that parse .html files and execute instructions.

It is class-based typeless language that would be easy to any PHP-developer to learn. At the same time it could be much more cost-effective to use in common web-application that PHP or Perl.

It features transparent charset handling including UTF-8, working with different database, XSLT transformation, XML parsing and other things.

The main feature of the language is that it keeps to be simple while providing almost every capabilities you could think of.

Further reading, documentation, downloads and support could be found at www.parser.ru/en/

PS: Yes I've used to work for Art.Lebedev some time ago :)
PPS: I know there are a lot of grammar problems. Normally I speak Russian most of the time, you know :))