Feeds:
Posts
Comments

Archive for June, 2008

convert(1)                                                                                                                                     convert(1)

NAME
       convert  – convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.

SYNOPSIS
       convert input-file [options] output-file

OVERVIEW
       The convert program is a member of the ImageMagick(1) suite of tools.  Use it to convert between image formats as well as resize an  image,  blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.

       For  more  information about the convert command, point your browser to file:///usr/share/doc/imagemagick/www/convert.html or http://www.imagemag ick.org/script/convert.php.

       Run ‘convert -help’ to get a summary of the convert command options.

SEE-ALSO
       ImageMagick(1)

COPYRIGHT
       Copyright  (C)  1999-2005  ImageMagick  Studio  LLC.  Additional  copyrights  and  licenses  apply  to  this  software,  see  http://www.imagemag      ick.org/script/license.php

ImageMagick                                                     Date: 2005/03/01 01:00:00                                                      convert(1)

Read Full Post »

Tcl's original rand() is not sophisticated. Tcllib has random variable manipulations:

——-
package require math::statistics;
expr {srand(1)};    # Init. the seed
puts [::math::statistics::random-uniform 0 10 5]; # return 5 uniform RV, ranging from 0 ~ 10
# …
——-

For more infomation, refer to http://tcllib.sourceforge.net/doc/statistics.html

Read Full Post »

Many GUI in Linux can adjust their geometry from command line.

For example, the gnome file browser 'nautilus' can be invoked at the command line:
nautilus -g 800×600+30+20 /home

And 'gv':
——–
for f in *.ps
do
  gv -geometry 1000×1000+0+0 $f &
done
——–

The geometry format is:
-geometry [<width>][x<height>][{+-}<xoffset>{+-}<yoffset>]

Very convenient. It's another reason I love Linux.

Read Full Post »

The Tk GUI builder is the new SpecTcl. It's open source, elegant, easy to use.

Read Full Post »

To do HTTP automation, as far as I can think of for now, there are two main issues: a basic tool to communicate with the HTTP server, and HTML parser to understand (or retrieve information from) what you get from the server.

==============
I. HTTP CLIENT
==============
The basic tool is an http client implementation. For the practice I have so far is using the http package of Tcl language. But there's also libwww, written in C, and it may be better and more comprehensive, but more difficult to use I guess.

—————
1. GET and POST
—————
Communicating with the http server is basically sending queries to the server. Clicking a link, submitting forms, etc., are all queries with specific URLs and with or without body contents. There are mainly two kinds of queries, GET and POST. GET are normally used to retrieve a URL from the server. It is used in our case to simulate mouse clicks on links. It also can do some simply submitting jobs like in CGI. POST method is more comprehensive. It is used to simulate submitting contents to a server, like authentication (logging in), etc.

The queried contents are sent back by the server and is directly followed by the queries (although some delays and the queries may block your program procedure a little sometimes).

Take Tcl http package for example, to query a URL using GET:
set token [::HTTP::geturl $url]
Using POST:
set token [::HTTP::geturl $url -query $query]
where $query is where the body contents stored.
To URL encode a content, use:
set query [::HTTP::formatQuery $key1 $value1 $key2 $value2 …]

———–
2. Cookies
———–
It is often needed to use cookies. Cookies are sent by the server in HTTP header (like Set-Cookies: XXXX),  and they have to be contained in the client's query package headers (Like Cookies: XXXX;XXXX;XXXX). The Tcl way to retrieve cookies from server's HTTP packet header:
————————
  package require http
  set login [::http::formatQuery email spammer@hotmail.com password fooFoo!]
 
  set tok [::http::geturl http://mysite.net/register/user-login.tcl -query $login]
  upvar \#0 $tok state
  set cookies [list]
  foreach {name value} $state(meta) {
       if { $name eq "Set-Cookie" } {
       lappend cookies [lindex [split $value {;}] 0]
       }
  }
  ::http::cleanup $tok
————————-

To set the cookies in the following queries:
————————-
  set tok2 [::http::geturl http://mysite.net/some/restricted_page.html -headers [list Cookie [join $cookies {;}]]]
  … your code
  ::http::cleanup $tok2
————————-

Here's a complete example showing how to communicate with HTTP servers pragmatically:
————————-
  package require http;
 
  proc get_url {token} {
      set contents [::http::data $token];
      set regresult [regexp {URL=(..*)\'} $contents dummy url];
      if { $regresult != 1 } {
      puts "get_url:error!";
      }
      return $url;
  }
 
  set domain {http://uni14.ogame.org};
 
  # format the submitting contents
  set login [::http::formatQuery v 2 universe {uni14.ogame.org} login {your-username} pass {your-pass}];
  # POST to the server
  set token [http::geturl $domain/game/reg/login2.php -query $login];

  # Retrieve cookies
  upvar #0 $token state;
  set cookies [list];
  foreach {name value} $state(meta) {
      if { $name == "Set-Cookie" } {
      lappend cookies [lindex [split $value {;}] 0];
      }
  }
 
  set url [get_url $token];
  puts $url
 
  # Using cookies to query following data
  set token [::http::geturl ${domain}${url} -headers [list Cookie [join $cookies {;}]]];
  puts [::http::data $token];
————————-

===============
II. HTML PARSER
===============
Once we have methods to simulate actions of web browsers, we only need to consider how to retrieve useful information from what we get from the server. I think of this issue quite a lot and initially thought of using regular expressions. However, it seems that regexps are not safe or stable to do this task. Then I googled and found that HTML parsers might be the correct choice. On this issue, I still know little. And more studies are needed. And this is my following task.

Read Full Post »

Here is my note on HTTP protocol and http client-side automation

HTTP protocol
=============
The following link in a good tutorial on HTTP protocol. Later I may put the contents on this blog.
http://www.garshol.priv.no/download/text/http-tut.html

HTTP Client-Side Automation
===========================
Basically to “simulate'' the behaviour of a browser is to manually send queries to the server. Two main methods for a client to query from a server: GET and POST.

GET is the most common query method. But for authentication or filling forms, etc., one needs POST.

Sharkwire is a wonderful network protocols tracing tool. I traced HTTP protocols on ogame.org and knew the basic idea how authentication works.

Read Full Post »

vim : Message: Re: put (paste) from windows clipboard into vim

In Vim, the system clipboard is known as "register plus". On non-Unix
versions, "register star" is synonymous with it. So, just prefix your P
(put) command with "+ (double-quote plus) or, on non-Unix systems, by "*
(double-quote star) and voilĂ ! The clipboard contents get patsed.
Conversely, "+y or "+d do a yank (copy) or delete (cut) to the clipboard:

"+p paste before cursor
"+P paste after cursor
"+y copy (visual area, or takes a postfix telling Vim
"what" to copy)
"+d cut (visual area, or with a postfix)

:echo @+ show the contents of the system clipboard _without_
pasting

etc.

And BTW, it's p (put after cursor) or P (put before cursor), _without_ a
colon prefix; or you can youse the :pu[t] command, which takes the
register-name after the command, and accepts a line number:

:put +

pastes the clipboard after the current line, and

:0put +

pastes it at the top of the file (or use ":$put +", without the quotes,
to paste at the bottom).

And the correct name (in Vim lingo) for where Vim stores data between a
yank and a put if you don't explicitly specify a register name, is —
the unnamed register.

See ":help change.txt", and, in particular, ":help registers".

Read Full Post »