Tuesday, May 23, 2017

Editing Mac keybindings on the command line

This sets the "Set Print Area" command on Excel to 'Cmd-Shift-Alt-Ctrl-k'

defaults delete com.microsoft.Excel NSUserKeyEquivalents -dict-add "Set Print Area" -string "@$~^k"

It does work, but you get cramps in your fingers.

You can delete all keybindings in an app with

defaults delete com.microsoft.Excel NSUserKeyEquivalents

I can't seem to delete only one keybinding.

Listing keybindings works like this:

defaults read com.microsoft.Excel NSUserKeyEquivalents

which will give you:

{
    "Set Print Area" = "@$~^k";
}

and in case you can't find your app

defaults domains|perl -lpe "s/\, /\n/g"

will neatly list all the domains and

defaults find NSUserKeyEquivalents

will list all the user keybindings

Sources:

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