Thursday, October 15, 2015

Javascript libraries that work in Illustrator

Some libraries developed for the web also work inside Illustrator. Here is a list:
  • md5.js
  • color.js
  • handlebars.js
  • moment.js
  • underscore.js
  • json2.js
  • chroma.js
  • numeral.js
  • sylvester.js
In some case they might not work out of the box because nested three-way assignments don’t work. This

return a ? b ? 0 : -j : i;

needs to be edited as

return a ? (b ? 0 : -j) : i;

It just takes some patience.

Wednesday, June 10, 2015

LaTeX, Gnumeric and Inkscape on Heroku

Sometimes my web apps require Linux desktop applications, such as Inkscape, or Gnumeric, or LaTex.

They are easy to deploy thanks to ddollar's apt buildpack.

Sizes seem to be no problem, as a XeTeX slug sizes at 162.6 Mb, one focused on image processing (ImageMagick and Inkscape) at 221.8 Mb, and adding Gnumeric does not seem to add to the size (which seems wrong).

Now I can use these applications on Heroku - for example for converting Excel spreadsheets (via ssconvert) or converting SVG (inkscape).

Saturday, September 27, 2014

Deploying Catalyst apps to Heroku

catalyst.pl Hastu
cd Hastu/
# this is important
mv hastu.psgi app.psgi
# need to edit app.psgi here
git add .
git init && git add .
git commit -m "first commit"
git remote add origin https://github.com/simonecesano/Hastu.git
cpanm --installdeps .
heroku apps:create hastu --stack cedar --buildpack https://github.com/miyagawa/heroku-buildpack-perl.git
git push -u origin master
git push heroku master

Saturday, May 31, 2014

Setting up a Postgres database

First you create the directory the database resides in:
sudo mkdir /Volumes/Data/Postgresql/perfido
Then you make sure that it's owned by the user postgres
sudo chown -R postgres:postgres /Volumes/Data/Postgresql
and finally you create the database
sudo su postgres -c "initdb -D /Volumes/Data/Postgresql/perfido"
and you're ready to go.

If things don't work (you get a "could not connect to server" message) it's very likely a path issue (see this), and therefore fix your path:

export PATH=/opt/local/lib/postgresql93/bin:$PATH

To start postgres automatically use:

sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql93-server.plist

Change to "unload" to stop the system from starting postgres automatically.

Sunday, March 20, 2011

Serving the right file suffix

Sometimes if you use applications other than the browser to open up links (i.e.: Excel), they behave better if the file served has the neat, correct suffix at the end.
This messes up all internal paths in Catalyst though. So I figured out that if I could clean up the suffix at the end of the URI, and keep it as the format parameter, I'd solved the problem. So here's the code:



# inside My::Catalyst::App

after 'prepare_path' => sub {
my ($c) = @_;
local $_ = $c->request->path;
s/\.([a-z]+)$//i;
$c->stash->{format} = lc $1 || 'html';
$c->request->path($_);
};

Cleaning up parameters

I decided that one-letter parameters would be only for internal application use, so that all other can be directly used for querying data. That way I can separate them out before every action, by using a private action in the root controller like this:

sub begin : Private {
my ( $self, $c) = @_;
my ($p, $i);
$p = $c->req->params;
for (grep { /^\w$/ } keys %{$p}) {
$i->{$_} = $p->{$_};
delete $p->{$_}
}

$c->stash->{params} = $p;
$c->stash->{int_params} = $i;
}

Now I have a set of separate parameters that I can use

  • v = view
  • f = format
  • q = query
  • p = page
  • n = number per page
  • s = sort
  • c = columns
  • l = language

Tuesday, July 28, 2009

Serving static files with Catalyst

Serving static javascript files from Catalyst can be a hassle. URLs don't match etc.

If instead you change your MyApp.pm file as follows

__PACKAGE__->config->{static}->{dirs} = [
'static',
qr/^(images|css|js)/,
];

and you place your javascript files in the MyApp/root/js directory, the hassle's gone.

Even better, if you don't have application specific files, you can symlink the directory to the one where you keep the same files to be served by Lighttpd.