Generate the route url for a Cornice service or resource

As far as I can tell, there’s no documentation on how to generate the reverse url for a Cornice resource or service. Suppose I want to publish a list of children resources and i want to make them behave as linked data. For that, I want to be able to generate proper URLs, based on the request URL. This is some sample code to show how to achieve that, based on a side project I’m working on: [...]

Another way to index category labels in categorization tasks

One common task in machine-based categorization tasks is to relabel data with a numeric value, an index, where before that data was labeled with a string. The basic Python code would be something like this: label_index = {} labels = [] for l in string_labels: if l not in label_index: label_index[l] = len(label_index) labels.append(label_index[l])> While writing that bit of code from above, I realized that a word tokenizer can do the same thing. [...]

How to shuffle two arrays to the same order

This is a small recipe on how to get two arrays with the same shape (same length) shuffled with the same “random seed”. This is useful when the two arrays hold related data (for example, one holds values and the other one holds labels for those values). It takes advantage of the fact that numpy arrays can be indexed with other arrays, something that seems really magical when compared to regular python arrays. [...]

Editing Short python scripts with vim

Being that I usually find interesting to know about other people’s workflow, here’s a short description of my working environment that I typically use when developing in Python: tmux In the beginning I’ve used Yakuake tabs to split servers and files in separate tabs. As the number grew, I’ve started naming the tabs (and even had a short stint extending Yakuake to fit this use case), but as the number of projects and environments that I have to juggle kept growing, I’ve resorted to splitting each separate tab into “subtabs”, using tmux. [...]

Do you really need that metadata column?

It is one of the tenets of Plone optimization that brain.getObject() should be avoided and instead new metadata columns should be defined, to pass have that information in the brain. In the interest of keeping the ZODB free of junk and avoid duplication of information, I argue that it is possible sometimes to avoid polluting the catalog and instead use the information stored in the index itself.  As an example: when exploring collective. [...]

Auto-bootstrap (n)vim configuration

Ever since I've moved to Neovim and redid my whole setup, I've had this piece of code at the top of my init.vim: if empty(glob('~/.config/nvim/autoload/plug.vim')) silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs \ autocmd VimEnter * PlugInstall | source $MYVIMRC endif Together with the rest of that dotfile, it automatically bootstraps the whole plugins install process, which makes moving to a new machine a simple operation of just cloning the repo in the proper location, start once Neovim to let it bootstrap, then boom, everything fits in place. [...]

Django templates make me go mad...

Why is this a positive thing? Excerpt from Django Oscar, an eComerce framework. <li class="step2 {% if step == 2 %}active{% else %}{% if step == 3 %}previous{% else %}{% if step > 2 %}visited{% else %}disabled{% endif %}{% endif %}{% endif %} "> Gah... [...]

Always fun, deciphering Ruby DSLs (part 1)

I never back down from a new system or programming language and thankfully my daily work has exposed me to some Ruby and Rails code. So I've been learning some, just enough to be able to tweak code, fix bugs and make minor additions. I'm not a fan of the Ruby on Rails design, but I enjoy it as a challenge. One thing that I found difficult was writing code that uses some of the many DSLs created by the community. [...]

Easier development when dealing with docker-compose stacks

For some time I've had to deal with two separate, docker-compose based application stacks. One of them combining a Ruby on Rails app with a whole suite of ElasticSearch nodes, sidekiq worker, Postgresql, nginx, the whole shebang. Another is just a plain Zope/Plone stack, but the difficulties remain the same: when I wanted to do production debugging or just plain development using that environment, I needed something that can be started manually, in the whole stack. [...]

Change the authentication cookie name in Plone

Not obvious of first, there are two places to change the cookie name used in login: /acl_users/credentials_cookie_auth/manage_propertiesForm and /acl_users/session/manage_propertiesForm [...]