A Painting Comes to Life

A painting captures a single moment in time. Unlike a photograph, we never know if the things in a painting actually existed in that moment. The objects, people, and scenery are all painted over a long time using fuzzy human memory. We are left with an impression of what might have been.

While wandering through art galleries I often wonder what was happening in the scenes. How were the people feeling? What were the sounds in the atmosphere? What was the weather like? Most of all; out of all the moments in an artists life, what made something worth painting?

In Loving Vincent by Dorota Kobiela and Hugh Welchman we get a unique perspective and potential answers to some of these questions. The worlds first oil painted animated movie takes us on a journey surrounding the circumstances of Vincent van Gogh’s death. In learning about his tragic death, we get a glimpse into pieces of his life.

Like many artists, Vincent van Gogh was a tortured soul. During his short career as an artist he created hundreds of oil paintings. Although his contemporaries considered him crazy and a failure, he achieved international acclaim after his death and is considered one of the most influential artists of modern times. We see evidence of this today since it is nearly impossible to visit any modern art museum without seeing at least one of his works.

Kobiela and Welchman bring a selection of van Gogh’s most famous works to life. The postmaster, woman at the piano, man in a yellow jacket, the paint seller, and many other famous paintings are transformed from still portraits into full characters with emotions, dreams, goals, and lives of their own.

The film is a work of art in and of itself. Even if you don’t care about fine art, or film, or animation, or the life of van Gogh. It is difficult to watch this film without a sense of appreciation for the six years of work, and hundreds of painters, that it took in order to produce the film. It will be difficult to view his work again without imagining the motion.

If you were not able to view this truly unique film in a theatre, Blue Ray and DVD version of Loving Vincent  will be available on January 16th.

 

 

 

 

Using Plex with Nextcloud

After hearing about it for years, I finally got around to installing plex on my nuc. I’m impressed with everything about Plex. It was easy to install, and mostly works out of the box. I am using it to manage my ever growing movie collection and massive music library.

All of my files were already on the nuc since I am using Nextcloud. Rather than duplicating the files, I pointed my media library to the same directory where my files are in my nextcloud installation.

This poses a couple of permissions problems. On Ubuntu, this directory is owned by the www-data (apache) user and group. In order to get plex to be able to see the files at all I had to add the plex user to the www-data group and then restart the plex service. The following commands will make that happen:

sudo usermod -aG www-data plex
sudo systemctl restart plexmediaserver.service

My biggest complaint with most “home media servers” is that once you point the files to the right place, you cannot really “manage” most of them. For instance, I have a massive (50+ GB) music collection that I have built up over the years. When I am listening on shuffle I want to prune out some of the songs that I hate. Luckily, with plex this is very simple. The only catch is that the www-data group needs to have read/write/execute access to those files.

In order to make this happen you can run the following command against your data file. Be sure to replace the directory I have below to whatever you are using for your own Nextcloud files.

chmod -R 775 /var/www/nextcloud/data/levlaz/files

Doing these two things makes the Plex + Nextcloud integration work very well. Now whenever I add or remove files from my many different computers everything stays in sync.

SQLite DB Migrations with PRAGMA user_version

This blog used a simple homegrown blogging engine that I wrote backed by a SQLite database. I have a function in the flask app that performs database migrations. My current approach has been to keep a folder full of migrations and run them sequentially whenever the app starts.

This works well for the case of adding and removing tables since SQLite has the handy IF NOT EXISTS option. However, when you are altering an existing table, this entire model falls apart since IF NOT EXISTS no longer works.

Practically, this means that outside of a fresh install my database migrations are useless.

I am still being stubborn and not using a well written solution like Alembic (which I would highly recommend for a “serious” project) for this blog. Instead, I discovered that SQLite comes with a built in mechanism to keep track of the user schema. This is the pragmastatement, and specifically user_version.

Using PRAGMA user_data for DB Migrations

My migrations folder structure looks like this:

.
├── blog.db
├── blog.py
├── __init__.py
├── migrations
│   ├── 0001_initial_schema.sql
│   ├── 0002_add_unique_index_to_posts_tags.sql
│   ├── 0003_add_fts.sql
│   ├── 0004_add_column_to_post.sql
│   ├── 0005_add_comments_table.sql
│   └── 0006_add_admin_flag_to_comments.sql

As you can see the naming convention is 000N_migration_description.sql. Each migration file has the following statement in it:

PRAGMA user_version=N; (where N is the 000"N" part of the file name)

This steps the current user_version to be equal to the current version as defined by the file name.

The code to do stuff with the database is shown below:

def connect_db():
    """Connects to Database."""
    rv = sqlite3.connect(
        app.config['DATABASE'],
        detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
    rv.row_factory = sqlite3.Row
    return rv


def get_db():
    """Opens new db connection if there is not an
    existing one for the current app ctx.
    """
    if not hasattr(g, 'sqlite_db'):
        g.sqlite_db = connect_db()
    return g.sqlite_db


def migrate_db():
    """Run database migrations."""

    def get_script_version(path):
        return int(path.split('_')[0].split('/')[1])

    db = get_db()
    current_version = db.cursor().execute('pragma user_version').fetchone()[0]

    directory = os.path.dirname(__file__)
    migrations_path = os.path.join(directory, 'migrations/')
    migration_files = list(os.listdir(migrations_path))
    for migration in sorted(migration_files):
        path = "migrations/{0}".format(migration)
        migration_version = get_script_version(path)

        if migration_version > current_version:
            print("applying migration {0}".format(migration_version))
            with app.open_resource(path, mode='r') as f:
                 db.cursor().executescript(f.read())
                 print("database now at version {0}".format(migration_version))
        else:
            print("migration {0} already applied".format(migration_version))

The relevant part to this blog post is the migrate_db() function. Two things are happening.

  1. The get_script_version() helper function extracts the integer from the migration name.
  2. current_version gets the current value of user_version of your database.
  3. We iterate over each migration file in the migrations folder and perform a simple check. If the migration version is larger than the current_version we run the migration, otherwise it gets skipped.

This solves for most cases and allows for a smooth upgrade path if anyone ever decides to start using this blogging engine for themselves. I am still pretty happy with this approach because this is essentially a fully functional migration system in just a handful of lines of python.

A Robot With a Soul

OPUS: The Day We Found Earth was released on Nintendo Switch this week. I picked it up and played through the main story in a few hours. There are few other games at the $5 price point that are worth playing in the Nintendo eShop. This simple game tells a very compelling story. Like most great short stories, it quickly establishes an emotional connection with the main characters and draws you in.

Lately, I’ve been thinking about video games as a medium for telling compelling stories. No one does this better than indie developers and the team at SIGONO delivers with this emotional adventure.

In OPUS, you play as a tiny robot who’s mission is to find the planet Earth in order to save the human race. You do this by exploring a vast galaxy from a space ship that is equipped with a powerful telescope. As you progress through the game you uncover additional parts of the space ship and begin to understand the curious circumstances in which the robot finds himself.

The game is short, the graphics are not revolutionary, and the game mechanics are very simple. However, where OPUS really shines is in the story that is told. The robot loves the woman who programmed him, he exhibits emotions, and you are quickly drawn in to feel sympathy and concern for his wellbeing. Coupled with the calming soundtrack by Triodust, you are immersed in the game and race against time to fulfill the seeming futile task of finding Earth.

I really loved this game. I can’t wait to see what comes next from Sigono and I would love to see more games like this in the Nintendo eShop.