Irish time! A picture of the place where I almost died of hypothermia.

Forty Foot, Dublin (Ireland)
Forty Foot, Dublin (Ireland)

Anki Flashcards generator

Mnemocards 0.1.3 is out! This version of Mnemocards is the first one to be public available for everyone. Last version were already public but not well documented. That’s what I did during a couple of days of this week, adding documentation and improving some important details of the code.

I want to keep a constant public API so people do not need to change their cards_config.json files every time a new version is out. I did some little changes in the structure of the configuration file and I think now it’s ready to be public for everyone.

Also, I invest a lot of time trying to publish the package on PyPi. This error makes me invest 3 times more time as I was expecting:

ERROR: Packages installed from PyPI cannot depend on packages which are not also hosted on PyPI.
mnemocards depends on genanki@ git+https://github.com/guiferviz/genanki.git@feature-deck-conf

Some weeks ago I made a fork of Genanki to add new features (deck configurations) and those changes are still not merged into the package. I don’t think they will ever be merged, because the pull request didn’t get very good reception (no comments, no likes… I’m very sad about it). So I need to rely on my fork as a dependency to Mnemocards. How did I solved this problem?

There isn’t any good solution to this, so I choose to change my installing instructions. Instead of installing with pip install mnemocards your should install the package in two steps:

pip install --no-deps mnemocards
pip install mnemocards

For some reason, installing the package first and install the dependencies later seems to work fine. It also works when installing it from source with python setup.py install.

The dependency in the requirements.txt file looks like this:

genanki @ git+https://github.com/guiferviz/genanki.git@feature-deck-conf

Another alternatives for solving this problem are:

  • Publish my own version of Genanki to PyPi and use that as a reference.
  • Add the fork as a git submodule and include the code in my project as a vendor library.
  • Host your own PyPi server and use --extend-index-url to install your own version of the packages.

I think that my solution does not work when you add Mnemocards in any other requirements.txt, just because you cannot specify there install without dependencies and later install dependencies. Anyway, for installing applications that are not supposed to be used as a dependency for other packages it seems a good workaround. Hope this helps someone.

This is the Mnemocards repository on GitHub. Try it out!

Uranium

Not too much visible work in Uranium, apart from publishing the post 01 about compiling and installing LLVM, Clang, Flex and Bison.

I’ve been reading the dragon book of compilers, chapter 3 about grammars. Still reading it.

Competitive programming - CodeForces

My favourite problem of the week is problem D of competition 1343. I used prefix sums to solve it in linear time.

def solve():
    # Read input.
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))

    h = n // 2
    c = [0] * (2*k+2)
    for i in range(h):
        # Two changes
        c[0] += 2
        # No change in this pair.
        p = a[i] + a[n-i-1]
        c[p] += -1
        c[p+1] += 1
        # Only one change.
        min_sum_1 = min(a[i], a[n-i-1]) + 1
        max_sum_1 = max(a[i], a[n-i-1]) + k
        c[min_sum_1] += -1
        c[max_sum_1+1] += 1
    # Compute prefix sum.
    s = 0
    for i in range(len(c)):
        s += c[i]
        c[i] = s

    print(min(c))

What about next week?

Continue with the Uranium series, maybe a new CodeForces programming competition and pick up AIdictive, my old ML library to try to launch a first version in two weeks.