Edent, to HowTo
@Edent@mastodon.social avatar

🆕 blog! “link rel="alternate" type="text/plain"”

Hot on the heels of yesterday's post, I've now made all of this blog available in text-only mode. Simply append .txt to the URl of any page and you'll get back the contents in plain UTF-8 text. No formatting, no images (although you can see the alt text), no nothing! Front page https://shkspr.mobi/blog/.txt This blog […]

👀 Read more: https://shkspr.mobi/blog/2024/05/link-relalternate-typetext-plain/

blog, to HowTo
@blog@shkspr.mobi avatar

link rel="alternate" type="text/plain"
https://shkspr.mobi/blog/2024/05/link-relalternate-typetext-plain/

Hot on the heels of yesterday's post, I've now made all of this blog available in text-only mode.

Simply append .txt to the URl of any page and you'll get back the contents in plain UTF-8 text. No formatting, no images (although you can see the alt text), no nothing!

This was slightly tricky to get right! While there might be an easier way to do it, here's how I got it to work.

Firstly, when someone requests /whatever.txt, WordPress is going to 404 - because that page doesn't exist. So, my theme's functions.php, detects any URls which end in .txt and redirects it to a different template.

//  Theme Switcheradd_filter( "template_include", "custom_theme_switch" );function custom_theme_switch( $template ) {    //  What was requested?    $requested_url = $_SERVER["REQUEST_URI"];    //  Check if the URL ends with .txt    if ( substr( $requested_url, -4 ) === ".txt")  {            //  Get the path to the custom template        $custom_template = get_template_directory() . "/templates/txt-template.php";        //  Check if the custom template exists        if ( file_exists( $custom_template ) ) {            return $custom_template;        }    }    //  Return the default template    return $template;}

The txt-template.php file is more complex. It takes the requested URl, strips off the .txt, matches it against the WordPress rewrite rules, and then constructs the WP_Query which would have been run if the .txt wasn't there.

//  Run the query for the URl requested$requested_url = $_SERVER['REQUEST_URI'];    // This will be /whatever$blog_details = wp_parse_url( home_url() );  // Get the blog's domain to construct a full URl$query = get_query_for_url(     $blog_details["scheme"] . "://" . $blog_details["host"] . substr( $requested_url, 0, -4 ));function get_query_for_url( $url ) {    //  Get all the rewrite rules    global $wp_rewrite;    //  Get the WordPress site URL path    $site_path = parse_url( get_site_url(), PHP_URL_PATH ) . "/";    //  Parse the requested URL    $url_parts = parse_url( $url );    //  Remove the domain and site path from the URL    //  For example, change `https://example.com/blog/2024/04/test` to just `2024/04/test`    $url_path = isset( $url_parts['path'] ) ? str_replace( $site_path, '', $url_parts['path'] ) : '';    //  Match the URL against WordPress rewrite rules    $rewrite_rules = $wp_rewrite->wp_rewrite_rules();    $matched_rule = false;    foreach ( $rewrite_rules as $pattern => $query ) {        if ( preg_match( "#^$pattern#", $url_path, $matches ) ) {            $matched_rule = $query;            break;        }    }    //  Replace each occurrence of $matches[N] with the corresponding value    foreach ( $matches as $key => $value ) {        $matched_rule = str_replace( "$matches[{$key}]", $value, $matched_rule );    }    //  Turn the query string into a WordPress query    $query_params = array();    parse_str(        parse_url( $matched_rule, PHP_URL_QUERY),         $query_params    );    //  Construct a new WP_Query object using the extracted query parameters    $query = new WP_Query($query_params);    //  Return the result of the query    return $query;}

From there, it's a case of iterating over the posts returned by the query. You can see the full code on my GitLab.

https://shkspr.mobi/blog/2024/05/link-relalternate-typetext-plain/

CppCon, to HowTo
@CppCon@mastodon.social avatar

We have released a new CppCon 2023 Video!

Lightning Talk: Writing a Better std::move – by @foonathan- CppCon 2023
https://youtu.be/hvnl6T2MnUk

GregCocks, to Battlemaps
@GregCocks@techhub.social avatar
Taffer, to HowTo
@Taffer@mastodon.gamedev.place avatar

New post - Auto-deploy: Hugo and Codeberg CI https://taffer.ca/posts/2024/hugo-ci/

A description of how I’ve set up Codeberg’s CI to automatically build and deploy changes to my website.

tuxedocomputers, to legal German
@tuxedocomputers@linuxrocks.online avatar

Collection of instructions

When you buy a TUXEDO, you don't just buy a laptop - we also provide a wide range of help articles and instructions that are constantly being updated and expanded.

Just take a look!
https://www.tuxedocomputers.com/en/Infos/Help-and-Support/Instructions.tuxedo

mboelen, to HowTo
@mboelen@mastodon.social avatar

One of the best HTTP clients is the open source tool curl. With ongoing development and continuously new updates, it is worth getting everything out of this powerful tool!

https://linux-audit.com/cheat-sheets/curl/

And as a bonus: @bagder is friendly developer, and also great to follow here on Mastodon! So give the article a go and follow Daniel 😉

This is the first version of the cheat sheet, with some practical examples. Feedback is very welcome, and boosts as well 🚀

Taffer, to HowTo
@Taffer@mastodon.gamedev.place avatar

New post - Backups https://taffer.ca/posts/2024/backups/

Please back up your files (and a how-to for restic on Linux)!

Edent, to HowTo
@Edent@mastodon.social avatar

🆕 blog! “Server-Side Rendering of Embedded Markdown Code Snippets in WordPress”

Because I'm a grumpy old man, I don't use Gutenberg or Block themes on my WordPress. Instead, I write everything in Markdown. When I write code snippets in Markdown, they look like this: ```php $a = 1; echo $a; if ($a < 5) { // Do Something return thing( $a, true …

👀 Read more: https://shkspr.mobi/blog/2024/04/server-side-rendering-of-embedded-markdown-code-snippets/

#HowTo #php #programming #WordPress

blog, to python
@blog@shkspr.mobi avatar

Server-Side Rendering of Embedded Markdown Code Snippets in WordPress
https://shkspr.mobi/blog/2024/04/server-side-rendering-of-embedded-markdown-code-snippets/

Because I'm a grumpy old man, I don't use Gutenberg or Block themes on my WordPress. Instead, I write everything in Markdown.

When I write code snippets in Markdown, they look like this:

php$a = 1;echo $a;if ($a < 5) { // Do Something return thing( $a, true );}

But I want to render that with code highlighting. I was using the Prismatic Plugin. It is excellent and very customisable. But it uses JavaScript to do the code highlighting. I want to respect my readers' time and battery life; so I'm trying to reduce my dependency on Client-Side rendering.

I've switched to a modified version of WP-GeSHi-Highlight. That turns the above Markdown into:

$a = 1;echo $a;if ($a < 5) {   // Do Something   return thing( $a, true );}

Necessary Changes

When the JetPack Markdown pre-processor encounters a code block, it changes:

```php

into

<code class="language-php">

This means the WP-GeSHi-Highlight detection needs to be changed.

Old version:

return preg_replace_callback(    "/s*".    "(.*)</pre>s*/siU",   "wp_geshi_store_and_substitute",   $s);

New version:

return preg_replace_callback(    "/s*".    "(.*)</code>s*/siU",   "wp_geshi_store_and_substitute",   $s);

One of those matches looks for escaped= which can be true or false. I always want this to be true so, later in the code, I change a variable from:

$escaped = trim($match[3]);

To:

$escaped = true;

Style Changes

By default, everything looks pretty good - but there are a few changes I found necessary to make.

Firstly, there was something weird going on with the line-heights of my style, so I added this to my site's CSS:

/* GeSHI Highlighter Fixes */pre:has(> .wp-geshi-highlight-wrap5) {    line-height: 0;    padding: 0;    background: none;    filter: invert(1);}

The invert gives it a dark mode.

Secondly, in order to make any changes to the default styles of the highlighter, you need to add the bundled wp-geshi-highlight.css file into your style directory. The plugin will use that if it exists - so you can change font size and padding to be the same as your main theme.

Limitations

There are a few limitations with this approach.

No line-numbers. The plugin looks for something like line="13", but there's no way to add that in Markdown.

GeSHi hasn't received style updates on some languages for quite some time. It hasn't received any significant update since 2019. Which means bugs and security issues are likely.

Language definitions are quite strict. You can use javascript but not json.

The plugin doesn't have any options - nor an easy way to override its settings. So I've monkeypatched everything above. If the plugin updates, I'll need to change my code.

Demos

A few demos - just so you can see what it looks like.

Python

#!/usr/bin/env pythonfrom datetime import datetime, timedeltafrom mastodon import Mastodonfrom bs4 import BeautifulSoupimport config#  Set up accessmastodon = Mastodon( api_base_url=config.instance, access_token=config.access_token )#  Get user's infome = mastodon.me()my_id = me["id"]year_joined = me["created_at"].year

Bash

if [ "$(basename $2)" = "Image.gz" ] || [ "$(basename $2)" = "vmlinuz.efi" ]then# Compressed install  echo "Installing compressed kernel"  base=vmlinuzelse# Normal install  echo "Installing normal kernel"  base=vmlinuxfiif [ -f $4/$base-$1 ]; then  mv $4/$base-$1 $4/$base-$1.oldfi

Rust

// This is the main function.fn main() {    // Print text to the console.    println!("Hello World!");}

JavaScript

if (hour < 18) {  greeting = "Good day";  alert( greeting );} 

https://shkspr.mobi/blog/2024/04/server-side-rendering-of-embedded-markdown-code-snippets/

Taffer, to HowTo
@Taffer@mastodon.gamedev.place avatar

New post - Touchpad vs Mouse - KDE on Wayland https://taffer.ca/posts/2024/touchpad-vs-mouse/

I figured out a way to automatically enable or disable my laptop touchpad when my mouse is disconnected or connected!

sergio_101, to usenet
@sergio_101@mastodon.social avatar

Rereading @pluralistic 's "Little Brother" last week brought back great memories of staying up way too late at night reading s and s .. and then doing some sketchy shit with

aral, to SmallWeb
@aral@mastodon.ar.al avatar
otyugh, to HowTo French
@otyugh@pouet.chapril.org avatar
blog, to HowTo
@blog@shkspr.mobi avatar

A personal WordPress MonoRepo for my themes and plugins
https://shkspr.mobi/blog/2024/03/a-personal-wordpress-monorepo-for-my-themes-and-plugins/

I use a self-built WordPress theme for this blog. I also use a variety of self-developed WordPress plugins for various enhancements. I used to publish these plugins, but I get terribly confused by the SVN shenanigans involved, and they weren't used by many people, so I stopped.

Recently, I've been moving all my plugin code into my theme. This is sort-of-but-not-quite a MonoRepo.

I've also tried to move away, as far as possible, from using other people's plugins. Most of the ones I had were single-shot plugins which did one thing and needed the minimum amount of configuration. So I learned from their code and re-implemented it into my theme.

This isn't quite digital-homesteading. I'm not rolling my own crypto, or building my own CMS. I'm just taking back a little control, learning how things work, and enjoying the busy-work of Digital Gardening.

I don't know if this is a good idea. It means I don't get security updates if my knock-off code is vulnerable. I don't get new features. But I also don't have to trust that a 3rd-party developer isn't going to screw up (I can screw up on my own, thank-you-very-much!). I've had a few bad experiences with plugins which suddenly stopped working, or had abusive behaviour.

HowTo

I put new functionality into a file with a descriptive name, for example related-posts.php and I save it in my-theme/includes/.

In my WordPress's theme, I add this to functions.php:

//  Load all the files$includes_path = get_template_directory() . "/includes/";foreach ( new DirectoryIterator( $includes_path ) as $fileInfo ) {    if( $fileInfo->isDot() ) continue;  //  Ignore . and ..    if( $fileInfo->getExtension() != "php" ) continue; // Only load PHP    require_once( get_template_directory() . "/includes/" . $fileInfo->getFilename() );}

That loads all the .php files from /includes/.

I have no idea how performant this is. I have some fairly aggressive caching plugins which should minimise any slowness - and they're not part of my MonoRepo.

https://shkspr.mobi/blog/2024/03/a-personal-wordpress-monorepo-for-my-themes-and-plugins/

Taffer, to HowTo
@Taffer@mastodon.gamedev.place avatar

New post - Framework 16 https://taffer.ca/posts/2024/framework16/

In July last year, I eagerly pre-ordered a Framework 16 laptop.

thevglibrary, to gamedev
@thevglibrary@mstdn.social avatar

Every game starts with an idea. But how does it get from conception to release❓

In this book, author Alexey Savchenko has put together a practical guide, based on his 20+ years in , to help you avoid the common pitfalls and deliver on your idea!

👉
https://www.thevideogamelibrary.org/book/games-as-business-from-dreams-to-release

@bookstodon

tallship, to linux
@tallship@fedia.social avatar

I think, for me, much like EDLIN, it's pretty much always been a matter of knowing that it was the default editor available in every incarnation of and since, ... I dunno, ... 4.2BSD or so?

Perhaps I should say vi, and in DOS I don't really recall when EDIT.COM supplanted , but do feel free to checkout my friend's more modern in the link above. h/t to @dheadshot for creating a POSIX interpretation of that classic utility from the days when disk drives talked to you and diskettes shimmied...

Also, These memes are some of the funnest elbows to the ribs of the person sitting next to you we can all enjoy together... unless, unless, Oh my gawd am I on Drugs?

Here's another one for folks to add to their collections, for foshizzles and giggles, of course, and we all can haz ! 🍔

Kindest regards, and thank you for some of the very best cookbook style , 's, and introspectives for the UNIX / Linux / FOSS world on the Internet :)

?

.

RE: mastodon.social/users/nixCraft/statuses/112112461370380508

dnc, to baking
@dnc@vive.im avatar
christian, to HowTo
@christian@suma-ev.social avatar

I was asked to “patch up” a group's Mastodon server that was still running an unpatched version 4.0.x.

When I was done, they asked me how I did it so quickly. Here is a :

– back up DB
– check out v4.1.15
– follow these upgrade notes: https://github.com/mastodon/mastodon/releases/tag/v4.1.0 (!)
– test

– back up DB
– check out v4.2.8 (latest)
– follow these upgrade notes: https://github.com/mastodon/mastodon/releases/tag/v4.2.0 (!)
– test

→ Follow upgrade notes for each version x.y.0, or you will miss migrations!

danslerush, to HowTo
@danslerush@floss.social avatar

convert DTS to AAC (and save space) thru with

› Open you file with
› Select only the audio track you want and run multiplexing
› You have normally your MKA file now
› ffmpeg -i input.mka -acodec aac -vn output.m4a

I've gone from 4GB to 400MB 🤓 (could be useful)

You can now "remerge" this new audio track with the previous MKV

Natanox, to diy
@Natanox@chaos.social avatar

What is a good alternative to instructables.com? Autodesk is a garbage corpo.

CardboardDM, to DnD
@CardboardDM@dice.camp avatar
dnc, to cooking
@dnc@vive.im avatar
Taffer, to HowTo
@Taffer@mastodon.gamedev.place avatar

New post - Hashtags Hugo https://taffer.ca/posts/2024/hashtags-hugo/

If this works, I figured out how to add a post’s tags to the RSS feed’s <description> block.

Taffer,
@Taffer@mastodon.gamedev.place avatar

Yay, it worked!

  • All
  • Subscribed
  • Moderated
  • Favorites
  • anitta
  • Durango
  • magazineikmin
  • InstantRegret
  • hgfsjryuu7
  • vwfavf
  • Youngstown
  • slotface
  • thenastyranch
  • ngwrru68w68
  • rosin
  • kavyap
  • PowerRangers
  • DreamBathrooms
  • cisconetworking
  • khanakhh
  • mdbf
  • tacticalgear
  • ethstaker
  • modclub
  • osvaldo12
  • everett
  • tester
  • cubers
  • GTA5RPClips
  • normalnudes
  • Leos
  • provamag3
  • All magazines