1062Resetting a User Password in ProcessWire

It happens to best of us: You have an local installation of your favourite CMS - and then you can't remember the password! Login throtteling kicks in, you still can't remember it. And this being a local XAMPP installation, you can't send an email to recover the password.

Here is Ryan1 to the resuce:

You can always reset your password just by pasting this temporarily into any one of your templates, and then viewing a page that uses the template:

$u = $users->get('admin'); // or whatever your username is
$u->of(false); 
$u->pass = 'your-new-password';
$u->save();

1 Who is Ryan? Ryan Cramer is the founder and lead developer of ProcessWire.

1060Getting multiple ACFs via raw MySQL in ClassicPress

ACFs are a great (legacy?) way of storing additional data in a ClassicPress/Wordpress installtion. But things can get a but ugly when you have thousands of posts, each with ACFs maybe nested Repeater ACFs. Getting data out of larger installation with get_posts and WP_Query can quickly hit the limits of the DB installation and fail.

The solution? A raw, hand-crafted MySQL query:

Getting a Single Custom Field

SELECT wp_postmeta.meta_value             // return the meta_value
  FROM wp_posts, wp_postmeta
  WHERE wp_posts.post_status = 'publish'    // publish posts only
   AND wp_posts.ID = wp_postmeta.post_id
   AND wp_postmeta.meta_key = 'my_key'       // get value from 'my_key'

Getting the results with $wpdb->get_results().

$results = $wpdb->get_results($query);

Example Output

Array
(
    [0] => stdClass Object
        (
            [meta_value ] => 123
        )
    [1] => stdClass Object
        (
            [meta_value ] => 456
        )
)

That works great, if you want to get one Custom Field, but how about multiple Custom Fields?

Getting Multiple Custom Fields

Custom fields are stored in the wp_postmeta table and defined by the meta_key and meta_value column.

SELECT p.ID, m1.meta_value as v1, m2.meta_value as v2 
FROM wp_posts p
LEFT JOIN wp_postmeta m1 ON p.ID = m1.post_id
LEFT JOIN wp_postmeta m2 ON p.ID = m2.post_id
WHERE p.post_status='publish'
AND m1.meta_key = 'my_key'
AND m2.meta_key = 'my_other_key'

Is it important to note - and slightly unintuitive - that the select line also declares aliases which will be used in the rest of the query:

  1. The p in p.ID is a shortcut for wp_posts
  2. The m1 in m1.meta_value is a shortcut for wp_postmeta
  3. Same as m2, but we want to select and JOIN different meta key we also need to have two shortcuts for wp_postmeta.
  4. meta_value as v1 is also important. If we would not use ... as v1 then the return array would include meta_value as a key and m2 would overwrite m1. Does not have to be v1 and v2, use whatever you like.

Example Output

Array
(
    [0] => stdClass Object
        (
            [ID] => 123
            [v1] => 33
            [v2] => 20130402
        )
    [1] => stdClass Object
        (
            [ID] => 456
            [v1] => 22
            [v2] => 20130404
        )
)

Getting Multiple Custom Fields including ACF Repeater

The ACF Repeater fields also stores its values in wp_postmeta, following this schema: repeatername_nr_fieldname. Let's say we have a repeater field called videos and a sub-field called video, the meta_keys in wp_postmeta would look like this:

videos_0_video
videos_1_video
videos_2_video
videos_3_video
...

That means we need to modify the previous query, because the we can't be sure how many meta_key we have.

SELECT p.ID, m1.meta_value as v1, m2.meta_value as v2 
FROM wp_posts p
LEFT JOIN wp_postmeta m1 ON p.ID = m1.post_id
LEFT JOIN wp_postmeta m2 ON p.ID = m2.post_id
WHERE p.post_status='publish'
AND m1.meta_key REGEXP '[[:<:]]videos_[0-9]*_video[[:>:]]' 
AND m1.meta_value > 0
AND m2.meta_key = 'my_key'

AND m1.meta_key REGEXP '[[:<:]]videos_[0-9]*_video[[:>:]]' is a regular expression with some MySQL-specific syntax: [[:<:]] means beginning of string and [[:>:]] stands for end of string.

Sources

1053Creating & Displaying a Local Javacript-based Clock

Problem

Organizing meeting across time-zones can lead to mis-communication of the meeting start-times, especially when daylight-saving-time changes are involed.

Solution

Show the Meeting Start Time AND the current Local Time at the Meeting Website.

var f = new Intl.DateTimeFormat([], {
  timeZone: 'Asia/Tokyo',
  hour: 'numeric',
  minute: 'numeric',
  second: 'numeric',
  hourCycle: 'h23'
})
var setTime = () => document.getElementById('time').innerHTML = f.format(new Date())
setTime()
setInterval(() => setTime(), 1000)
</script>

Intl.DateTimeFormat creates a new Intl formatter. Time to be displayed: Asia/Tokyo. Displayed are only: hour, minute and second. The hourCycle' optionh23` sets the display to a 24h clock.

setTime is a function that sets the innerHTML of id element time to the current Date, formatted with the Intl date.

setTime() call the function once on load.

setInterval() repeatetly calls the setTime() function to update the clock.

1052Redirecting with meta & refresh

A basic redirect from one website to another:

<meta http-equiv="refresh" content="0; URL=https://www.trembl.org" />
  • content is the dealy in milliseconds
  • URL is the target url

1051Wget & Multibyte

Making a copy of a website with wget should work like that:

wget -r mywebsite.com

-r recursively crawls the site, default is until level 5.

With filenames with non-latin characters, wget is not happy:

bash Incomplete or invalid multibyte sequence encountered Incomplete or invalid multibyte sequence encountered Incomplete or invalid multibyte sequence encountered Incomplete or invalid multibyte sequence encountered

That seems to be a bug in wget.

Workaround

wget -r --restrict-file-names=nocontrol mywebsite.com

1046Resizing & Compressing Movies with ffmpeg

Resizing Movies with ffmpeg

Scaling down Full HD from 1920x1080 to 960x540:

ffmpeg -i input.mp4 -s 960x540 -c:a copy output.mp4

-i ... input
-s ... scale
-c ... codec

Compressing with H.2645

ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4

crf ... video quality, lower value means better quality

1044networkQuality

Testing network speed on macOS:

networkQuality

Example output:

Downlink: capacity 24.052 Mbps, responsiveness 321 RPM - Uplink: capacity 0.000
Downlink: capacity 24.052 Mbps, responsiveness 294 RPM - Uplink: capacity 20.669
Downlink: capacity 24.548 Mbps, responsiveness 250 RPM - Uplink: capacity 20.669
Downlink: capacity 24.548 Mbps, responsiveness 248 RPM - Uplink: capacity 17.763
Downlink: capacity 26.099 Mbps, responsiveness 243 RPM - Uplink: capacity 17.763
Downlink: capacity 26.099 Mbps, responsiveness 243 RPM - Uplink: capacity 16.716
Downlink: capacity 26.567 Mbps, responsiveness 240 RPM - Uplink: capacity 16.716
Downlink: capacity 26.567 Mbps, responsiveness 240 RPM - Uplink: capacity 16.632
Downlink: capacity 27.436 Mbps, responsiveness 237 RPM - Uplink: capacity 16.632
Downlink: capacity 27.436 Mbps, responsiveness 235 RPM - Uplink: capacity 15.908
Downlink: capacity 27.120 Mbps, responsiveness 194 RPM - Uplink: capacity 15.908
Downlink: capacity 27.120 Mbps, responsiveness 185 RPM - Uplink: capacity 16.711
Downlink: capacity 25.164 Mbps, responsiveness 156 RPM - Uplink: capacity 16.711
Downlink: capacity 25.164 Mbps, responsiveness 150 RPM - Uplink: capacity 16.939
Downlink: capacity 24.892 Mbps, responsiveness 124 RPM - Uplink: capacity 16.939
Downlink: capacity 24.892 Mbps, responsiveness 118 RPM - Uplink: capacity 17.627
Downlink: capacity 23.011 Mbps, responsiveness 108 RPM - Uplink: capacity 17.627
Downlink: capacity 23.011 Mbps, responsiveness 100 RPM - Uplink: capacity 15.339
Downlink: capacity 22.093 Mbps, responsiveness 87 RPM - Uplink: capacity 15.339
Downlink: capacity 22.093 Mbps, responsiveness 85 RPM - Uplink: capacity 13.592
Downlink: capacity 23.291 Mbps, responsiveness 63 RPM - Uplink: capacity 13.592
Downlink: capacity 23.291 Mbps, responsiveness 63 RPM - Uplink: capacity 14.177
Downlink: capacity 23.291 Mbps, responsiveness 43 RPM - Uplink: capacity 17.627 
==== SUMMARY ====
Uplink capacity: 17.627 Mbps
Downlink capacity: 23.291 Mbps
Responsiveness: Low (43 RPM)
Idle Latency: 19.708 milliseconds

1040Checking a POP3 Connection with OpenSSL

This is mainly used for troubleshooting POP3 connections, to check if the connection/server/password actually works. Also possible to read emails that way, but very ~1995ish. If you really, really want to (re-) experience that experience, check out alpine, the sucessor of pine.

Start connection with OpenSSL:

openssl s_client -connect yourusername.yourmailserver:995

This is non-quiet, resulting in a lot of talkback, most importantly:

    ...
    Start Time: 1693034257
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)
    Extended master secret: no
    Max Early Data: 0
---
read R BLOCK
+OK Dovecot ready.

+OK Dovecot ready. tells use the mail programme - in this case Dovecot - is ready, waiting for user & password input.

user youremailaddress
+OK
pass yourpassword
+OK Logged in.

The stat command tells you how many message, and how large they are.

stat
+OK 2 9394

Ok, two message, totalling 9394 bytes. To read it, use the retrive command, specifiying the number of the message you want to read.

retr 1

This will display the whole message, including any and all headers.

1038Turing on Directory View in Apache

Situation

Your directory on your Apache Server does not have an index.html and creates a 404 when visited. But there are files in the directory, that should be displayed.

Solution

Create a .htaccess file and add the following line:

Options +Indexes

This only works, if AllowOverride Options is set to true in your Apache Settings.

1033How to kill a screen

Mac, Terminal

Open screen with log flag, address & baud rate

screen -L /dev/tty.usbmodem14101 9600

End the session with: ^a - k (press control+a, release, then press k)

Screenshots to follow