Categories
Servers

Certbot Renewal failing well-known challenge

In my case when I added the domain for LetsEncrypt I forgot /public from the Laravel path. Registration worked for some reason (?), but renewal a few months later failed.

I updated /etc/letsencrypt/renewal/*.conf and changed the path to /public and it worked.

Categories
Uncategorized

S3 CLI Jobs

Move batch of files with a pattern. (Delete –dry-run to do it for real)

aws s3 mv s3://mybucket/path/ s3://mybucket/newpath/ --recursive --exclude "*" --include "my_pattern*.gz" --dryrun 

Find some objects with the deprecated Reduced Redundancy Storage type to migrate

aws s3api list-objects-v2 --bucket mybucket --max-item 200 --start-after "somepath" --query 'Contents[?StorageClass==`REDUCED_REDUNDANCY`][Key]'
Categories
Servers

SCP with PEM key

If you’re using a non-default key to SSH into a server SCP will need an extra argument to connect and upload the file.

scp -i TheOtherKey.pem localfile.zip user@example.com:/var/www/uploadedfile.zip 

Categories
JavaScript Static Site Generators

Static Site Generator Opinions

Eleventy looks good for actual simplicity and genuine static sites.

Nuxt

Nuxt Update 2.13

19 June 2020: Now supports target: static to actually build a static site.


TL;DR: up to and including 2.12 do not support writing fully-static HTML without client side JS. It gets part the way there whereby you don’t need a Node server, however there’s still 150kb+ of client JS.

A coming version should support a ‘static’ directive to avoid that.


Just dabbled with this for potential client project. Seems powerful for apps and SPA, and it apparently does SSG and SSR; HOWEVER their definition of a static generated site means static files, but the page rendering is still done with JS!

I found issues on their Github, and log running RFCs to discuss making real static HTML files that have the content actually rendered there are built time, but still nothing implemented as of April 2020.

It’s pretty frustrating TBH, because if the result is static content on the page I’m not sure why the JS community cannot fathom writing it into the HTML file and not into a JS render function.

You’d lose the power of the SPA.

Whoever

Yeah, that’s fine. The browser is really good at navigating pages. If they are static HTML they will be super fast, the routing is automatic, the whole thing is super portable and SEO friendly.

Gridsome & Eleventy

These are probably the best of the non-React JS ones to try next.

Gridsome uses GraphQL and if you know that might offer power for fetching data.

Eleventy looks like it probably can with Data sources that use functions/async funcs to fetch data for build. If you were iterating on a site could you separate fetching API data from each build so you have more control about when that runs?

Categories
Laravel

Safe Mass Assignment in Laravel

Rather than explicitly assigning each allowed property to a Model (to avoid passing user input directly through) you can use the validated data to safely mass assign.

Re this tweet:

The $request->validate() method will return the keys of valid data (and redirect on failure).

<?php
$data = $request->validate([
...$rules])

$model->fill($data);

However if you accept input in the request that needs to be validated, but should not end up on the model this approach won’t work.

Categories
WordPress

Create WordPress user programatically

if (! defined('ADDED_THE_USER')) {
    add_action('init', 'mh_add_user');
}

function mh_add_user() {
    $username = 'myusername';
    $password = 'cool_password';
    $email = 'theuser@example.com';

    // Create the new user
    $user_id = wp_create_user( $username, $password, $email );

    // Get current user object
    $user = get_user_by( 'id', $user_id );

    // Remove role
    $user->remove_role( 'subscriber' );

    // Add role
    $user->add_role( 'administrator' );
    
    
    define('ADDED_THE_USER', true);
}
Categories
Uncategorized

FFMPEG

Sequential still frames to video

ffmpeg -r 60 -f image2 -s 1920x1080 -i pic%04d.png -vcodec libx264 -crf 25  -pix_fmt yuv420p test.mp4

Where the %04d means that zeros will be padded until the length of the string is 4 i.e 0001…0020…0030…2000 and so on. If no padding is needed use something similar to pic%d.png or %d.png.

Resize video

scale is horizontal width. :-1 maintains ratio.

ffmpeg -i 2022-08_Mike-Dave.mp4 -filter:v scale=1920:-1 -c:a copy 2022-08_Mike-Dave_1080.mp4
Categories
Static Site Generators

VuePress

I gave VuePress the 101 Hello World run through.

Dev experience was fine, and running vuepress dev was nice enough, however seems like it doesn’t actually generate static sites. The build command creates an index.html, but it still references webpack powered JS files to actually setup the styles and templates. You can’t just dump that output on a static host like S3 or Github pages.

Others reported the same issue on Github and the answer seemed to be to install some lightweight node http server, but that’s not a solution. I can’t run a server on S3 or Cloudfront?

Surely the point is that you end up with simple fucking HTML files, and not needing to run node on a server?!

And even if I wanted to piggy back on an existing server, that node process couldn’t listen to port 443 if it’s already in use by Nginx or whatever. So what, I need to provision a whole new real server?

And (2) even if I did that the code sent to the browser still includes a lot of JS it has to parse, so much of the perf benefit is lost.

No thank you VuePress, I do not think we’ll be doing business together!

Categories
Workflow

Nginx on Homebrew

Feb 2020 – replacing Apache with Nginx to fix broken dev env.

Nginx with PHP-FPM was giving 404 because the script name wasn’t being forwarded to PHP-FPM.

Needed this inside the fast_cgi file. It wasn’t there by default, but some random Googling turned it up 🙁

fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;

Various Paths and Notes

  • Need system Apache to be off. (sudo apachectl stop)
  • May need to (re)start nginx and php-fpm
  • Create new local domains in /usr/local/etc/nginx/servers
  • nginx -t to test config
  • sudo nginx -s reload

Nginx may start as non-sudo/root user and lack permission to bind to :80

In that case I brew services stop nginx, then sudo brew services start nginx.

Paths

  • /usr/local/etc/nginx/ (nginx config)
  • /usr/local/var/www (old default location, I have since changed to my user /Code dir)
  • /usr/local/etc/php/7.4/
  • /usr/local/etc/php/7.4/php-fpm.d/www.conf
Categories
Workflow

Broken MySQL after Homebrew installing Qcachegrind

MySQL died after rebooting after installing Qcachegrind.

I think the problem was brew update doing a ‘prune’ which removed /usr/local/etc/my.cnf.d

I recreated it manually and was able to start MySQL

cd /usr/local/bin
sudo mysql.server start