diff --git a/Gemfile b/Gemfile index 0a677bf..7779847 100644 --- a/Gemfile +++ b/Gemfile @@ -6,3 +6,9 @@ source "https://rubygems.org" gem "jekyll", "~> 4.3" gem "jekyll-archives" +gem "nokogiri" +gem "liquid_reading_time" +gem "liquid_pluralize" +gem "jekyll-sitemap" +gem "jekyll-seo-tag" +gem "jekyll-feed" diff --git a/Gemfile.lock b/Gemfile.lock index e564778..6f236c8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -33,8 +33,14 @@ GEM webrick (~> 1.7) jekyll-archives (2.2.1) jekyll (>= 3.6, < 5.0) + jekyll-feed (0.17.0) + jekyll (>= 3.7, < 5.0) jekyll-sass-converter (3.0.0) sass-embedded (~> 1.54) + jekyll-seo-tag (2.8.0) + jekyll (>= 3.8, < 5.0) + jekyll-sitemap (1.4.0) + jekyll (>= 3.7, < 5.0) jekyll-watch (2.2.1) listen (~> 3.0) kramdown (2.4.0) @@ -42,13 +48,21 @@ GEM kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) liquid (4.0.4) + liquid_pluralize (1.0.3) + liquid (>= 2.6, < 5.0) + liquid_reading_time (1.1.3) + liquid (>= 2.6, < 5.0) + nokogiri (~> 1.6) listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) mercenary (0.4.0) + nokogiri (1.14.3-x86_64-linux) + racc (~> 1.4) pathutil (0.16.2) forwardable-extended (~> 2.6) public_suffix (5.0.1) + racc (1.5.1) rake (13.0.6) rb-fsevent (0.11.2) rb-inotify (0.10.1) @@ -70,6 +84,12 @@ PLATFORMS DEPENDENCIES jekyll (~> 4.3) jekyll-archives + jekyll-feed + jekyll-seo-tag + jekyll-sitemap + liquid_pluralize + liquid_reading_time + nokogiri BUNDLED WITH 2.4.7 diff --git a/_config.yml b/_config.yml index 53c6032..2bdcd61 100644 --- a/_config.yml +++ b/_config.yml @@ -1,8 +1,13 @@ plugins: - jekyll-archives + - liquid_reading_time + - liquid_pluralize + - jekyll-sitemap + - jekyll-seo-tag + - jekyll-feed permalink: pretty -baseurl: "/" +baseurl: "/andrewconl.in" url: "https://andrwcnln.github.io" defaults: @@ -20,7 +25,7 @@ defaults: values: permalink: til/:title/ category: til - layout: post + layout: til-post jekyll-archives: enabled: diff --git a/_layouts/default.html b/_layouts/default.html index f311ef7..9d61c4a 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -4,9 +4,7 @@ - - andrew conlin diff --git a/_layouts/post.html b/_layouts/post.html index 80efee5..7bd5349 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -2,13 +2,18 @@ layout: default --- +{% capture time %}{{ content | reading_time }}{% endcapture %} + {% assign categories = page.categories %} {% assign category = site.data.categories[categories.first] %} {% assign tags = page.tags %}

-  {{ page.date | date_to_string }}   |    +  {{ page.date | date_to_string }} +    |    +  {{ content | reading_time | pluralize: "minute" }} +    |      {{ categories.first }}     |    diff --git a/_layouts/til-post.html b/_layouts/til-post.html new file mode 100644 index 0000000..ef563e3 --- /dev/null +++ b/_layouts/til-post.html @@ -0,0 +1,27 @@ +--- +layout: default +--- + +{% assign categories = page.categories %} +{% assign category = site.data.categories[categories.first] %} + +{% assign tags = page.tags %} + +

+  {{ page.date | date_to_string }} +    |    +  {{ content | reading_time | pluralize: "minute" }} +    |    +   {{ categories.first }}  +    |    + + {% for tag in tags %} + {{ tag }} + {% if tag != tags.last %} + , + {% endif %} + {% endfor %} +

+
+ +{{ content }} diff --git a/_site/blog/2023/01/14/musings-on-the-cinema/index.html b/_site/blog/2023/01/14/musings-on-the-cinema/index.html index 5f026f1..898ca7f 100644 --- a/_site/blog/2023/01/14/musings-on-the-cinema/index.html +++ b/_site/blog/2023/01/14/musings-on-the-cinema/index.html @@ -4,9 +4,7 @@ - - andrew conlin @@ -109,8 +107,13 @@ + +

-  14 Jan 2023   |    +  14 Jan 2023 +    |    +  1 minute +    |      thoughts     |    diff --git a/_site/blog/2023/03/05/yuri-felsen-on-love/index.html b/_site/blog/2023/03/05/yuri-felsen-on-love/index.html index 1b5d469..e2d9b18 100644 --- a/_site/blog/2023/03/05/yuri-felsen-on-love/index.html +++ b/_site/blog/2023/03/05/yuri-felsen-on-love/index.html @@ -4,9 +4,7 @@ - - andrew conlin @@ -109,8 +107,13 @@ + +

-  05 Mar 2023   |    +  05 Mar 2023 +    |    +  1 minute +    |      quotes     |    diff --git a/_site/blog/2023/03/10/putting-thoughts-into-action/index.html b/_site/blog/2023/03/10/putting-thoughts-into-action/index.html index 43fa3ca..3b85ab9 100644 --- a/_site/blog/2023/03/10/putting-thoughts-into-action/index.html +++ b/_site/blog/2023/03/10/putting-thoughts-into-action/index.html @@ -4,9 +4,7 @@ - - andrew conlin @@ -109,8 +107,13 @@ + +

-  10 Mar 2023   |    +  10 Mar 2023 +    |    +  2 minutes +    |      thoughts     |    diff --git a/_site/blog/2023/04/29/links-arent-performances/index.html b/_site/blog/2023/04/29/links-arent-performances/index.html index 03dd762..053b80f 100644 --- a/_site/blog/2023/04/29/links-arent-performances/index.html +++ b/_site/blog/2023/04/29/links-arent-performances/index.html @@ -4,9 +4,7 @@ - - andrew conlin @@ -109,8 +107,13 @@ + +

-  29 Apr 2023   |    +  29 Apr 2023 +    |    +  1 minute +    |      links     |    diff --git a/_site/blog/index.html b/_site/blog/index.html index 86d7f3d..db76fec 100644 --- a/_site/blog/index.html +++ b/_site/blog/index.html @@ -4,9 +4,7 @@ - - andrew conlin diff --git a/_site/feed.xml b/_site/feed.xml new file mode 100644 index 0000000..d5f7173 --- /dev/null +++ b/_site/feed.xml @@ -0,0 +1,167 @@ +Jekyll2023-05-01T17:31:05+01:00http://localhost:4000/feed.xmlLinks aren’t performances2023-04-29T00:00:00+01:002023-04-29T00:00:00+01:00http://localhost:4000/blog/2023/04/29/links-arent-performances“For starters, it finds that publishing a link can be a “performance” of a copyrighted work, which meant that when Linkletter linked to the world-viewable Youtube files that Proctorio had posted, he infringed on copyright.

+ +

This is a perverse, even surreal take on copyright. The court rejects Linkletter’s argument that even Youtube’s terms of service warned Proctorio that publishing world-viewable material on its site constituted permission for people to link to and watch that material.”

+ +

Via: Pluralistic

]]>Running a Python script periodically in a Docker container using cron2023-04-19T00:00:00+01:002023-04-19T00:00:00+01:00http://localhost:4000/til/running-python-in-cron-in-dockerRecently, my partner gave a great idea for utilising my old Kindle: generate a “newspaper” each morning from a bunch of RSS feeds, and email it to the Kindle using “Send-to-Kindle” feature (a blog post about this project is in the works).

+ +

I loved this idea, and thought it would be no problem to get a Python script up and running periodically on my Raspberry Pi home server using cron. However, I ran into various issues along the way (some of which were not so easy to resolve), so I’m collating all the configuration changes I made in the hopes that it will be useful to someone one day. You can find the full repo for this project here, and I have also included my Dockerfile, docker-compose.yml and crontab at the end of this TIL.

+ +

1. Double check the user

+ +

A lot of problems with cron come down to user privileges. Each user has their own crontab, and then there is the system-wide root crontab. The first issue I ran into with creating a cron job inside a container was that Docker created the crontab as a non-root user. This issue presented itself to me when I tried to run the following command, to list the current cronjobs in the Docker container:

+
docker-compose exec container-name crontab -l
+
+

This returned the following output:

+
no crontab for root
+
+

Now, it is not necessarily a problem to have non-root cron jobs, but just make absolutely certain that you are creating the jobs with the user you expect. For me, I wanted to run as root, so I added to following line to my docker-compose.yml:

+
user: root
+
+

Now, the root user will be used when building your Docker image and the created crontab will be where you expect.

+ +

2. Missing dependencies

+

When cron calls your Python script, you may run into issues with ModuleNotFoundError or ImportError, where Python cannot find your installed packages. This is because cron does not have access to your system environment variables, including the Python path. You can resolve most of these errors with imports by adding the PYTHONPATH environment variable to your crontab. This should be the path to your site-packages folder, something like this:

+
PYTHONPATH=/usr/bin/local/python3
+
+

You may also need to add a shebang (#!) to your Python script to direct cron to the correct version. You can find the Python location with one of the following commands:

+
which python
+which py
+which python3
+
+

NOTE: These commands must be performed in your Docker container when it is up and running. In docker-compose syntax this would be the following (with the name of your container instead of container-name):

+
docker-compose exec container-name which python3
+
+

You can then add this to the top of your Python script, as follows:

+
#!/usr/bin/local/python3
+
+

3. Still missing dependecencies

+

Some modules will still run into errors even when the PYTHONPATH variable has been set. In particular, I ran into problems with reportlab and Pillow/PIL:

+
ImportError: cannot import name '_imaging' from 'PIL'
+
+

This was solved by adding the system PATH to the crontab as well. The system path is included in the default crontab that is created when you first run crontab -e:

+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+
+

Therefore, it is a good idea to include it if you are making a new crontab to make sure cron can find everything it needs to.

+ +

4. Check relative paths in Python

+

By default, cron runs from the default root path. Therefore, both your call to Python in your crontab and the filepaths within Python should either be relative to root (i.e /main.py rather than main.py) or just use full paths instead.

+ + +

This error is related to Python inside a Docker container rather than cron. However, someone might still find it useful. When you install your requirements.txt, you may encounter errors such as

+
legacy-install-failure
+error: command '/usr/bin/gcc' failed with exit code 1
+fatal error: Python.h: No such file or directory
+
+

I was able to resolve these by adding python3-dev, wheel and Cmake to my requirements.txt. These are sometimes required when packages include other binaries or need to compile other code when installed.

+ +

6. Other useful tips

+
    +
  • crontab.guru is a great resource for checking cron syntax
  • +
  • Installing vim/nano in your Docker container to make the debugging stage easier. This is especially useful for changing your crontab to run much more frequently, or adding debugging messages etc., when the container is up.
  • +
+ +

I hope this helped you resolve some errors! I’ve included my Dockerfile, docker-compose.yml and crontab below if you want to set up a similar project or adjust your own files. The full repo is also available here.

+ +

Dockerfile:

+
FROM python:3
+
+COPY . .
+RUN python3.11 -m pip install --no-cache-dir -r requirements.txt
+
+RUN touch /var/log/cron.log
+
+RUN apt-get update \  
+&& apt-get install cron -y
+
+RUN chmod +x main.py
+
+RUN crontab crontab 
+
+CMD cron -f
+
+

docker-compose.yml:

+
version: "2.4"
+
+services:
+  watchman:
+    platform: "linux/arm64/v8"
+    image: watchman:latest
+    container_name: watchman
+    restart: always
+    user: root
+    build:
+      context: build
+      dockerfile: Dockerfile
+
+

crontab:

+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+PYTHONPATH=/usr/bin/local/python3
+15 7 * * * python3 /main.py >> /var/log/cron.log 2>&1
+
+
]]>
A measure of how easily thoughts can be translated to action2023-03-10T00:00:00+00:002023-03-10T00:00:00+00:00http://localhost:4000/blog/2023/03/10/putting-thoughts-into-actionRecently, I’ve been using multiple different languages and frameworks (both at work and personally) and I’ve been thinking about why I prefer some over others. Ultimately, I think it comes down to this:

+ +

How easily can I translate what I am thinking about into a working setup?

+ +

That is, how much effort needs to go into converting my idea into a solution? (If there is not already a word for this, then there should be. Don’t worry, I am willing to take the hit and have it named after me.)

+ +

For example, I’ve been building this website over the past month or so. Generally, for static websites, I think that HTML + CSS are very good at allowing me to get what I see in my head running on localhost. At this point CSS has so many different options that you just need to find the right search terms in order to get what you want.

+ +

However, they are both lacking somewhat in intuitiveness. Especially when starting out, it can get very confusing to know the right tags and the right syntax and the right placement (and so on) to realise your vision.

+ +

This is where services like Squarespace et al. come into play. They give you that intuitive UI, dragging and dropping of features, resizing and changing colours. They make it super duper easy to do the actual building, at the cost of the range of bricks you can use.

+ +

So, we have two measures:

+
    +
  1. Can I do everything I want to?
  2. +
  3. How easy is it?
  4. +
+ +

These are usually a direct tradeoff, with ease typically preferred over options. This tends to frustrate me, as I want full control of all those little configurations.

+ +

The solution to this, at least for me, are frameworks such as Bootstrap and Jekyll. They put a layer between the user and the options; essentially translating and simplying all the little configurations into something much easier to work with. Columns in Bootstrap make page layouts simple; markdown-to-html parsing in Jekyll makes text formatting a breeze. But, most importantly of all, these frameworks don’t sacrifice on the possibilities. They make it easier to apply complex setups, but if you want to go in and tweak absolutely everything to your liking, go right ahead. By providing the user with simpler ways of doing the same things as before, they manage to bridge the gap between Can I do everything I want to? and How easy is it?. And I think that is beautiful.

]]>
Yuri Felsen on love2023-03-05T00:00:00+00:002023-03-05T00:00:00+00:00http://localhost:4000/blog/2023/03/05/yuri-felsen-on-love“Like everyone, I have my own, maybe obsessive futile, maybe in some way authentic, vision: all of a sudden, I will imagine the entire homogenous world as it is revealed to us-the streets, the cities, the rooms, those intelligent beasts of a sad and predatory nature, who have learn to stand on their hind legs, who have built all this but are fated to disappear, who, despite this, still try to cling to something solid and lasting, still try to ward off the inevitability of death, who dreamt up fairy tales and, now that these stories have been disproved, are disconsolate - and for me the only means of defending myself from our terrible fate is love, my love - Lyolya. Without love we fall into a stupor or despair, it covers our naked animal essence; with the fear of death, with deliberate attempts to grab hold of some kind of eternity, one that is at once a mystery to us and yet devised by us, even the remains of love, even its very echo in music, imbues us with a semblance of fearlessness, dignity and the spiritual range to disregard death. Only by loving, by knowing about love, hoping for love, are we inspired and meaningfully engaged in life, able to banish the sovereignty of petty day-to-day cares, to stop waiting for the end to come”

+ +

- Yuri Felsen (trans. Bryan Karetnyk)

+ +

From ‘Deceit’, first published in 1930 and translated to English in 2022.

]]>
Fixing php errors in a Nextcloud docker-compose configuration2023-03-01T00:00:00+00:002023-03-01T00:00:00+00:00http://localhost:4000/til/nextcloud-php-errorsI was trying to rescan the files in my Nextcloud server (running on Raspberry Pi 4 with DietPi), and kept running into some weird php errors.

+ +

First error - “could not find driver”

+ +

I was trying using the following syntax to call occ and scan the files:

+ +
sudo -u www-data php /path/to/nextcloud/occ files:scan --all
+
+ +

but I kept running into a PHP error. Specifically this error:

+ +
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: could not find driver in /path/to/nextcloud/lib/private/DB/Connection.php:139
+
+ +

followed by a long, verbose stack trace.

+ +

It took me a decent amount of time to diagnose the exact issue, but eventually I found this list of required PHP modules in the Nextcloud admin manual.

+ +

Running php -m will print out the list of currently installed PHP modules. I noticed I was missing quite a few of the required modules, but the one that was causing my issue was the missing pdo_mysql module. +This can be installed by running:

+ +
sudo apt-get install php7.4-mysql
+
+

Note: This command will change based on your OS, PHP version and database type

+ +

This resolved the error! However (as is always the case), this only meant I got a shiny new error instead:

+ +

Second error - “Name or service not known”

+ +
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known in /path/to/nextcloud/lib/private/DB/Connection.php:139
+
+ +

From first glance, this looks like something wrong in the DNS name resolution. This sent me a long way down the wrong path, changing a whole bunch of things in my docker-compose.yml file. +Eventually however, after a long and perilous journey over the high seas of Nextcloud forums and StackOverflow, I found this example of running php occ in a docker-compose configuration. +This led me to running this command:

+ +
docker-compose exec -u www-data nextcloud-app php occ files:scan --all
+
+

Note: replace nextcloud-app with the name of your Nextcloud container. Also, this command must be run from the directory of your Nextcloud docker-compose.yml

+ +

….aaaaaand, voila! The command runs, the files are scanned and everything is up to date.

+ +

terminal output showing the files that have been successfully been scanned

]]>
Musings on the power of cinema2023-01-14T00:00:00+00:002023-01-14T00:00:00+00:00http://localhost:4000/blog/2023/01/14/musings-on-the-cinemaI’ve realised that going to the cinema makes me sad; a quiet, contemplative melancholy. Ennui. No matter the film, something about the cinema experience is meditative for me. I always look at things differently in the aftermath; like my perception is temporarily knocked off balance. No, more like a fog is lifted for a while. I especially enjoy that time immediately after, the cycle home. I notice so many little details, scenes of beauty and of strange nostalgia. Like I’m finally seeing the world how it is, or rather, I begin to see rather than look, listen rather than hear. I feel as though these moments, however brief, are when I am truly in touch with myself. My soul, my inner essence. This is why I love the cinema. These moments of private melancholy, of temporary clarity. It is a feeling I cannot replicate anywhere else in my life.

]]>
\ No newline at end of file diff --git a/_site/index.html b/_site/index.html index 442eecd..4af1a24 100644 --- a/_site/index.html +++ b/_site/index.html @@ -4,9 +4,7 @@ - - andrew conlin diff --git a/_site/robots.txt b/_site/robots.txt new file mode 100644 index 0000000..d297064 --- /dev/null +++ b/_site/robots.txt @@ -0,0 +1 @@ +Sitemap: http://localhost:4000/sitemap.xml diff --git a/_site/sitemap.xml b/_site/sitemap.xml new file mode 100644 index 0000000..5b77618 --- /dev/null +++ b/_site/sitemap.xml @@ -0,0 +1,108 @@ + + + +http://localhost:4000/blog/2023/01/14/musings-on-the-cinema/ +2023-01-14T00:00:00+00:00 + + +http://localhost:4000/til/nextcloud-php-errors/ +2023-03-01T00:00:00+00:00 + + +http://localhost:4000/blog/2023/03/05/yuri-felsen-on-love/ +2023-03-05T00:00:00+00:00 + + +http://localhost:4000/blog/2023/03/10/putting-thoughts-into-action/ +2023-03-10T00:00:00+00:00 + + +http://localhost:4000/til/running-python-in-cron-in-docker/ +2023-04-19T00:00:00+01:00 + + +http://localhost:4000/blog/2023/04/29/links-arent-performances/ +2023-04-29T00:00:00+01:00 + + +http://localhost:4000/blog/ + + +http://localhost:4000/ + + +http://localhost:4000/til/ + + +http://localhost:4000/blog/tag/journal/ + + +http://localhost:4000/blog/tag/cinema/ + + +http://localhost:4000/blog/tag/film/ + + +http://localhost:4000/blog/tag/php/ + + +http://localhost:4000/blog/tag/nextcloud/ + + +http://localhost:4000/blog/tag/docker/ + + +http://localhost:4000/blog/tag/docker-compose/ + + +http://localhost:4000/blog/tag/yuri-felsen/ + + +http://localhost:4000/blog/tag/love/ + + +http://localhost:4000/blog/tag/html/ + + +http://localhost:4000/blog/tag/css/ + + +http://localhost:4000/blog/tag/bootstrap/ + + +http://localhost:4000/blog/tag/jekyll/ + + +http://localhost:4000/blog/tag/webdev/ + + +http://localhost:4000/blog/tag/cron/ + + +http://localhost:4000/blog/tag/python/ + + +http://localhost:4000/blog/tag/kindle/ + + +http://localhost:4000/blog/tag/copyright/ + + +http://localhost:4000/blog/tag/law/ + + +http://localhost:4000/blog/tag/pluralistic/ + + +http://localhost:4000/blog/category/thoughts/ + + +http://localhost:4000/blog/category/til/ + + +http://localhost:4000/blog/category/quotes/ + + +http://localhost:4000/blog/category/links/ + + diff --git a/_site/til/index.html b/_site/til/index.html index 3492748..7538751 100644 --- a/_site/til/index.html +++ b/_site/til/index.html @@ -4,9 +4,7 @@ - - andrew conlin diff --git a/_site/til/nextcloud-php-errors/index.html b/_site/til/nextcloud-php-errors/index.html index 7605fa8..9d8ed35 100644 --- a/_site/til/nextcloud-php-errors/index.html +++ b/_site/til/nextcloud-php-errors/index.html @@ -4,9 +4,7 @@ - - andrew conlin @@ -110,8 +108,11 @@

-  01 Mar 2023   |    -   til  +  01 Mar 2023 +    |    +  2 minutes +    |    +   til     |    diff --git a/_site/til/running-python-in-cron-in-docker/index.html b/_site/til/running-python-in-cron-in-docker/index.html index c8672a9..146d78a 100644 --- a/_site/til/running-python-in-cron-in-docker/index.html +++ b/_site/til/running-python-in-cron-in-docker/index.html @@ -4,9 +4,7 @@ - - andrew conlin @@ -110,8 +108,11 @@

-  19 Apr 2023   |    -   til  +  19 Apr 2023 +    |    +  3 minutes +    |    +   til     |