1027SSH Key Permissions too open

This warning is pretty self- explanatory:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/Users/georg/.ssh/my_rsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.

Solution

Limit the key to read/write access by the user only:

chmod 600 ~/.ssh/my_rsa_key

It's also possible to make it only readable by the user, but then you need to chmod every time you want to update/change it.

chmod 400 ~/.ssh/my_rsa_key

Sources: StackOverflow

1025hugo Shortcuts

Quick run through hugo Installation & Update on macOS.

Install hugo

brew install hugo

Check Version

hugo version

hugo v0.109.0+extended darwin/amd64 BuildDate=unknown

Upgrade hugo

brew upgrade hugo
Warning: hugo 0.109.0 already installed

Create New Site

hugo new site my-new-hugo-site
cd my-new-hugo-site
git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke themes/ananke
echo "theme = 'ananke'" >> config.toml

hugo does not come with an in-built theme, therefore we need to clone the anake theme into themes/ananke. More hugo themes. Clone and update config.toml.

Serve Site

hugo server

Build Site

Just hugo, nothing else.

hugo
Start building sites … 
hugo v0.109.0+extended darwin/amd64 BuildDate=unknown
INFO 2022/12/26 19:37:15 syncing static files to /

                   | EN  
-------------------+-----
  Pages            | 10  
  Paginator pages  |  0  
  Non-page files   |  0  
  Static files     |  1  
  Processed images |  0  
  Aliases          |  1  
  Sitemaps         |  1  
  Cleaned          |  0  

Total in 154 ms

1024mkDocs Shortcuts

Quick run through mkDocs Installation & Update on macOS.

Install mkDocs

pip install mkdocs

Check Version

mkdocs -V

mkdocs, version 1.1.2 from /usr/local/lib/python3.9/site-packages/mkdocs (Python 3.9)

Update mkDocs

pip install -U mkdocs
mkdocs -V

mkdocs, version 1.4.2 from /usr/local/lib/python3.9/site-packages/mkdocs (Python 3.9)

Install mkdocs-material

pip install mkdocs-material

Update to latest mkdocs-material

pip install -U mkdocs-material

Create new mkDocs Site

mkdocs new my-new-site

Start Serving Site

cd my-new-site
mkdocs serve

Stop Serving Site

⌨️: ^[ctrl]-C

1021Facebook Custom Share Link

Facebook's depreciate Custom Share Link (as of 2022). Still work, but not recommended.

https://www.facebook.com/sharer/sharer.php?u=custom_url

Share this post!

1019Importing Screenshots to Photos with Automator

A simple Automator Action to import Screenshots in OSX into Photos:

  • Select the Folder to which the Action is attached
  • "Add to existing top-level album" - called "Screenshots"

I also have my Screenshots Folder on Dropbox, the Folder Actions are attached to that Folder.

1017Finding and Deleting Files without Content

Finds all empty JPEGs at current directory:

find . -maxdepth 1 -name "*.jpg" -size 0

Finds and deletes all empty JPEGs at current directory:

find . -maxdepth 1 -name "*.jpg" -size 0 -delete

Finds and deletes all empty JPEGs in all sub-directories.

find . -maxdepth 2 -name "*.jpg" -size 0 -delete

Sources: 1, 2

1014Installing IIJmio Sim-Card on iPhone

Problem: IIJMIO Network not working: Solution: Dowload and Install Profile

  1. Go to https://t.iijmio.jp/en/apn/
  2. Download and Install the Profile
  3. That's it.

1010Importing a MySQL File with Command Line

Working with XAMPP and and phpMyAdmin makes dealing with databases more visual, but importing large db dumb files can fail/take a long time.

Importing from the command line is faster and more stable.

Use the XAMPP mysql, if there is not a global mysql

cd /Applications/XAMPP/xamppfiles/bin 

Import on Local Server

mysql -u username -p db_name < ~/path/to/db/file.sql

Import with specified Server

mysql -u username -p -h hostname db_name  < ~/path/to/db/file.sql

Checking Status of MySQL Server

mysqladmin -u username -p -h hostname status
  • -p asks for the password on execution
  • Importing a ca. 300MB file takes ca. 5 seconds.
  • Make sure the DB "db_name" already exists.

Troubleshooting

I exported all the DB from one installatino as one, big localhost.sql and then tried to import it in another one. That creates the following error:

ERROR 2006 (HY000) at line 127571: MySQL server has gone away

Some DBs have been imported, but not all.

Workaround: Export/Import DBs individually.

1008JS Loops and async/await

I've been trying to get data from an API, a async call is used to parse the data. I've be naively iterating over the responses with forEach, calling await in the forEach function, and wondering why it is not producing the result I expected, i.e. wait for the data to settle.

NG:

async function getData() {
  output = ""
  results.forEach(async (block) => {   
    var b = await abc.parse(block)
    output += b
  })
}

Solution

Use a standard for or for..of to loop over the list:

async function getData() {
  output = ""
  for (const block of results) {
    var b = await abc.parse(block)
    output += b
  }
}

1007Regenerating Thumbnails in WordPress

Option 1: Plugin

The Regenerate Thumbnails Plug-in.

This option is usualy slower - and some hosting providers might confuse it for a malicious attach and block the IP.

Option 2: WP-CLI

WP-CLI is the command line interface for WordPress/ClassicPress.

Installation

From the WP-CLI Guide

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Run --info from your WP root directory, to check if it works:

php wp-cli.phar --info

If you get a json_encode error, it means your PHP version is not compatible with WP-CLI.

PHP 7 was the default on one server, it did not work.

Check for other PHP versions
which php
// /usr/bin/php

ls /usr/bin/php* 
// php80 php81 php82 php83

Let's use the latest verson of PHP.

php83 wp-cli.phar --info

Regenerating

Regenerate all images, without confirmation.

php83 wp-cli.phar media regenerate --yes

Regenerate thumbnails only.

$ php83 wp-cli.phar media regenerate --image_size=thumbnail

More options for regenerating images with WP-CLI:

# Regenerate thumbnails for given attachment IDs.
php83 wp-cli.phar media regenerate 123 124 125

# Re-generate all thumbnails that have IDs between 100 and 200.
seq 100 200 | xargs php83 wp-cli.phar media regenerate

# Re-generate all thumbnails that have IDs between 100 and 200.
seq 100 200 | xargs php83 wp-cli.phar media regenerate

# Re-generate all thumbnails that have IDs between 100 and 200, only thumbnails
seq 100 200 | xargs php83 wp-cli.phar media regenerate --image_size=thumbnail

#### Error

`Error: Error establishing a database connection.`

When working on _localhost_, use `127.0.0.1` instead of `localhost` in wp.config
```php
define( 'DB_HOST', '127.0.0.1' );