Tuesday, May 5, 2009

Java floats and doubles

I'm attempting to write some high performance Java. There is some limited evidence that you might expect a small performance improvement using floats over doubles.

There is a good case why memory usage will be reduced.

However, why is it such a pain to use floats? I am constantly finding methods, in the Graphics2D classes, which only support one or the other (generally better support for Doubles).

I think this post sums up reasons not to use floats, and makes a good point: why have floats at all?

Sunday, April 19, 2009

chains vs args

I've been using chains for endpoints for a bit. They are quite useful if I want one simple filter criteria.

Recently, I have a requirement for two or more criteria. This could be, for example: filetype=10 and project=8. I'm imagining that I could construct the required end point with chains, but how could I do this without implementing two controllers: one for ./filetype/10/project/8 and the other for /project/8/filetype/10.


In this case, I think it would be nice for the order of criteria to be arbitrary. I'm not sure how to achieve this, so instead I've used: $c->req->query_parameters and get the GET hash and then used that to construct my filter criteria.

I've seen a post, dating from 2006 I think, on this topic. I feel like there should be a pattern, or best policy which should improve on my crude solution. I look forward to it.

Sunday, February 22, 2009

Gmane save the day again

I had a problem where I wanted to perform authorization without authentication. After alot of scratching of my head, Gmane came to the rescue:
http://article.gmane.org/gmane.comp.web.catalyst.general/17180

I really like Gmane, there is a handy search plugin for it as well:
http://article.gmane.org/gmane.discuss/8737

Friday, February 20, 2009

many_to_many torture

I have just spent the best part of the last week wrestling with many_to_many configuration with DBIx in Catalyst.

My problem manifested it self as an error when calling $newApp->add_to_directory($directories);

DBIx seeming was unable to do the sensible thing and put the primary key from my apps table into the join table.

I also got errors like:
ManyToMany::__ANON__(): No such column

Now, after a week, I have discovered that if I update_or_insert my $newApp (which I made with $c->model('Proj::App')->new({}); first, then add_to_$rel works.

This wasn't obvious to me in the documentation, but hopefully you have stumgled across this post as you search for help with the same problem.

Wednesday, November 5, 2008

Adding body events to a single catalyst page

I wanted to include some javascript on a single page which was identical to the rest of the site, except it had 'onLoad()' and 'onResize()' events in the page body.

To do this, I created a new ./lib/MyApp/View/NewView.pm, which was identical to ./lib/MyApp/View/HTML.pm except it pointed to a different wrapper: 'site/jsPageWrapper'.

My 'site/jsPage' was identical to 'site/wrapper' except it called the WRAPPER 'site/jsPageHTML'

In turn, 'site/jsPageHTML' was identical to 'site/html' but with the relevant event handlers on the body tags.

In my controller, I needed to forward to my new view: $c->forward('MyApp::View::NewView').

and that was that.

Sunday, October 5, 2008

Thanks to mst and edenc on irc, I managed to reuse a configuration for connect_info among a number of models. And then I wrote it up for the wiki:

http://dev.catalystframework.org/wiki/gettingstarted/howtos
/ModelConfigSharing.highlight

Thursday, October 2, 2008

Template toolkit rendering a hash

I wanted to render a which I generated within my app; it is a calendar basically:
$calendar{$year}{$month}{$day} = daynumber; which I add stash as:
$c->stash->{calendar} = $calendar;

the code I used to get this working is as follows:

[% FOREACH year IN calendar.keys -%]
[% FOREACH month IN calendar.$year -%]
[% SET m = month.key %]
[% FOREACH day IN calendar.$year.$m -%]
[% SET d = day.key %]
values =
[% year %],
[% month.key %],
[% day.key %],
day number = [% calendar.$year.$m.$d %]


[% END %]
[% END %]
[% END %]