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 \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim 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 [...]

How to make the linked object editable in droppable collective.cover tiles

By default, collective.cover offers one mechanism to "drop" objects to their tiles, by using the "Add content" button at the top. I've received feedback that the button will not be very friendly to editors, so my solution, in this case, is really simple. In the tile schema, instead of the default: uuid = schema.TextLine( title=_(u'UUID'), required=False, readonly=True, ) redefine uuid to be such as: from plone.formwidget.contenttree import UUIDSourceBinder from z3c. [...]

Trigger cron style jobs in Plone sites without passwords

For some time the plone.recipe.zope2instance added support to execute scripts in the context of a full "Zope 2 environment", by using it such as  bin/instance run /path/to/script This can be used to launch Python scripts with full support of the Zope machinery, connected to the Zeo server, etc. The script can be generated as a console script from any Plone addon. Here's a small snippet to be used to get a " [...]