diceline-chartmagnifiermouse-upquestion-marktwitter-whiteTwitter_Logo_Blue

Today I Learned

Upgrade your SSH Keys to the new Ed25519 standard

Why should you upgrade?

Your ssh key is most probably half a decade or more old, as with all technlologies, cryptographic algorithms evolve and all of them become less secure with time as vulnerabilites are discovered, or computing power increases. Good SysOps and DevOps often rotate their keys and you should too!

See all the benefits of Ed25519 here: https://ed25519.cr.yp.to

You need to upgrade right now if:

  • your key was generated using DSA you need to upgrade right now
  • your key was generated using RSA less than 3072bit length
  • your key was generated using ECDSA

Ed25519 is the public-key algorithm you should use today.

How to generate your key:

I like to have custom names for my keys, and I also add relevant information to key comments like: role, name and e-mail. The -o 100 option, increases the brute force resistance of your key by increasing the KDF rounds.

ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/zeno.popovici.ed25519 -C "Graffino Member :: Zeno Popovici (zeno@graffino.com)"

Don't forget to provide a strong password for your key.

Deploy (macOS)

You can now deploy your key. First, you need to add it to your keychain like this:

ssh-add -K ~/.ssh/zeno.popovici.ed25519

On macOS, to copy your public key to the clipboard and paste it into GitHub or other services you're using, just issue:

pbcopy < ~/.ssh/zeno.popovici.ed25519.pub

That's it!

How to fix a render-blocking video on Safari

This is related to the MOOV atom that contains all the metadata and information about the frame locations other important information the browser needs to know about the video. For some reason, all other major browsers load it with no issues but Safari prefers to wait until the whole resource has downloaded in order to decide what to do with it.

For mp4 files, downloading FFMPEG and running the following command solved my issue:

./ffmpeg -y -i source.mp4 -movflags faststart dest.mp4

What it does is that it takes the MOOV atom from the end and adds it right at the start.

Extend Ecto's query API with your own macros

Imagine for a second this is something you're using a lot when programming Elixir and Phoenix:

Repo.one(
	from u in User,
		where: fragment("lower(?)", u.email) == ^email
)

You can write your own Elixir macro to improve your flow.

defmacro lower(arg) do
	quote do: fragment("lower(?)", unquote(arg))
end

Then your query can be rewritten like this:

Repo.one(
	from u in User,
		where: lower(u.email) == ^email
)

How to change JPEG compression rate in WordPress

Our client wants pixel perfect images in his WordPress site. Truth is WordPress is a bit agressive in compressing JPEGs.

WordPress default is 75% compression quality. A higher setting will generate better looking images, to the expense of larger filesize.

Add this to your functions.php file:

// Change JPEG compression rate - 85 is much more reasonable setting
// You can also disable it by settign it to 100
$jpeg_compression = function() { 
	return 85; 
};

add_filter( 'jpeg_quality', $jpeg_compression );

The importance of clear namespaced HTML attributes

Here's another reminder why expressive, namespaced ids are important. This time is about a label's for attribute.

<input id="phone">
<label for="phone"></label

This would work just as expected unless, for example, we have a svg sprite at the beginning of the document that includes an svg with a "phone" id.

<symbol id="phone" viewBox="0 0 61.4 48">...</symbol>
...
<input id="phone">
<label for="phone"></label

In this case, the label's for will match the first in a top-down order that has the target id.

And you will never know why clicking the label won't trigger the input.