Wednesday, 7 April 2010

Spring

This is the last post I write in this blojsom installation because I'm moving to Blogger. blojsom is a beautiful piece of software and its author really rocks but I'm no more interested in running my own blogging platform (and it is consuming a lot of computational resources I need for other projects).

The new blog address is blog.superfluo.org, as usual I'm not going to write much but if you like, please subscribe to the new atom feed.

Posted by Nicola Piccinini at 10:47 AM CEST in /

Saturday, 14 November 2009

Workaround for an issue with dojo.io.iframe.send

I've developed a widget to retrieve and update a rating in an application that resides on another domain. Due to this cross domain requirement, I had to exploit the iframe hack, which dojo toolkit implements in the dojo.io.iframe module.
It works perfectly with Firefox but I was experiencing a problem with IE 7 and Safari 4: the update went well only the first time the widged is used, afterwards no other requests were sent to the target application.

At the end I've understood that I need to create the communication iframe for every request, this is my workaround:

if ((dojo.isIE || dojo.isSafari) && dojo.io.iframe["_frame"])
{
  dojo.destroy(dojo.io.iframe['_frame']);
  var frameName = dojo.io.iframe._iframeName;
  dojo.io.iframe["_frame"] = window[frameName] = null;
  if (window.frames)
    window.frames[frameName] = null;
}
dojo.io.iframe.send(...)

Check my post to dojo-interest group for any update about this topic.

Technorati Tags:

Posted by Nicola Piccinini at 5:52 PM CET in devel/

Wednesday, 3 June 2009

Html view plugin for dijit.Editor

I've searched a bit for a plugin for dijit.Editor able to provide the HTML view of the content but I haven't found anything so I've thought it was a good occasion to try to build a plugin by myself.

Here the code, probably you want to change the module name if you try it:

dojo.provide("pc.widget.editor_html_view");

dojo.require("dijit._editor._Plugin");
dojo.require("dijit.Dialog");

dojo.requireLocalization('pc.widget', 'editor');

dojo.declare("pc.widget.editor_html_view", 
  dijit._editor._Plugin,
  {
    // Override _Plugin.useDefaultCommand... processing is handled by this plugin, not by dijit.Editor.
    useDefaultCommand: false,

    _initButton: function() {
      // Override _Plugin._initButton() to setup listener on button click

      this.command = "htmlView";
	this.editor.commands[this.command] = "HTML";
	this.inherited("_initButton", arguments);
	delete this.command;

        this.connect(this.button, "onClick", this._htmlView);
    },


    _htmlView: function() {
      this._initDialog();
      this.textarea.value = this.editor.getValue();
      this.dialog.show();
    },

    _initDialog: function () {
      if (!this.dialog) {
        this.dialog = new dijit.Dialog({}, dojo.doc.createElement('div'));
        var messages = dojo.i18n.getLocalization('pc.widget', 'editor', this.lang);
        //var buttonsHtml = '<button>Set</button><button>Set and continue</button>';
        var buttonsHtml = dojo.string.substitute('<button>${0}</button><button>${1}</button>', [
          messages['Set'], messages['Set_and_continue']
        ]);
        this.dialog.attr('content', '<div class="html-view"><div><textarea></textarea></div><div class="buttons">' + buttonsHtml + '</div></div>');
        dojo.body().appendChild(this.dialog.domNode);
        this.dialog.startup();

        this.textarea = dojo.query("textarea", this.dialog.domNode).pop();
        var buttons = dojo.query("button", this.dialog.domNode);
        this.setBtn = buttons.pop();
        this.setAndHideBtn = buttons.pop();
        this.connect(this.setAndHideBtn, 'onclick', this._replaceValueAndHide);
        this.connect(this.setBtn, 'onclick', this._replaceValue);
      }
    },

    _replaceValue: function () {
      this.editor.replaceValue(this.textarea.value);
    },
    _replaceValueAndHide: function () {
      this._replaceValue();
      this.dialog.hide();
    }
  }
);

// Register this plugin.
dojo.subscribe(dijit._scopeName + ".Editor.getPlugin",null,function(o) {
  if(o.plugin){ return; }
    switch(o.args.name) {
      case "htmlView":
	o.plugin = new pc.widget.editor_html_view({command: o.args.name});
    }
});

Here you can see it in action:
https://superfluo.org/blojsom-resources/htmlView-dijit.Editor/editor.html
and here you can list and download all files:
https://superfluo.org/blojsom-resources/htmlView-dijit.Editor/

Posted by Nicola Piccinini at 5:47 PM CEST in devel/

Sunday, 14 December 2008

Geokit geocoding with multiple matches

Do you want to be able to manage multiple geocoding matches with Geokit?

>> g = Geokit::Geocoders::GoogleGeocoder.geocode('Springfield')
=> #<Geokit::GeoLocs:0x7f0705acb288 ...
>> g.full_address
=> "Springfield, MO, USA"
>> g.ll
=> "37.196828,-93.287061"
>> g.size
=> 9
>> g.map {|e| e.full_address}
=> ["Springfield, MO, USA", "Springfield, Florida, USA", "Springfield, IL, USA", "Springfield, Missouri, USA", "Springfield, MA, USA", "Springfield, Virginia, USA", "Springfield, OH, USA", "Springfield Ave, Paris, IL 61944, USA", "Springfield, Baldwin, MI 49304, USA"]
>> g.is_a? Geokit::GeoLoc
=> true

Give a try to my simple enhancement (only for Google geocoder) and let me know.

Technorati Tags:

Posted by Nicola Piccinini at 4:40 PM CET in /

Friday, 5 December 2008

Posting a file with ActiveResource

Recently I had to put or post files to a web service using ActiveResource. I thought that it was a common tasks but, after searching a bit, I wasn't able to find any documentation about how to do that and so I ended up implementing my dirty solution.

Luckily, Rails already knows how to parse a file parameter so I only had to produce an XML conforming to what that parameter parser expects. If you, like me, are receiving the file from a multipart/form-data form in a Rails application, then you have an UploadedStringIO instance to play with:

module ActionController
  class UploadedStringIO
    def to_xml(options = {})
      options[:indent] ||= 2
      xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
      xml.instruct! unless options[:skip_instruct]
      dasherize = !options.has_key?(:dasherize) || options[:dasherize]
      _root = options[:root] || 'file'
      root_tag = dasherize ? _root.to_s.dasherize : _root.to_s
      xml.tag!(root_tag, ActiveSupport::Base64.encode64(string), :type => 'file', :name => original_path, 
        (dasherize ? 'content-type' : 'content_type') => content_type)
    end
  end
end

With that, if you have a Tournament model, with a flier attribute and you assign to it a text file (file name: flier.txt, file content: abc) then ActiveResource will post/put something like:

<?xml version="1.0" encoding="UTF-8"?>
<tournament>
  <flier type="file" name="flier.txt" content-type="text/plain">YWJj
</flier>
</tournament>

that is what Rails wants.

Technorati Tags:

Posted by Nicola Piccinini at 6:03 PM CET in devel/

Sunday, 30 November 2008

Relay mail via Google SMTP or AuthSMTP with Postfix

A well know trouble with EC2 instances is to send mail reliably, in fact the dynamic nature of the IP numbers in the cloud makes them suspect for most spam countermeasures. The common workaround is to have an external SMTP server thorough which relaying every email message.

A natural choice is to use Google Apps for your domain and to exploit their service which is free up to 2000 messages per day and comes with all the Gmail goodies.
Jules Szemere has a good post (1) about how to do that with Postfix (note for Ubuntu users: the CA.sh script is in /usr/lib/ssl/misc).

Unfortunately, in my experience (and not only in mine) also messages from Google servers are sometimes considered SPAM. Perhaps switching to the premium edition could solve that, anyway I followed the recommendation (2) from Paul Dowman (EC2 on Rails author) and I'm using AuthSMTP. The minimum fee is lesser than Google Apps premium edition (though the cost per message is not) and it's actually reliable.

What I miss more with AuthSMTP is the lack of a copy of the message in the sent mail folder, I could always add a BCC field but this wastes the service quota.
The ideal solution is to use Google to send to safe addresses that are unlikely to drop the message (especially those in BCC) and to use AuthSMTP otherwise. In practice we have to put together the configurations in (1) and (2) in a smart way. So, thanks to the suggestions of my trusty system administrator, in /etc/postfix/main.cf:

transport_maps = hash:/etc/postfix/transport

# auth
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

# tls
smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_note_starttls_offer = yes
tls_random_source = dev:/dev/urandom
smtp_tls_scert_verifydepth = 5
smtp_tls_key_file=/etc/postfix/certs/postfixclient.key
smtp_tls_cert_file=/etc/postfix/certs/postfixclient.pem
smtpd_tls_ask_ccert = yes
smtpd_tls_req_ccert = no
smtp_tls_enforce_peername = no

Two maps need to be specified, transport_maps defines which relay server to use depending on the destination address:

gmail.com   :[smtp.gmail.com]:587
yahoo.com   :[smtp.gmail.com]:587
*           :[mail.authsmtp.com]

while smtp_tls_policy_maps defines the policy to use with the relaying server:

[mail.authsmtp.com]             none
[smtp.gmail.com]:587            may

Finally, in smtp_sasl_password_maps we specify both Google and AuthSMTP credentials:

gmail-smtp.l.google.com username@yourdomain.com:password
smtp.gmail.com username@yourdomain.com:password
mail.authsmtp.com username:password
Posted by Nicola Piccinini at 5:19 PM CET in devel/

Tuesday, 1 April 2008

Английски

All my solidarity to Valentina Hasan, I never understand lyrics!

(via)

Posted by Nicola Piccinini at 10:56 PM CEST in /in the net/

Wednesday, 12 March 2008

mongrel_rails service and $stdout problem on Windows server

Charlie:

First, if you have the choice, ditch windows, not worth it. However, if you are like me and are forced to use windows for a project then your solution is a simple derivative of what you will find here.

I'm forced to work with a Windows server too and I was experimenting the same issue. Charlie put me on the right track and I solved it adding what follows at the beginning of #{RAILS_ROOT}/config/boot.rb:

begin
  $stdout.write("checking $stdout -> ")
  $stdout.flush # really try to write!
  $stdout.write("OK\n")
rescue
  $stdout.reopen('log/mongrel.log')
  $stderr.reopen('log/mongrel_err.log')
end

As $stdout and $stderr are redirected only when IO#write raises an exception, it is effective only when Mongrel is running as a service and you still can launch it from a terminal or use a console without any problem.

Posted by Nicola Piccinini at 12:57 AM CET in devel/

Tuesday, 13 November 2007

Experimenting with MySQL spatial extensions

Two years ago I was experimenting with PostGIS on etch and in these days I'm trying to do the same with MySQL. I'm no longer maintaining a page with my system configuration because It was more annoying than useful (at least for me ;-P ), it should be enough to know that we are on a debian lenny, with MySQL 5.0.45-1.

To test the spatial extensions of MySQL, I'll use again the free GIS data about world borders. The first step is to convert the shape file in a SQL script suitable for MySQL:

  • download shp2mysql from http://kartoweb.itc.nl/RIMapper/ (currently it's at version 0.4);
  • compile it. Assuming that all needed library and header files are installed in the system, it's sufficient to do:
    $ gcc -lshp shp2mysql.c -o shp2mysql
    
  • the usage is analogous to shp2pgsql, for example:
    $ ./shp2mysql -s 4326 ../../geo_data/world_borders/world_borders.shp world_borders db_name > world_borders.mysql.sql
    

Now you you can execute the obtained SQL script in a MySQL database and then query the world_borders table:

> select CNTRY_NAME from world_borders where Contains(ogc_geom, GeomFromText('Point(13 40)')) = 1 ;
+------------+
| CNTRY_NAME |
+------------+
| Italy      | 
+------------+
1 row in set (0.41 sec)

and that's fine.

Without the need of loading GIS data we can try some geometric functions:

> select Glength(GeomFromText('LINESTRING(12 34, 13 35)')) ;
+---------------------------------------------------+
| Glength(GeomFromText('LINESTRING(12 34, 13 35)')) |
+---------------------------------------------------+
|                                   1.4142135623731 | 
+---------------------------------------------------+
1 row in set (0.00 sec)

From MySQL 5.0 reference manual:

In MySQL, the SRID value is just an integer associated with the geometry value. All calculations are done assuming Euclidean (planar) geometry.

Does it mean that you can't do geometric calculation on spheroid with MySQL spatial extensions? I don't think so, maybe it's only a bit more complicated, read this enlighten (for me) thread: MySQL GIS

A final note: both PostgreSQL with PostGIS and MySQL spatial extensions work well under Microsoft Windows. I know it because not every coworker uses GNU/Linux, unfortunately ;-) .

Posted by Nicola Piccinini at 12:18 PM CET in geo/

Wednesday, 31 October 2007

Omar

Today:
Omar

For equal opportunities ;-), about 3 years ago, when I haven't a blog:
Enrico

Technorati Tags:

Posted by Nicola Piccinini at 11:53 PM CET in /

Wednesday, 22 August 2007

dojo 0.4.x to 0.9 porting

I've just ported a bunch of code from dojo 0.4.x to 0.9 and I like to share some brief considerations, in the hope that they could be useful for somebody:

  • most of the job consists of searching and replacing some common patterns, for example: widget declaration and creation, second argument in topic publishing method (that now is an array), etc. (see the porting guide). It's boring but easy;
  • exotic usage of the dom node used in widget creation can cause problems because it seems that dojo 0.9 substitutes it with a new source dom node. In such cases a slightly refactoring is usually needed;
  • what I initially missed more was the unavailability of debugAtAllCosts and dojo.hostenv.writeIncludes() but luckily the same problem (debugging evaled code) is solved in a better way by Fireclipse;
  • some features are missing in dojo 0.9 but usually there is another way to achieve the same effect or one can solve the problem copying and adapting the right functions from 0.4.x.

After (to be honest) a lot of work I've completely refactored my application that consists approximatively in 15 widgets and 25 other Javascript source file (divided into two modules).

Unfortunately I can't yet precisely evaluate any performance gain because I'm having problem with the build system and the flattening of localization bundles and I'm not able to build a working release (I believe it's a bug of the build system but can't prove that ;-). Anyway:

  • the (gzipped) size of the release is about 25% less than with dojo 0.4,
  • rendering seems a lot faster in 0.9 respect to 0.4 (no numbers, just feelings).

In conclusion, it seems that the porting to dojo 0.9 has improved my application performance but the gain isn't so impressive. In my opinion it's better to promptly follow the evolution of the library, so I believe that it's worth to upgrade anyway.

Technorati Tags:

Posted by Nicola Piccinini at 1:02 AM CEST in devel/

Sunday, 24 June 2007

Photos

A message for my 3 readers: I've just uploaded some photos.

PS: if interested subscribe to the Picasa feeds, I'm not going to inform here of updates.

Posted by Nicola Piccinini at 2:01 AM CEST in /

Saturday, 23 June 2007

Connect to Microsoft SQL Server from Debian lenny GNU/Linux

Life is unjust and one can't always use open source technologies ;-) .

There are many guides about how to do that but they usually require to compile the drivers from source. Considering I'm using Debian lenny, I'd prefer a solution compatible with its package system, Debian has more than 18000 packages, there should be those I need! In fact it's so, first step is to install these packages:

# apt-get install tdsodbc libiodbc2 unixodbc odbcinst1debian1
[...]
#
  • tdsodbcs is the package with the precompiled FreeTDS drivers,
  • odbcinst1debian1 contains the utility we'll use to configure the drivers,

Second step is to inform the system that now we have the FreeTDS drivers:

# odbcinst -i -d -f /usr/share/tdsodbc/odbcinst.ini
[...]

This adds in /etc/odbcinst.ini the following section:

[FreeTDS]
Description     = TDS driver (Sybase/MS SQL)
Driver          = /usr/lib/odbc/libtdsodbc.so
Setup           = /usr/lib/odbc/libtdsS.so
CPTimeout       =
CPReuse         =
UsageCount      = 1

Third step is to configure your ODBC Data Source Names:

$ odbcinst -i -s -r
[YourDsn]
Description     = Your description
Driver          = FreeTDS
Database        = CatalogName
Server          = 192.160.1.10
Port            = 1433
odbcinst: Sections and Entries from stdin have been added to ODBC.INI
$

Note that if you execute the last command as a normal user the section is added to ~/odbc.ini.

That's all, try it:

$ isql YourDsn UID PWD
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> select * from table_name ;
[...]
SQLRowCount returns 4
4 rows fetched
SQL> 
Now, if you want to use the drivers with Ruby and Rails, there are some additional steps.
First I have to install the libdbd-odbc-ruby package too (you system may need more packages ...), then in database.yml:
development:
  adapter: sqlserver
  username: your_user_name
  password: your_password
  dsn: YourDsn
  mode: ODBC

It's all fine except for an annoying problem with table creation: most columns take an unspecified NOT NULL constraint and that causes a lot of troubles. Maybe somebody could suggest a remedy, it would be very well appreciated :-) .

Posted by Nicola Piccinini at 11:21 PM CEST in devel/

Tuesday, 8 May 2007

Virtual machines

VirtualBox is a great product and works smoothly on Lenny. Kudos!

Technorati Tags:

Posted by Nicola Piccinini at 10:52 PM CEST in debian/

Monday, 26 February 2007

OpenID and REST doubts

Gabriele Renzi:

che bello, mi distraggo per un po’ e Microsoft, AOL e Digg adottano OpenID, mentre phpbb e wordpress ammiccano tramite mod e plugin.

Tim Bray:

Unless I’m missing something.

For a coincidence (I really don't remember what drove me to do it), a while ago I register to MyOpenID and so now I can identify myself as piccinini.myopenid.com and, trough delegation, as superfluo.org.
which, if no other, is pretty cool (in response to Tim Bray's What Could I Use It For Today? question ;-) ).

But I'm missing something about OpenID too and I'm going to share these doubts with my readers (have I readers??!!).

A short story: I discovered OpenID about 6 month ago while I was evaluating authentication methods for a new public web application. It immediately appeared to me as a very clever and exciting idea so I would be happy to adopt it. From another side, I wanted to follow a REST architectural style and these two requisites seemed to me very hard to conciliate and so, having already enough problems in my ToDo list, I gave up with OpenID.

Back to present, I still retain that it's a great idea but I wonder how can it be used RESTfully. Let me explain why in 4 steps:

  1. to obey the RESTful principles your application should be stateless;
  2. this means that you haven't a user session where to save authentication credentials;
  3. this, in turn, implies that you have to authenticate every request;
  4. if OpenId is part of the game, this means that for every request you have to contact an OpenId server to check the user credentials. In my opinion this is impracticable in most of the real situations.

Obviously I could be completely wrong, am I? In such case, how is it possible to use OpenID in a RESTful way? Back when I did my first evaluation I searched quickly (very very quickly, honestly speaking) but found nothing.

Technorati Tags:

Posted by Nicola Piccinini at 12:29 AM CET in /taken cues/

Friday, 26 January 2007

Firebug 1.0

Joe Hewitt:

The web development paradigm wants to evolve, but we can’t build the future with yesterday’s hammer.

Tools are very important indeed.
Firebug made me love JavaScript again and preserves our relationship in the course of time ;-) .

Posted by Nicola Piccinini at 12:01 AM CET in /taken cues/

Friday, 8 December 2006

Selenium on Rails and Edge, again

It seems that the patch wasn't complete. In fact there was also an issue with test:acceptance task. A description of the problem and relative solution can be found here: http://forums.openqa.org/thread.jspa?threadID=5282.

Moreover, if you are wondering why you can't find any result file in selenium-on-rails/log after having run the task (as I was), the reason is that they are removed unless there are some test failures the tests take more time than a configurable limit (see selenium-on-rails/lib/selenium-on-rails/acceptance_test_runner.rb).

Did you save other 5 minutes? ;-)

2006-Dec-09 CET: modified to correct my wrong assertion about the reason why log files aren't preserved after task execution. By the way, I'd prefer if these files weren't removed when there is some failures, as I thought initially.

Technorati Tags:

Posted by Nicola Piccinini at 2:30 AM CET in devel/

Monday, 13 November 2006

Selenium on Rails patch for Edge

The problem with Selenium on Rails and Edge is described here: http://forums.openqa.org/thread.jspa?threadID=5147

You can download the patch here: https://superfluo.org/selenium-on-rails-resources/patch-for-edge-rails.20061111.txt

Nothing at all but maybe it could save 5 minutes to someone.

Technorati Tags:

Posted by Nicola Piccinini at 1:31 AM CET in devel/

Thursday, 9 November 2006

Entrepreneurship

Kyle Shank:

The light at the end of the tunnel is dimming for the developer/entrepreneur who wants to change the world. Act now.

At least, it isn't time anymore to build a video game alone, I believe.

Wil Shipley:

Don't listen to me.

via Dion Almaer.

Marc Hedlund:

What have I been learning: I’m learning to appreciate luck a lot more.

via Francesco.

PS: four posts in a row, that's a record.

Posted by Nicola Piccinini at 6:43 PM CET in /taken cues/

Wednesday, 8 November 2006

More hype please

Joe Gregorio:

... the hype around Ruby on Rails is beginning to fade ...

I'm a RoR adopter and I retain that hype is a big weapon for a framework, therefore this isn't a good news.
I'm writing this post in the hope to revive a little bit of hype ;-)

Technorati Tags:

Posted by Nicola Piccinini at 2:21 AM CET in /taken cues/

Tuesday, 7 November 2006

FCKeditor in Streamlined

In this post to Streamlined group: http://groups.google.com/group/streamlined/browse_frm/thread/12444a2ec7e1c3bd/#
my recipe on how to integrate FCKeditor in Streamlined.

It uses the Ruby FCKeditor Plugin for Rails, mantained by Scott Rutherford.

Posted by Nicola Piccinini at 1:21 AM CET in devel/

Monday, 6 November 2006

Akismet service

I've just finished to install the Akismet Moderation Plugin for using the homonym anti-span service, consequently:

  1. trackbacks are again enabled. I had to close them a month or two ago because they weren't protected by the Math Comment Moderation Plugin and spammers were playing on it. Anyway I'm almost sure that nobody miss them :-D ;
  2. the Math Comment Moderation Plugin has retired, in the hope to not have to come back.

The plugin is configured for deleting automatically every comment/trackback/pingback that is judged spam. So if you add a comment and don't see it, first try to force a refresh of the page and then, please, try to rewrite it using less times the word sex ;-)

Technorati Tags:

Posted by Nicola Piccinini at 12:50 AM CET in blojsom/

Friday, 29 September 2006

What Ruby needs

Tim Bray:

Still, there are flies in the ointment, worms in the apple, fake jewels in the shop window.

At least Unicode (as soon as possible) and IDE. We have RadRails, I use it but it's lacking some important features (by the way, rumors in the mailing list say that an usable debugger is around the corner, great!)

Technorati Tags:

Posted by Nicola Piccinini at 8:20 AM CEST in /taken cues/

Saturday, 23 September 2006

Not using C compiler makes me happy

I was looking again at geospatial matters when I had to reinstall PostGIS. Differently from previous time, life was easy:

stakhanov:~# apt-get install postgresql-8.1-postgis
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
  libgeos-c1 libgeos2c2a postgis proj
[...]

:-D

Technorati Tags:

Posted by Nicola Piccinini at 6:03 PM CEST in devel/

Sunday, 10 September 2006

Ruby libraries

From a one month old post written by Sam Ruby:

The difference isn’t the language, but the libraries. Outside of Weirich and DHH, the Ruby libraries are at best uneven. This even includes libraries which are included with the language. Many seem to be baubles that were created by authors without an attention to detail, and subsequently abandoned.

I have played a lot with the Ruby language in this period and I've the same unpleasant feeling. Maybe, with the continuous growing (intuitively I agree with Pascal Belloncle's comment) in the interest for that language, the situation is going to improve. At least I hope so.

Editorial notes: this isn't a long post but I believe to have already accomplished my plan with an article (in Italian) on Superfluos; although the summer is almost finished, I doubt to be able to write more frequently in the future.

Technorati Tags:

Posted by Nicola Piccinini at 8:52 AM CEST in devel/imho/

Sunday, 25 June 2006

Strange interaction between Mozilla and WEBrick

If you are wondering why WEBrick responds to your XMLHttpRequest from Mozilla 1.7 with:
ERROR bad Request-Line `'
then read this message by prototype's author Sam Stephenson: http://lists.rubyonrails.org/pipermail/rails/2005-March/004703.html

Not surprisingly prototype includes the workaround while, unfortunately (for me), dojo doesn't.
This post in the hope that it took you less than me to discover this.

Posted by Nicola Piccinini at 5:38 PM CEST in devel/

Wednesday, 21 June 2006

How to register a new MIME type in Rails

It's almost summer and it's a lot better playing volleyball under the sun than writing about technical stuffs. Anyway I've a blog and I must feed it so I'll try to add a post every one/two months. Hence, this is for June and July :-) .

The REST web-service support in Rails 1.1 is nice and powerful but how to add a new MIME type management, specifically a text/json [1] one? I haven't found any documentation about this and so I dug into the source code searching for a solution. I ended up with the following (after not few troubles):

require 'json'

# register a new Mime::Type
Mime::JSON = Mime::Type.new 'text/json', :json
Mime::LOOKUP[Mime::JSON.to_str] = Mime::JSON

# its default handler in responder
class ActionController::MimeResponds::Responder
  
  DEFAULT_BLOCKS[:json] = %q{
    Proc.new do 
      render(:action => "#{action_name}.rjson", :content_type => Mime::JSON, :layout => false) 
    end  
  }  
  
  for mime_type in %w( json )
    eval <<-EOT
      def #{mime_type}(&block)
         custom(Mime::#{mime_type.upcase}, &block)
      end
    EOT
  end
end

# its param parser
ActionController::Base.param_parsers[Mime::JSON] = Proc.new do |data|
  {:resource => JSON.parse(data)}
end

require 'json' is for the json library by Florian Frank.

Note that inserting the new Mime::Type into the LOOKUP Hash is fundamental because otherwise:

  1. one can't register the param parser using the constant but has to write ActionController::Base.param_parsers[Mime::Type.lookup('text/json')] = ... ;
  2. a lot more subtle, registering the param parser with this last instruction create a completely new Mime::Type object o and o.hash == Mime::JSON is false, consequently the responder isn't able to find a match!
    In fact the class Mime::Type doesn't opportunely redefine the Object#hash method though it modifies Object#eql? in order to make true o.eql? Mime::JSON. I think that this isn't appropriated: [...] must have the property that a.eql?(b) implies a.hash == b.hash [...] (from Ruby core RDoc documentation)

Now in controllers you can write something like:

  respond_to do |wants|
    wants.json 
    wants.xml
    wants.html
  end

Moreover, if your request has the right content type you'll find in param[:resource] a Ruby Hash corresponding to your JSON object.

So far, so good but I wonder if there isn't a cleaner way to do this ...

[1] actually, the official MIME type for JSON is application/json but dojo recognizes text/json. Anyway my troubles with dojo are material for another post that maybe I'll write in August ;-) .

Posted by Nicola Piccinini at 8:32 AM CEST in devel/

Thursday, 4 May 2006

eclipse 3.2

After some plugins messed up eclipse 3.1.2, I've installed a release candidate of version 3.2 intrigued by the Callisto project. It promises to eliminate uncertainty about project version numbers and is aimed at product producers but I believe to benefit from this stability too.

The first impression is that it's faster and a lot more stable than the latest official release :-D .

Technorati Tags:

Posted by Nicola Piccinini at 11:16 PM CEST in devel/

Tuesday, 2 May 2006

Tips from my rails installation

After my useless lucubration and following emendation, it's time to write something that may be helpful. Unfortunately, first I've to introduce the subject and hence I need to lucubrate a little more.

I developed my Ruby on Rails project on stakhanov (system configuration) and deployed it on stratagemma (system configuration). Debian and Ubuntu have a nice packaging tool that makes absolutely undifficult installing rails. Nonetheless I chose to get it using RubyGems because it's as easy and, in this way, I have more control:

  • I can maintain the development and production environments as much similar as possible and that could avoids unexpected and annoying problems. In my case, luckily, I could have installed the same Rails version (1.0.0) both on stakhanov and stratagemma but who assures me that this will be always valid?
    The same reasoning can be repeated for the development team: it is preferable to have an environment as uniform as possible and so one ignores the various exotic packaging system and goes directly to the source.
  • I can upgrade Rails without waiting that the distribution provide an apposite package. Considering the recent release of the 1.1 version of rails (while Debian etch and Ubuntu breeze are stuck at 1.0), that's not so unlikely.

Anyway apt is still fine and convenient and I used it to install on stratagemma ruby1.8, the DBMS, apache2 and every other necessary tool. The problem is how to integrate all these packages with what comes from RubyGems, particularly when, for avoiding incidental conflict with distribution's packages, you chose to install it and its gems outside the standard system directories. In this way various executable and library can't be found without setting specific environment variables:

# ruby
export RUBY_HOME=/path/ruby 
export RUBYLIB=$RUBY_HOME/local/lib/site_ruby/1.8

# ruby gem
export GEM_HOME="$RUBY_HOME/rubygems"
export RUBYOPT=RubyGems 

export PATH=$RUBY_HOME/bin:$GEM_HOME/bin/:$PATH

This solves the problem from command line but, to make work your rails application, you have to pass the same values to the web server. For apache2:

<VirtualHost your.domain.name>
  [...]
  DocumentRoot /path/to/the/public/directory/in/the/rails/app

  SetEnv RUBY_HOME /path/ruby
  SetEnv RUBYLIB /path/ruby/local/lib/site_ruby/1.8
  SetEnv GEM_HOME /path/ruby/rubygems
  SetEnv RUBYOPT rubygems
  [...]
</VirtualHost>

That's fine for the CGI dispatcher but doesn't suffice for the FastCGI one and you have to add apposite directives. For libapache2-mod-fcgid (Ubuntu package for mod_fcgid):

  DefaultInitEnv RUBY_HOME /path/ruby
  DefaultInitEnv RUBYLIB /path/ruby/local/lib/site_ruby/1.8
  DefaultInitEnv GEM_HOME /path/ruby/rubygems
  DefaultInitEnv RUBYOPT rubygems

These are my tips :-) . In the web there are numerous tutorials with detailed description of each step to install rails, for a configuration similar to the mine, see for example Ruby, Rails, Apache2, and Ubuntu Breezy (5.10) on fo64.com.

Posted by Nicola Piccinini at 11:42 PM CEST in devel/

Saturday, 25 March 2006

Thinking of Ruby on Rails again

Yesterday I was talking with my fellow in business about Ruby on Rails and my doubts on its adoptability in designers driven projects (we were just going to meet a bunch of designers ;-) ). So I thought of the question again and understood that my conclusions were partially wrong and I was too hurried in writing them (ah, the desire to post!).

The described problem is real: in such kind of projects there are difficulties to organize the work in a way that:

  • maintains the most suitable environment for each involved part,
  • facilitates the collaboration and the integration of the work.

A perfect solution doesn't exist and it's necessary to come to compromises, I believe.

I sustained that Ruby on Rails wasn't adapt for managing this operational context, particularly in comparison with the JSP or PHP approaches. This is wrong because, except for the simplest cases, also these last ones are destined to break the normal HTML functioning. It's true that they maintain an environment more similar to what the designer expects to find but this alone is a marginal advantage.
Moreover and above all, independently from the adopted technologies, for preserving the designer-friendly pages navigation, one has to renounce to the MVC pattern and often it isn't worthwhile!

So I'm happy because I'll have less hesitations in using Ruby on Rails even in designers driven projects :-) . This doesn't stop me to look at Nitro because it seems to have a lot of flexibility and that's may be useful in a plenty of situations.

Posted by Nicola Piccinini at 10:40 PM CET in devel/imho/

Thursday, 23 March 2006

General considerations inspired by Ruby on Rails

I followed the hype too and I've tried Ruby on Rails.

A digression: I think that there is a big difference between the hype in real life and in software development. In real life one can be completely nonconformist and lose nothing (one lives even better!). In software development, instead, the hype matters because it means more interested people and this implies more documentation, more code, more tools, more resources in general. Of course a flawed product remains flawed even if it's over hyped so one must be careful as usual but the hype should be considered a plus.

I was saying that I've tried Ruby on Rails on a little project and I must join to the many that say it rocks. In little time I created a working application and deployed it. In truth it was a very simple job: a products' showcase, whole similar to the depot application described in Agile Web Development with Rails. Anyway I'm sure I wouldn't be able to do it in less time using other technologies, although I'm a complete newbie with Ruby and Rails!

This experience has been enough to make me assert that many of the Rails spot are indeed true. Among them, my favorites are:

  1. One language: Ruby

    (from the Apple Rails tutorial). One language should suffice :-) because using multiple languages makes the learning curve steeper and inter operating between them often causes unnecessary impediments.
  2. Instant feedback: edit the code, hit Refresh, and the change is in my browser.

    (from Agile Web Development with Rails). I know, the theory blames the change and try approach but the practice teachs me that it's a great value. Maybe it's also a form of agility, related to the working software over comprehensive documentation assertion, and we want to be agile, or not?

In years, as a developer, I've used almost exclusively the Java language and I like it a lot. Some sustain that Ruby is more powerful but frankly I haven't played enough with it to form an opinion on this subject. Instead I can complain about the lack of a powerful IDE and join Dion Almaer in his request for IntelliR :-).
I used RadRails that is nice (and fresh winner of the Eclipse Best Developer Tool Award) but is far away from what can be done with eclipse or IntelliJ IDEA with Java code. Again I agree with Almaer in his response to Bruce Eckel: an evolved IDE is a fundamental tool that can boost your productivity and software comprehension.
An IDEA developer is accustomed to features like:

  • code navigation between files, classes and method, etc.,
  • sophisticated refactoring,
  • code completion,
  • error highlighting and intention actions

and strongly miss them when aren't available!

I think that a dynamically typed languages is less inclined to be tamed by an IDE and this is a structural disadvantage. However Almaer (yes, always him :-) may be right when writes:

The real winner though? Nice language AND nice tool. And, it's coming.

especially when looking at what JetBrains and Interact (via Ajaxian) are doing with JavaScript.
Moreover, although I agree the most with the article of Bruce Eckel titled Strong Typing vs. Strong Testing", in my opinion:

  • the compiler still does a good job and saves you from writing many tests,
  • considering IDE support, statically typed languages aren't so much less productive than dynamically typed ones.

On the other side, the dynamically typed languages are concise and more manageable. Ruby, in particular, seems to have some potent constructions (I'm thinking, for example, to its capabilities in meta-programming) that should be of great utility but, unfortunately, I don't yet know :-) .

However, if it's true that the dear Java language is becoming old and it's time for a change, maybe I'll prefer to choose again in the static realm. There, the Scala language (via Waste of Time) looks very promising but, as Francesco remembered me, it isn't enough used: if being hyped brings more resources, on the contrary, being not much known is an big deficiency :-( .
Ruby instead is gaining acceptance on a daily base and is a nice language: it's a pure object oriented language and reminds me Perl, that I love. Surely it's a strong candidate.

Anyway, I think that the programming language is not the most important thing to take into consideration and that frameworks matter more (perhaps the two things are connected: good frameworks are written with good languages and vice versa ...). Ruby on Rails is a great framework and I may explain why in my opinion in some cases it is the optimal choice. I may also try to compare it with other ones belonging to the Java world, highlighting pros and cons. Instead, as this post is already too long, I'll preserve these ideas for when I'll have the time to write another one :-). So,again, I'm going to focus on what, from a newbie point of view, I believe isn't so good (please Ruby and Rails people excuse me!).

Rails is a pure MVC framework and this is fine in a developers driven project, i.e. a project leaded by the developers in which the designers (if present) are able to work directly on views and check the results through a running web server.

Unfortunately, in the typical situation we have designers driven project. I'm talking about those low budget (but high frequency) jobs in which a designer (or a group of designers) brings to you, developer, a static web site and asks to add some functionalities. The problems in this context are that:

  1. designer and developer work separately, this isn't agile but real,
  2. designer has the command and is not inclined to change his modus operandi.

Using Rails you have to break the original HTML structure to honor its MVC pattern. On the other side the designer continues to work on the graphics (he must change that awful color, increase the image width of 2 pixels, move the menu from the right to the left and back and so on) and want to do it on a natural (non-Rails) structure. In this way the integration soon becomes a mess.
From this point of view, PHP or Java with JSP (but without taglet) have a cleaner and more convenient approach. It may be that Rails can solve this problem with no effort but I don't know how (probably one can reconfigure the views' locations to resemble the environment the designer expects to find).
Anyway I searched a little and I haven't found a simple workaround. In compensation, I discovered Nitro. Judging from the (terse) documentation and from the demonstration videos this framework (do we need another one?) is very promising and could solve this problem without renouncing Ruby and most Rails peculiarities. Unfortunately, as for Scala, it doesn't seem very used and consequently there won't be a lot of resources. We'll see if it gains popularity, good luck Nitro!

2006-May-07 CEST: Nitro has moved and I've updated the links.

Posted by Nicola Piccinini at 4:38 AM CET in devel/imho/

Wednesday, 28 December 2005

An effort to localize blojsom

A while ago I sketched a solution to localize the blojsom public interface but I haven't time to write about it until now. So, for anyone that could find it useful:
the solution is based on ResourceManager and doesn't require any modification to source code.
It uses the Velocity dispatcher and:

  • a couple of specific velocimacros that should be added in user-macros.vm in WEB-INF/classes;
  • a set of properties files with messages' translations named lMessages_<language_code>.properties and placed in WEB-INF/classes too.
    If a user wants to be newfangled, he can add personal translations in files named <user_id>_lMessages_<language_code>.properties;
  • localized Velocity templates;
  • the DateFormatPlugin to format the dates of comments and trackbacks. In fact, differently from org.blojsom.blog.BlogEntry, the classes org.blojsom.blog.BlogComment and org.blojsom.blog.Trackback don't have a method getDateAsFormat with a parameter of type java.util.Locale.

The translation's file is choosen depending on the language code specified in blog configuration.

At https://superfluo.org/blojsom-resources/ you can find:

To localize your Asual theme, simply:

  1. configure conveniently DateFormatPlugin,
  2. tar xzf blojsom-l-messages.tgz in WEB-INF/classes,
  3. if your desired language code is different from en or it, add in WEB-INF/classes a new resources file named lMessages_<language_code>.properties :-) ,
  4. substitute standard Asual templates and resources with the localized ones in blojsom-asual.tgz,
  5. set blog-language=<language_code> in WEB-INF/<user-id>/blog.properties,
  6. restart servlet container.

Why not to simply create different templates for different languages? Because, in my opinion:

  • it's easier to mantain a set of message sources than a set of templates. This is a crucial point for blojsom developers but is unhelpful for us users :-) ,
  • in this way, the blog's owner can change the language with a very simple operation that can be done also by inexperienced users. This could be important in many situations, expecially when new blogs are added frequently.

Superfluos and Sakscia are using this solution.

Known problems:
  • many (harmless) ERROR log messages are generated by the attempt by velocimacro lMsgF to read a user messages file, when this last one is missing.
Posted by Nicola Piccinini at 5:21 PM CET in blojsom/

Wednesday, 7 December 2005

A contribution to JSON-RPC-Java

It seems that I'm regarded as a contributor of JSON-RPC-Java thanks to my work to handle cases where a method generic signature (such as java.lang.Object) is overloaded with a more specific signature. I'm truly honored :-) !

Posted by Nicola Piccinini at 6:51 PM CET in devel/

Monday, 5 December 2005

Improving my blojsom installation

Now I'm running the CVS head version of blojsom because:

  1. I'm using the new exclusion mapping feature (see blojsom changelog) for filtering out the entries in category zzz,
  2. I slightly modified the source code of org.blojsom.filter.PermalinkFilter to move around the lack of URIEncoding configuration parameter in the version of Apache Tomcat on mayatecnologie (see Internazionalization section in blojsom FAQ) and so, in order to merge future releases, it's better to work under version control.

With the usage, I've noticed that my policy configuration was still too much restrictive. It's necessary to add
permission java.io.FilePermission "/tmp/-", "read, write, delete";
to allow resources' upload.

Posted by Nicola Piccinini at 10:19 PM CET in blojsom/

Tuesday, 22 November 2005

Apache XML-RPC over HTTPS

Some scattered notes about using Apache XML-RPC over HTTPS.

Example code:

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Vector;

import org.apache.xmlrpc.CommonsXmlRpcTransport;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.secure.SecureXmlRpcClient;
import org.apache.xmlrpc.secure.SecurityTool;

public class XMLRPCClientSample
{

    public static void main(String[] args)
    {
        try
        {
            String serverLocation = "https://host.name/path";

/*m1*/      System.setProperty(
	        "javax.net.ssl.trustStore", "/keystore.path/keystore.name"); 
/*m2*/      System.setProperty(
		"javax.net.ssl.trustStorePassword", "keystore.password");    

/*m3*/      SecurityTool.setKeyStore(
		"/keystore.path/keystore.name"); 		             
/*m4*/      SecurityTool.setKeyStorePassword(
		"keystore.password");   		                     

/*m5*/      SecureXmlRpcClient client = new SecureXmlRpcClient(serverLocation);
            client.setup();

/*m6*/      CommonsXmlRpcTransport transport = 
                new CommonsXmlRpcTransport(new URL(serverLocation));         
/*m7*/      transport.setBasicAuthentication("user.name", "user.password");       

            Vector params;

            params = new Vector();
            params.add("param");

            XmlRpcRequest request = new XmlRpcRequest("method", params);

            Object o = client.execute(request, transport);
            System.out.println(o);
        }
        catch (MalformedURLException e)
        {
            e.printStackTrace();
            System.exit(1);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            System.exit(1);
        }

    }

}

If the key of the server you are connecting is not signed by a trusted certificate authority, the certificate is not automatically trusted. In order to force the certificate to be trusted, you must:

  1. import it into a keystore file (cacerts) using the keytool program;
  2. add the instructions marked /*m1*/, /*m2*/, /*m3*/ and /*m4*/ for specifing which keystore to use. Of course, rather of hard coding in instructions /*m1*/ and /*m2*/ these properties' values, you could invoke your executable with -Djavax.net.ssl.trustStore=/keystor.path/keystore.name -Djavax.net.ssl.trustStorePassword=keystore.password options.
    If you omit instructions /*m1*/ and /*m2*/ the exception below is thrown:
    java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
    If you omit instead instructions /*m3*/ and /*m4*/ the exception below is thrown:
    java.net.SocketException: Default SSL context init failed: null
    Anyway, this double pointer to the same information seems to me a little bit redundant :-( ;
  3. to download the server certificate (in order to import it into the keystore) you can use Microsoft Internet Explorer that is good for this stuff. Presently, that isn't possible (AFAIK) with Mozilla or Firefox!
    If you haven't Microsoft Internet Explorer in hand (as me), you can use openssl:
    pic@stakhanov:~$ openssl s_client -connect host.name:443 -showcerts
    CONNECTED(00000003)
    [...]
    
    Thanks to Emanuele Vicentini (my favorite system administrator ;-) that suggested it;
  4. The authentication parameters could be set using the setBasicAuthentication method in org.apache.xmlrpc.XmlRpcClient but it's deprecated. In fact you have to use the homonym method in CommonXmlRpcTransport as in instruction marked /*m7*/ (see Apache XML-RPC javadocs).
    In this way one have to specify the same server location in two places: in instructions /*m5*/ and /*m6*/. Again, this seems to me redundant and error-prone;
  5. the example is useful only if you can configure HTTPS globally and that isn't always the case.
Posted by Nicola Piccinini at 2:32 AM CET in devel/

Stakhanov, Wikipedia and stranger languages

I've just falsified the history of Superfluo :-P .

My local machine was erroneously called stakanov while the correct spelling has an h between k and a, so I've renamed the machine and substituted stakanov with stakhanov everywhere in the blog.

The funny thing is that I knew that stakanov was wrong but thought that the right form was stachanov! Since I disliked this last one and found it unusual (!), I had been using stakanov until, some days ago, Pippo pointed me out how the things were really (thank you!).

In Italian there is the noun stachanovista that is derived from Stakhanov and indicates a person that shows excessive fervor in doing his own work. This word misled me at first, then I found an article on Nederlands Wikipedia about Stachanov that gave me an additional (but wrong?) confirmation.

How is it possible that a proper noun is written differently in different languages? Note that for Stakhanov there is also a third version, the Polsky one. Isn't Wikipedia trustworthy on this subject? (I don't think so)

Posted by Nicola Piccinini at 2:29 AM CET in /

Saturday, 12 November 2005

Upgrade of blojsom and PostMailerPlugin

I upgraded blojsom to version 2.27. Everything went well except of a misunderstanding with TinyMCE templates.

Writing a new post, I noticed that my policies' configuration was excessively restrictive, unless one doesn't need trackbacks :-P . If it isn't the case, it's better to allow every outwards connection:
permission java.net.SocketPermission "*", "connect";

I've slighty adjusted the PostMailerPlugin too:

Howto
  1. copy blojsom-postmailer.jar to WEB-INF/lib,
  2. in your global /WEB-INF/plugin.properties file, add the following line:
    postmailer=org.blojsom.plugin.postmailer.PostMailerPlugin
  3. create in /WEB-INF/(blog-id) a configuration file named postmailer.properties (you can specify a different name in /WEB-INF/web.xml). In the sample configuration file you find some documentation about configurable parameters.

2005-Dec-05 CET: update.

Posted by Nicola Piccinini at 3:38 PM CET in blojsom/

Wednesday, 9 November 2005

Languages and Superfluous

Mary Blume: If you can't master English, try Globish

Uhm, perhaps English is really a too ambitious goal for me and so I could try with Globish :-) . Anyhow I think that the best way one can learn Globish is still to study and to exercise with English, though this doesn't seem to be the opinion of Jean-Paul Nerrière (for obvious reasons :-). So I'm not going to change my plans.

By the way, I've just discovered that also Itanglish is sometimes used to indicate an englishized Italian, hence Itaglish was in fact a good choice. Moreover I've foud a post with a lot of other proposals for a name for this new language.

The sure thing is that writing in Itaglish (or Globish or English) is hard and so, sometimes, I give up. That is one of the reasons that I've created Superfluous, the space in Italian of Superfluo.

Posted by Nicola Piccinini at 11:33 AM CET in /

Sunday, 30 October 2005

Experiments with PostGIS on etch

After the upgrading to etch I had to recompile PostGIS (version 1.0.4) for the new version of PostgreSQL:

pic@stakhanov:~$ /usr/lib/postgresql/7.4/bin/postmaster --version
postmaster (PostgreSQL) 7.4.8

I followed the hints in my previous post but had to change something:
$ ./debian/rules config isn't valid any more, one must instead use $ ./debian/rules build and is forced to compile all PostgreSQL's sources.

After this, I tested the new installation with some free GIS data downloaded from Mapping Hacks:

pic@stakhanov:~/devel$ mkdir geodata
pic@stakhanov:~/devel$ cd geodata
pic@stakhanov:~/devel/geodata$ wget http://mappinghacks.com/data/world_borders.zip
--23:03:33--  http://mappinghacks.com/data/world_borders.zip
           => `world_borders.zip'
Resolving mappinghacks.com... 216.218.203.219
Connecting to mappinghacks.com|216.218.203.219|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3,310,260 (3.2M) [application/zip]

100%[====================================>] 3,310,260    293.94K/s    ETA 00:00

23:03:47 (248.37 KB/s) - `world_borders.zip' saved [3310260/3310260]

pic@stakhanov:~/devel/geodata$ unzip world_borders.zip
Archive:  world_borders.zip
  inflating: world_borders.dbf
  inflating: world_borders.shp
  inflating: world_borders.shx
pic@stakhanov:~/devel/geodata$ /usr/lib/postgresql/7.4/bin/shp2pgsql -s 4326 world_borders.shp country > country.sql
Shapefile type: Polygon
Postgis type: MULTIPOLYGON[2]
pic@stakhanov:~/devel/geodata$ createdb testgis
CREATE DATABASE
pic@stakhanov:~/devel/geodata$ createlang plpgsql testgis
pic@stakhanov:~/devel/geodata$ # if the next command works, 
pic@stakhanov:~/devel/geodata$ # PostGIS has been installed correctly
pic@stakhanov:~/devel/geodata$ psql -d testgis -f /usr/share/postgresql/7.4/contrib/lwpostgis.sql
BEGIN
[...]
COMMIT
pic@stakhanov:~/devel/geodata$ psql -d testgis -f /usr/share/postgresql/7.4/contrib/spatial_ref_sys.sql
BEGIN
[...]
COMMIT
VACUUM
pic@stakhanov:~/devel/geodata$ psql -d testgis -f country.sql
BEGIN
[...]
COMMIT
pic@stakhanov:~/devel/geodata$ psql testgis
Welcome to psql 7.4.8, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help on internal slash commands
       \g or terminate with semicolon to execute query
       \q to quit

testgis=# select cntry_name, area, sum(area(transform(the_geom, 26591))) as calculated_area from country where cntry_name = 'Italy' group by cntry_name, area ;
 cntry_name |  area  | calculated_area
------------+--------+-----------------
 Italy      | 301230 | 301199476062.85
(1 row)

testgis=# /* note that the "area" column (in square kilometers, included in  
testgis*# shapefile) and the "calculate_area" column (in square meters) are 
testgis*# practically equal */

Other examples, indipendent of the imported data:

testgis=# select length2d(geometryFromText('LINESTRING(12 34, 13 35)')) ;
    length2d
-----------------
 1.4142135623731
(1 row)

testgis=# /* that is the usual distance between that two points in a cartesian
testgis*# plan, but: */
testgis=# select length2d_spheroid(geometryFromText('LINESTRING(12 34, 13 35)'), 'SPHEROID["GRS_1980",6378137,298.257222101]') ;  length2d_spheroid
-------------------
  144013.139256991
(1 row)

testgis=# /* the result is much bigger because in this case the points' 
testgis*# coordinates are interpreted as longitude, latitude on a big 
testgis*# spheroid.
testgis*# Changing the longitude doesn't affect the result: */
testgis=# select length2d_spheroid(geometryFromText('LINESTRING(42 34, 43 35)'), 'SPHEROID["GRS_1980",6378137,298.257222101]') ;
 length2d_spheroid
-------------------
  144013.139256991
(1 row)

testgis=# /* but changing the latitude does: */
testgis=# select length2d_spheroid(geometryFromText('LINESTRING(12 64, 13 65)'), 'SPHEROID["GRS_1980",6378137,298.257222101]') ;
 length2d_spheroid
-------------------
  121397.522102769
(1 row)

testgis=# /* the same length using the distance function and (I hope)
testgis*# an appropriate SRID: */
testgis=# select distance(transform(setSRID(geometryFromText('POINT(12 34)'), 4326), 26591), transform(setSRID(geometryFromText('POINT(13 35)'), 4326), 26591)) ;
     distance
------------------
 144144.751580593
(1 row)

Sincerely, I have a lot of doubts regard of the usage of spatial reference identifier (SRID). I chose 4326 because It's suggested in many documents :-P , then, for calculating the Italy's area, I chose 26591 as I saw in spatial_ref_sys table that it is related to that country and has meters as unit of measurement.
Calculating every country's area with this last SRID yields big gaps respect to the values in the shapefile.
Otherwise, using directly 4326 results, for Italy's area, in a small 33.1005615782892:

testgis=# select cntry_name, area, sum(area(the_geom)) as calculated_area from country where cntry_name = 'Italy' group by cntry_name, area ;
 cntry_name |  area  | calculated_area
------------+--------+------------------
 Italy      | 301230 | 33.1005615782892
(1 row)

What are these? Degrees?
An experiment shows that, in these conditions, the area is calculated as if the poligons were on a cartesian plan:

testgis=# select area(setSRID(GeometryFromText('POLYGON((12 34, 13 34, 13 35, 12 35, 12 34))'),  4326)) ;
 area
------
    1
(1 row)

But wasn't 4326 a SRID for longitude, latitude on spheroid? I don't understand.

Anyway, I think that these questions will remain without answer for a long. In fact in this period I am too busy and haven't free time to examine geospatial matters any more :-( .

Posted by Nicola Piccinini at 6:43 PM CET in geo/

Thursday, 13 October 2005

No more debian-non-US

An additional note about upgrading to etch:
don't waste your time (as I did :-( ) searching for a debian-non-US repository because it seems that it is no longer necessary, although I haven't found an official release note claiming it.

Posted by Nicola Piccinini at 10:42 PM CEST in debian/

Wednesday, 12 October 2005

From sarge to etch

Big changes on stakhanov last weekend: I switched from sarge to etch, mainly for X.org (and yes, also because I like having daily upgrades and stable releases are so boring!). debian is great for this type of things, I simply modified /etc/apt/sources.list and ran apt-get update && apt-get dist-upgrade, more than 500 packages were upgraded (included the kernel image) and dozens were added or removed. I had to respond to some questions and to check few configuration files and only the x-window-system-core package (that had been kept back) needed an additional apt-get install x-window-system-core. After reboot I had a perfectly working and configured debian etch, excellent!

Unfortunatly not all is good with debian. After upgrading I had to mess around with source packages to:

  1. building a DRI module,
  2. building the PostGIS library for the new version of PostgreSQL.

Well, In my opinion managing source packages is a pain. The key principles are solid and I like them, every package includes:

  • the original source,
  • a patch file to yield the debian version of the code,
  • debian magic to build and set up everything in a consistent manner.

The problem is in the magic that is often too much complicated! They are many tools to help with it (man dpkg-source) but, if one is not a geek (and I'm not), he has to toil a lot to create his customized binary package.
So one contents oneself to build the sources and to use the binaries outside the debian packaging system :-( but odd things still happen. For example, in my case:

  1. xorg-xserver source package had dependencies problems and couldn't be builded. Ok, I'm using a testing release and there could be problems but also I'm presenlty using the binaries of xorg-xserver and so it is strange,
  2. the only way I found to obtain the source tree of PostgreSQL was building the package postgresql-7.4, a little bit inconvenient.

Maybe all these complications and oddities with the source packages are the price to pay to have a so powerful binary packages management system but I feel that it could (and it should) be simpler. Maybe the next time I'll install an operating system I'll try another distribution (gentoo? Or something of totally different?)

Posted by Nicola Piccinini at 11:55 AM CEST in debian/

Monday, 3 October 2005

Into the geospatial community

I'm peering into the nice geospatial online community and, some days ago, I ended up installing PostGIS on stakhanov (system configuration).

This quick guide (curiously it is cited even in Web Mapping Illustrated) is a bit out of date but still mostly correct. Only ignore the last lines about sed magic and the relative (broken) link to official PostGIS doc.

Moreover I've found geowanking, a mailing list full of interesting thread. For example "[Geowanking] more google and gis", "[Geowanking] GeoSkating" from which you arrive at an awesome Google Maps mashup and "[Geowanking] googlemaps and WMS".
For coincidence also Paolo Massa has written a post about GeoSkating recently, highlighting the author's Google Maps API experiments.
Application's beauty apart, the interesting fact is the idea to integrate layers on Google Maps from any WMS server: it seems that Google Maps is predisposed for integration with WMS and WFS although this is not well documented presently. This provide a standard way to use a well-done service that, with its extraordinary success, could become a "must have" for commercial web mapping. On Google Maps and GIS web services integration see also:

Posted by Nicola Piccinini at 11:43 AM CEST in geo/

Tuesday, 27 September 2005

stakhanov

stakhanov is my local machine, it was named after Aleksei Stachanov as it should be "hard working" :-) .

Posted by Nicola Piccinini at 10:52 PM CEST in /

Saturday, 24 September 2005

The PostMailerPlugin

A missing feature in blojsom is the capability to send, every time an entry is added, an email with its content (title and description). For example blogger allows it and I find it useful because I'm using email as an archiving system (thanks to the recent avalability of free, with large disk storage and well working email services).

Fortunately, blojsom is open source software and so I could add this functionality. Its plugin architecture facilitated notably my job.
I took the CrossPostPlugin (with its event handling behaviour) and added a send email funtionality copying from the CommentPlugin. The result is the PostMailerPlugin (maybe not a good name). The source code with a velocity template for the email body and a sample configuration file are avalaible here.

2005-Nov-13 CET: update.

Posted by Nicola Piccinini at 6:53 PM CEST in blojsom/

Friday, 23 September 2005

Installing blojsom

I've choosen blojsom after a quick comparison with some other blog software and, in truth, it hasn't been a very meditated decision. Anyway, now I'm enthusiastic of blojsom, in my opinion it is really lightweight and powerful and looks different from the tipical java application, in fact it is inspired by bloxsom and it is really perlish!

Installing blojsom (version 2.26) was easy. I did it on mayatecnologie (system configuration) where tomcat is running with a SecurityManager enabled. Perhaps somebody could find useful my policy configuration:

// blojsom
grant codeBase "file:/usr/share/tomcat4/pic/blojsom/-"
 {
 // deducted by inspection of exceptions' traces in catalina.out
 permission java.lang.RuntimePermission "getClassLoader";

 // deducted by an error message concerning CompressionFilter and
 // exceptions' traces in catalina.out  
 permission java.lang.RuntimePermission 
   "accessClassInPackage.org.apache.catalina.*";
 permission java.lang.RuntimePermission 
   "defineClassInPackage.org.apache.catalina.*";

 // more liberal runtime permissions
 //permission java.lang.RuntimePermission "*";

 permission java.io.FilePermission 
   "/usr/share/tomcat4/pic/blojsom/-", "read, write, delete";
 permission java.io.FilePermission 
   "/var/lib/tomcat4/blojsom/-", "read, write, delete";
 // used by WeatherPlugin
 permission java.net.SocketPermission "www.nws.noaa.gov", "connect";
 // used by PingPlugin
 permission java.net.SocketPermission "rpc.weblogs.com", "connect";
 permission java.net.SocketPermission "rpc.pingomatic.com", "connect";
 // to send mail
 permission java.net.SocketPermission "localhost:25", "connect";

 // more liberal socket permissions
 //permission java.net.SocketPermission "*", "connect";

 permission java.util.PropertyPermission
   "blojsom.installation.directory", "read, write";
 permission java.util.PropertyPermission
   "org.apache.xmlrpc.TypeFactory", "read";

 //permission java.security.AllPermission;

 }
 ;
// end blojsom

Another suggestion for who is using the tomcat4 debian package:
I noted that the RefererLogPlugin wasn't able to write its log on tomcat's shutdown, this was due to the init script that kills every JVM processes without waiting their natural termination. From /etc/init.d/tomcat4:

 su -p $TOMCAT4_USER -c "\"$DAEMON\" stop" \
         >/dev/null 2>&1 || true 
 # Fallback to kill the JVM process in case stopping didn't work
 sleep 2
 start-stop-daemon --stop --oknodo --quiet \
         --pidfile "$PIDFILE" --user "$TOMCAT4_USER" 

I commented out "start-stop-daemon --stop ...", I suppose that it could cause troubles in many other situations other than installing blojsom (especially in application that creates a lot of threads, I guess).

2005-Nov-13 CET: update.

Posted by Nicola Piccinini at 4:03 PM CEST in blojsom/

mayatecnologie

Superfluo is hosted on mayatecnologie, a server owned by Maya Tecnologie and located in Arezzo.

Posted by Nicola Piccinini at 2:51 PM CEST in /

Maya Tecnologie

I'm presently employed as manager and software architect/developer (a sort of factotum) by Maya Tecnologie who is kindly hosting Superfluo. Many thanks!
Posted by Nicola Piccinini at 11:39 AM CEST in /

Thursday, 22 September 2005

Itaglish

I'm going to write some contents in English to make them accessible to a wider audience. Unfortunately I'm able to write only in an inaccurate and "italianized" English. You'll have a good example of what I intend reading this text :-P .

As far as I know, there isn't an official term to indicate this sort of language. In the Web it is called in various ways:

  1. Italenglish,
  2. Englitalian,
  3. Itaglish,
  4. Itanglish

The first one, in my opinion, sounds better than the others but is ambiguos: it is used to indicate an italianized English as well as an englishized Italian. Actually the second meaning is more common.
I haven't a clear preference among the other tree but I think that Itaglish is a bit more diffused and so I've adopted it.

In summary:

  1. I'm trying to write some posts in English,
  2. I apologize for all the errors, in effect the posts will be written in Itaglish rather than in English,
  3. I'm going to continuosly improve my English (it's my intention and my hope),
  4. any correction or suggestion will be of great help and well-appreciated.

2005-Nov-10 CET: more on this topic here.

Posted by Nicola Piccinini at 6:33 PM CEST in /