Arch linux thumbnails

The package is tumbler.

Fixed my timers (Bash, redirects, >)

I had two problems with my timer system: that it doesn’t work when the files are empty (because of the split I did in the code), and the files that grew exponentially, because they did not get deleted at the end of the timer.

I am not sure why did the > in the timer command leave the previous file contents (I assume it’s some magic with terminals and ^M?), but I fixed it by adding : > outfile to the command at the beginning.

From this tutorial:


   : > filename
      # The > truncates file "filename" to zero length.
      # If file not present, creates zero-length file (same effect as 'touch').
      # The : serves as a dummy placeholder, producing no output.

   > filename
      # The > truncates file "filename" to zero length.
      # If file not present, creates zero-length file (same effect as 'touch').
      # (Same result as ": >", above, but this does not work with some shells.)

My zsh was apparently one of the shells where that doesn’t work, but the first one worked nicely. So the final line in .i3/config is:

    bindsym Mod3+n exec ": > ~/s/sounds/outpomo && utimer -c 15m > ~/s/sounds/outpomo && mpg123 ~/s/sounds/tib.mp3"
    bindsym Mod3+Shift+s exec ": > ~/s/sounds/outpause && utimer -c 5m > ~/s/sounds/outpause && mpg123 ~/s/sounds/cl.mp3"

The files-not-existing thing was fixed by an additional try/catch block. The final (still bad) code looks like this:

    while True:
        line, prefix = read_line(), ''
        # ignore comma at start of lines
        if line.startswith(','):
            line, prefix = line[1:], ','

        j = json.loads(line)

        # Files with the output of utimer:
        tfile="/home/sh/s/sounds/outbash"
        tfile2="/home/sh/s/sounds/outpomo"
        tfile3="/home/sh/s/sounds/outpause"

        def rtime(tfile, color):
            try:
                with open(tfile, "r") as f:
                    # last line of the file
                    try:
                        t=f.readlines()[-1] # If file is empty
                    except IndexError:
                        t="O"
            except IOError: 
                # If the file doesn't exist at all
                t="O"
            # Utime seems to add a \n(^M?); at the end
            # We use it as a way to check that the timer has stopped
            # When it stops, a \n is added.
            if "\n" not in t:
                if t!="O":
                    to=t.split("ing:")[1]
                    j.insert(0, {'full_text': '%s' % to, 'color':'%s'%color})

        tcolor1="#FF0F02"
        tcolor2="#FFFFFF"
        tcolor3="#FA0FF2"

        rtime(tfile, tcolor1)
        rtime(tfile3, tcolor3)
        rtime(tfile2, tcolor2)

Jekyll pagination fun

Pagination – highlighted posts

I wanted to output the first couple of posts in full, and the next ones until the end of the page as excerpts for the first page, and for all the next pages – only the excerpts. This SO answer helped me, I didn’t know about offset and limit in for loops!

  {%- if site.posts.size > 0 -%}
      <h2 class="post-list-heading">Posts</h2>
      <ul class="post-list">
        <!-- This loops through the paginated posts -->
        <!-- If we're on the first page, output the first 3 posts in full-->
        {% if paginator.page == 1%}
          {% for post in paginator.posts limit:3 %}
          <h1><a href="{{site.url}}{{ post.url }}">{{ post.title }}</a></h1>
            <p class="author">
              {% assign date_format = site.minima.date_format | default: "%b %-d, %Y" %}
              <span class="post-meta">{{ post.date | date: date_format }}</span>
            </p>
            <div class="content">
              {{ post.content }}
              <br>
            </div>
          {% endfor %}
        {% else %}
        <!-- if not on the first page, output only the excepts-->
          {% for post in paginator.posts limit:3 %}
          <h1><a href="{{site.url}}{{ post.url }}">{{ post.title }}</a></h1>
            <p class="author">
              {% assign date_format = site.minima.date_format | default: "%b %-d, %Y" %}
              <span class="post-meta">{{ post.date | date: date_format }}</span>
            </p>
            <div class="content">
              {{ post.excerpt }}

              {% if post.excerpt != post.content %}
                  <a href="{{ site.baseurl }}{{ post.url }}">Read more...</a>
              {% endif %}
              <br>
              <br>
            </div>
          {% endfor %}
        {% endif %}

        <!-- The remaining posts either way should be excerpts -->
        {% for post in paginator.posts offset:3 %}
        <h1><a href="{{site.url}}{{ post.url }}">{{ post.title }}</a></h1>
          <p class="author">
            {% assign date_format = site.minima.date_format | default: "%b %-d, %Y" %}
            <span class="post-meta">{{ post.date | date: date_format }}</span>
          </p>
          <div class="content">
            {{ post.excerpt }}

            {% if post.excerpt != post.content %}
                <a href="{{ site.baseurl }}{{ post.url }}">Read more...</a>
            {% endif %}
            <br>
          </div>
        {% endfor %}

Pagination – removing the pages from the header with unless

I’m not sure what happened, but I saw all the generated paginator pages in the menu, all called “Posts”. I removed it by overriding the layout with unless, which is another really nice operator.

The relevant code in _includes/header.html:

        <div class="trigger">
          {%- for path in page_paths -%}
            {%- assign my_page = site.pages | where: "path", path | first -%}
            {%- if my_page.title -%}
            {% unless my_page.title == "Posts" %}
            <a class="page-link" href="{{ my_page.url | relative_url }}">{{ my_page.title | escape }}</a>
            {% endunless %}
            {%- endif -%}
          {%- endfor -%}
        </div>

DNB and Typing