Skip to content

Instantly share code, notes, and snippets.

View SOF3's full-sized avatar

Jonathan Chan Kwan Yin SOF3

View GitHub Profile
@Widdershin
Widdershin / ssr.md
Last active May 1, 2024 17:36
The absurd complexity of server-side rendering

In the olden days, HTML was prepared by the server, and JavaScript was little more than a garnish, considered by some to have a soapy taste.

After a fashion, it was decided that sometimes our HTML is best rendered by JavaScript, running in a user's browser. While some would decry this new-found intimacy, the age of interactivity had begun.

But all was not right in the world. Somewhere along the way, we had slipped. Our pages went uncrawled by Bing, time to first meaningful paint grew faster than npm, and it became clear: something must be done.

And so it was decided that the applications first forged for the browser would also run on the server. We would render our HTML using the same logic on the server and the browser, and reap the advantages of both worlds. In a confusing series of events a name for this approach was agreed upon: Server-side rendering. What could go wrong?

In dark rooms, in hushed tones, we speak of colours.

@Muqsit
Muqsit / GeneratorMethodNotYieldingRule.php
Last active April 5, 2024 00:55
PHPStan rule to find unused instantiated generators
<?php
declare(strict_types=1);
namespace pocketmine\phpstan\rules;
use Generator;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Assign;
@SOF3
SOF3 / k8s_quantity.jq
Last active December 27, 2024 05:52
Parse k8s quantities with jq
def parse_quantity:
{n: -3, u: -2, m: -1, k: 1, K: 1, M: 2, G: 3} as $units |
if .[-1:] == "i" then
{base: 1024, str: .[:-1]}
else
{base: 1000, str: .}
end |
.str[-1:] as $unit |
if $units | has($unit) then
pow(.base; $units[$unit]) * (.str[:-1] | tonumber)
use bevy::prelude::*;
fn main() {
// create an alternative Update schedule with a new set of systems
// and store it in a resource to swap later
let mut update = Schedule::new(Update);
update.add_systems(bar);
let mut app = App::new();
app