Contributing to Inkscape

Completed
  • Read this charter about Website moderators.
  • Requested an membership to the Moderators
Todos
Open Souce Is Not About You

Open Source Is Not About You by Rich Hickey simply reminded me that open source tools are “free”, as he says, “Open source is a no-strings-attached gift”. I sometimes forget that they are free, and feel like wanting to make an “Issue” on projects that I have never contribute to. The main point he makes is that people should not complain without doing anything for it, and even if they contribute to the project, they do not have the right to claim their needs which is not for the project itself. I deeply agree with this, and I should always think about it carefully as I contribute to projects.

Shell Script

I was trying to create some files for future posts and thought like why don’t I just we create everything at once. What I needed to know was if there are such commands that return the nearest coming Sunday from today. Of course, there weren’t any commands that get a specific day and return a date which is closest from today. What I found from the man page was a format string called %wthat returns a number which represents the day of the week. For example, if today is 2020-03-10 which is Tuesday, and the command date +%w returns 2 where 0 is Sunday, and 6 is Saturday. If I subtract this number from seven, I can get the difference from today between next Sunday. It also looks like there’s format which adds x days to the given date, that is + x days. Perfect. Then, command will look like:

date -d "$(date) + $((7-$(date -d $(date) +%w))) days"

where $(date) returns today’s date for the default value. This returns next Sunday. However, there was a problem that if today was Sunday, it would still return next Sunday. One might want to add a file for the day as well. To make it this Sunday or today, there is a format string for this (I am not sure it really is for this). The format is %u which also returns a number of the day in a week like %w does, but the value of this one is starting from 1 as Monday whereas %w starts from 0 Sunday. The part in the command above:

((7-$(date -d $(date) +%w)))

returns 7 if today is sunday which adds another week from today’s value; however, by replacing %w tp %u, we can get 0, the command is:

date -d "$(date) + $((7-$(date -d $(date) +%u))) days"

Now I have the value of this coming Sunday. The next step is to compare the values so that we can iterate by incrementing the dates, and stop before the date given. The operator < and > will do it, but it doesn’t return true if values are equal. The date command will return as is when I pass a date string. For example, if I run date, it returns something like this:

Tue Mar 10 12:20:44 EDT 2020

however, if I put date -d "2020-03-10", this gives me:

Tue Mar 10 00:00:00 EDT 2020

because I didn’t pass the date with no specific time, so I need those ‘less or greater than or equal to’ operators for this. Unfortunately, the -le -ge options do not work for dates, but it can be done using %s format. According to the man page, the option returns an integer value "seconds since 1970-01-01 00:00:00 UTC". Since it is an integer value, we can compare the equality of them. Finally, I ended up the script which creates files named formatted YYYY-MM-DD-WEEK_NUM.md with checking if the files already exist. I also have to add +%D to the command which gets today’s date since it returns a date with specific time without the format.

#!/bin/bash
today=$(date +%D)
this_sunday=$(date -d "$today + $((7-$(date -d "$today" +%u))) days")
first_day=2020-02-02
last_day=2020-05-22

next_sunday="$first_day"
i=1

while [[ $(date -d "$next_sunday" +%s) -le $(date -d "$last_day" +%s) ]];
do
    if [[ $(date -d "$this_sunday" +%s) -le $(date -d "$next_sunday" +%s) ]];
    then
        printf -v filename "%s/%s-week%02d.md" "$PWD" "$next_sunday" "$i"
        if [[ -f "$filename" ]];
        then
            echo "$filename already exists."
        else
                ## Create a file with header
                printf  '%s\n%s\n%s%d\n%s\n' "---" "layout: post" \
                "title: Week " "$i" "---" >> "$filename"

                echo "Created" "$filename"
        fi
    fi
    i=$(($i+1))
    next_sunday=$(date -d "$next_sunday + 7 days" +%Y-%m-%d)
done

However, the setting does not hide the upcoming posts for some reason. Yes, I have wasted sometime… But, it was good to know how those commands work.

Outside Activity

I made two contributions to OSM. Added a shrine and a community hall in my hometown.

Written before or on March 15, 2020