[Article] Thanks, RSS Readers [RSS Exclusive!]

 

This post is secret; you can only find it via my RSS feeds (and places which syndicate them). It's okay to talk about it or link to it, though. Thanks for being part of RSS Club!

Fellow Automattician and RSS Club member Matthias Pfefferle wrote a post yesterday (in German, but automatic translation clearly gets the gist of it), observing that Kev Quirk‘s RSS feed contains

<p class="feed-email-link">
  Thanks for reading this post via RSS. RSS is great, and you're great for using it. ❤️
</p>

Kev’s RSS feed contains this message appended to the content of each post

Matthias went on to mention a snippet of WordPress code shared by Jeremy Herves, which he uses to achieve a similar thing but with a randomly-selected one of eight different messages of thanks:

/**
 * Display a nice welcoming message to folks reading posts via RSS.
 *
 * Kudos Kev Quirk for the idea!
 *
 * @param string $content The current post content.
 *
 * @return string
 */
function jeherve_welcome_rss_readers( $content ) {
	$welcome_messages = array(
		'Thanks for reading this post via RSS. RSS is great, and you’re great for using it. ♥️',
		'Congratulations on being an RSS reader! You are part of an elite group of people who know how to stay updated in style.',
		'Hey there, RSS reader! You’re one of a special few, choosing this old-school yet awesome way of staying informed. Kudos!',
		'You are a true RSS aficionado! While others are drowning in social media noise, you enjoy the simplicity and control of RSS. Congrats!',
		'RSS readers like you are the unsung heroes of the internet. Keep up the good work!',
		'You are a master of efficiency! By using RSS, you save time and avoid distractions. 👏',
		'RSS readers like you are the secret sauce of the internet. Keep rocking and staying informed!',
		'Hey there, RSS reader! You’re cool. Keep being awesome! 😎',
	);

	$welcome_message = $welcome_messages[ wp_rand( 0, count( $welcome_messages ) - 1 ) ];

	return sprintf(
		'%1$s<p>%2$s</p>',
		$content,
		$welcome_message
	);
}
add_filter( 'the_content_feed', 'jeherve_welcome_rss_readers' );

Jeremy’s solution.

Like Jeremy, I was inspired by Kev Quirk and have been appending a message onto my posts in RSS feeds for a while. My approach is a little different, though:

  1. Rather than a random number, I use the post ID modulus the number of random messages to choose which “random” message to select. This means that a given post has a consistent message, which minimises the risk that a post will be detected as having been “changed” by a feed reader, and it also helps to reduce “runs” of the same message after multiple posts in a row. I have a prime number of random messages to reduce the risk that patterns in my posting (e.g. a series of posts, without drafts, each with exactly one image, like my recent and ongoing Bleptember series) end up introducing a predictable pattern to the messages.
  2. I only use the random message if a specific one is not provided via postmeta. I’ve got a metadata field in my editing interface which, if filled, overrides the random message. This lets me put a specific or targetted message in, usually/especially if I’m talking specifically about RSS-related things!
WordPress postmeta field for "RSS Thanks".
When I author a post, sometimes I’ll override the message that appears for that post.

Here’s the code I use to inject the messages into my RSS feed:

function q23_rss_thanks_default( $post ) {
  $rss_thanks_messages = [
    "💖 RSS is fantastic, and so are you for using it. 🎆",
    "👏 Congratulations on being an RSS user. 🎉",
    "🥰 You're reading this post via the RSS feed. That makes you one of the best people on the Internet! 🏆",
    "📰 Using a feed reader is the best way to read my blog posts. How clever you are to know that! 🚀",
    "🌟 You're reading this post via the RSS feed, you star! 🌠",
    "🪄 Feeds are wonderful, and you're a wonderful person for using them. 🔮",
    "❤️‍🔥 You're reading this post via the RSS feed. You're on fire! 🔥",
    "🧨 RSS is dynamite! Thanks for subscribing to my blog. 💥",
    "🤘 You're subscribed to DanQ.me using the RSS feed. You rock! 🎸",
    "🕵️ Subscribing to DanQ.me's RSS feeds means that you'll get to see secret bonus posts not publicised on the main site. Clever you! 🧠",
    "🧡 I love RSS feeds. And I love you for using them. 💙",
    "🎗️ Using RSS feeds is a great way to keep up-to-date with my blog. Thanks for subscribing! 🤗",
    "🦸 You're my hero! (For using RSS to follow my blog.) 🥇",
  ];
  $post_id = intval( $post ? $post->ID : 0 );
  return $rss_thanks_messages[ $post_id % count( $rss_thanks_messages ) ];
}

function q23_rss_thanks( $content ) {
  global $post;
  $rss_thanks_message = get_post_meta( $post->ID , 'rss_thanks_message', true );
  $rss_thanks_message = empty( $rss_thanks_message ) ? q23_rss_thanks_default( $post ) : $rss_thanks_message;
  return $content . "<p style=\"margin-top: 0.5ch; padding-top: 0.5ch; border-top: 1px solid #ccc;\">$rss_thanks_message</p>";
}

add_action( 'the_content_feed', 'q23_rss_thanks' );

Note my use of intval( $post ? $post->ID : 0 ) to get the post ID, % count( $rss_thanks_messages ) to get it-modulus-the number of messages, and my get_post_meta and empty( ... ) check to allow post metadata to override it. Oh, and that code is CC0/public domain, if you want it.

Regardless of whether or not you love RSS as much as I do, thanks for reading my blog via RSS!

🙌 This post was just for people who follow my RSS feed (or other services that syndicate my RSS feed). Thanks for reading! 🥳

Articles – Dan Q

13 Sep 2024 at 14:45

[Article] D20 with Advantage

 Dungeons & Dragons players spend a lot of time rolling 20-sided polyhedral dice, known as D20s.

In general, they’re looking to roll as high as possible to successfully stab a wyvern, jump a chasm, pick a lock, charm a Duke1, or whatever.

A 'full set' of white polyhedral dice commonly-used by roleplayers - a D4, D6, D8, two D10s, a D12, and a D20 - sit half-submerged in a red liquid.
Submerging your dice set in the blood of a halfling is a sure-fire way to get luckier rolls.

Roll with advantage

Sometimes, a player gets to roll with advantage. In this case, the player rolls two dice, and takes the higher roll. This really boosts their chances of not-getting a low roll. Do you know by how much?

I dreamed about this very question last night. And then, still in my dream, I came up with the answer2. I woke up thinking about it3 and checked my working.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
2 2 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
3 3 3 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
4 4 4 4 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
5 5 5 5 5 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
6 6 6 6 6 6 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
7 7 7 7 7 7 7 7 8 9 10 11 12 13 14 15 16 17 18 19 20
8 8 8 8 8 8 8 8 8 9 10 11 12 13 14 15 16 17 18 19 20
9 9 9 9 9 9 9 9 9 9 10 11 12 13 14 15 16 17 18 19 20
10 10 10 10 10 10 10 10 10 10 10 11 12 13 14 15 16 17 18 19 20
11 11 11 11 11 11 11 11 11 11 11 11 12 13 14 15 16 17 18 19 20
12 12 12 12 12 12 12 12 12 12 12 12 12 13 14 15 16 17 18 19 20
13 13 13 13 13 13 13 13 13 13 13 13 13 13 14 15 16 17 18 19 20
14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 15 16 17 18 19 20
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 16 17 18 19 20
16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 17 18 19 20
17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 18 19 20
18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 19 20
19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
Table illustrating the different permutations of two D20 rolls and the “advantage” result (i.e. the higher of the two).

The chance of getting a “natural 1” result on a D20 is 1 in 20… but when you roll with advantage, that goes down to 1 in 400: a huge improvement! The chance of rolling a 10 or 11 (2 in 20 chance of one or the other) remains the same. And the chance of a “crit” –  20 – goes up from 1 in 20 when rolling a single D20 to 39 in 400 – almost 10% – when rolling with advantage.

You can see that in the table above: the headers along the top and left are the natural rolls, the intersections are the resulting values – the higher of the two.

The nice thing about the table above (which again: was how I visualised the question in my dream!) is it really helps to visualise why these numbers are what they are. The general formula for calculating the chance of a given number when rolling D20 with advantage is ( n2 – (n-1)2 ) / 400. That is, the square of the number you’re looking for, minus the square of the number one less than that, over 400 (the total number of permutations)4.

Why roll two dice when one massive one will do?

Knowing the probability matrix, it’s theoretically possible to construct a “D20 with Advantage” die5. Such a tool would have 400 sides (one 1, three 2s, five 3s… and thirty-nine 20s). Rolling-with-advantage would be a single roll.

'400-sided die' shown on Numberwang.
I don’t think anybody’s ever built a real 400-sided die, but Numberwang! claimed to have one.

This is probably a totally academic exercise. The only conceivable reason I can think of would be if you were implementing a computer system on which generating random numbers was computationally-expensive, but memory was cheap: under this circumstance, you could pre-generate a 400-item array of possible results and randomly select from it.

But if anybody’s got a 3D printer capable of making a large tetrahectogon (yes, that’s what you call a 400-sided polygon – you learned something today!), I’d love to see an “Advantage D20” in the flesh. Or if you’d just like to implement a 3D model for Dice Box that’d be fine too!

Footnotes

1 Or throw a fireball, recall an anecdote, navigate a rainforest, survive a poisoning, sneak past a troll, swim through a magical swamp, hold on to a speeding aurochs, disarm a tripwire, fire a crossbow, mix a potion, appeal to one among a pantheon of gods, beat the inn’s landlord at an arm-wrestling match, seduce a duergar guard, persuade a talking squirrel to spy on some bandits, hold open a heavy door, determine the nature of a curse, follow a trail of blood, find a long-lost tome, win a drinking competition, pickpocket a sleeping ogre, bury a magic sword so deep that nobody will ever find it, pilot a spacefaring rowboat, interpret a forgotten language, notice an imminent ambush, telepathically commune with a distant friend, accurately copy-out an ancient manuscript, perform a religious ritual, find the secret button under the wizard’s desk, survive the blistering cold, entertain a gang of street urchins, push through a force field, resist mind control, and then compose a ballad celebrating your adventure.

2 I don’t know what it says about me as a human being that sometimes I dream in mathematics, but it perhaps shouldn’t be surprising given I’m nerdy enough to have previously recorded instances of dreaming in (a) Perl, and (b) Nethack (terminal mode).

3 When I woke up I also found that I had One Jump from Disney’s Aladdin stuck in my head, but I’m not sure that’s relevant to the discussion of probability; however, it might still be a reasonable indicator of my mental state in general.

4 An alternative formula which is easier to read but harder to explain would be ( 2(n – 1) + 1 ) / 400.

5 Or a “D20 with Disadvantage”: the table’s basically the inverse of the advantage one – i.e. 1 in 400 chance of a 20 through to 39 in 400 chance of a 1.

📰 Using a feed reader is the best way to read my blog posts. How clever you are to know that! 🚀

Articles – Dan Q

12 Sep 2024 at 06:55



Refresh complete

ReloadX
Home
(261) All feeds

Last 24 hours
Download OPML
A Very Good Blog by Keenan
*
A Working Library
Alastair Johnston
Andy Sylvester's Web
Anna Havron
annie mueller
*
Annie Mueller
*
Apple Annie's Weblog
*
Articles – Dan Q
*
Austin Kleon
*
Baty.net posts
bgfay
Bix Dot Blog
*
Brandon's Journal
*
Chris Coyier
Chris Lovie-Tyler
Chris McLeod's blog
CJ Chilvers
CJ Eller
*
Colin Devroe
*
Colin Walker – Daily Feed
Content on Kwon.nyc
*
Dave's famous linkblog
*
daverupert.com
Dino's Journal 📖
dispatches
*
dominikhofer dot me
E L S U A ~ A blog by Luis Suarez
Excursions
Flashing Palely in the Margins
Floating Flinders
For You
*
Frank Meeuwsen
frittiert.es
Hello! on Alan Ralph
Human Stuff from Lisa Olivera
inessential.com
*
Interconnected
Into the Book
*
jabel
Jake LaCaze
*
James Van Dyne
*
Jan-Lukas Else
Jim Nielsen's Blog
*
Jo's Blog
*
Kev Quirk
lili's musings
*
Live & Learn
Lucy Bellwood
Maggie Appleton
*
Manton Reece
*
Manu's Feed
maya.land
*
Meadow 🌱
Minutes to Midnight RSS feed
Nicky's Blog
*
Notes – Dan Q
*
On my Om
Own Your Web
Paul's Dev Notes
*
QC RSS
rebeccatoh.co
reverie v. reality
*
Rhoneisms
ribbonfarm
*
Robert Birming
Robin Rendle
Robin Rendle
Sara Joy
*
Scripting News
*
Scripting News for email
*
Scripting News podcasts
Sentiers – Blog
Simon Collison | Articles & Stream
strandlines
Tangible Life
the dream machine
*
The Marginalian
*
thejaymo
theunderground.blog
Thoughtless Ramblings
tomcritchlow.com
*
Tracy Durnell
*
uncountable thoughts
*
Winnie Lim
*
yours, tiramisu
Žan Černe's Blog

About Reader


Reader is a public/private RSS & Atom feed reader.


The page is publicly available but all admin and post actions are gated behind login checks. Anyone is welcome to come and have a look at what feeds are listed — the posts visible will be everything within the last week and be unaffected by my read/unread status.


Reader currently updates every six hours.


Close

Search




x
Colin Walker Colin Walker colin@colinwalker.blog