Skip to content

Instantly share code, notes, and snippets.

@mhart
mhart / functions-index.js
Last active June 26, 2024 02:42
PPR w/ CF Pages and HTMLRewriter
// functions/index.js
export async function onRequestGet({ request, env }) {
// Start getting something from "the DB"
const dbPromise = scheduler.wait(1000).then(() => new Date().toDateString());
// Fetch index.html from cache (body will stream below)
const staticShell = await env.ASSETS.fetch(request);
// The browser will immediately render up until the body closing tag,
// then we insert dom modification scripts as the data is resolved
#!/usr/bin/env bash
# Abort sign off on any error
set -e
# Start the benchmark timer
SECONDS=0
# Repository introspection
OWNER=$(gh repo view --json owner --jq .owner.login)
@boooeee
boooeee / team_ranking_example.R
Last active March 3, 2024 18:00
This code derives a schedule/home field adjusted team ranking for a randomly generated set of games. The randomly generated games can be replaced with actual teams and outcomes from the sport of our choice.
library(tidyverse)
n_games <- 100
# Define the teams
teams <- c("rock", "paper", "scissors")
# simulated home advantage #
home_adv<-2
# Generate the data frame
@rcrowley
rcrowley / example.tf
Created February 15, 2024 17:56
The simplest custom internal tool, protected by the Substrate Intranet, BYO functionality
data "archive_file" "example" {
output_file_mode = "0666" # before umask
output_path = "${path.module}/example.zip"
source_file = "${path.module}/example/index.js"
type = "zip"
}
data "aws_apigatewayv2_apis" "substrate" {
name = "Substrate"
protocol_type = "HTTP"
@surma
surma / .gitignore
Created February 1, 2023 15:48
Wasm GC
*.wasm
# Rails production setup via SQLite3 made durable by https://litestream.io/
# Copy this to Dockerfile on a fresh rails app. Deploy to fly.io or any other container engine.
#
# try locally: docker build . -t rails && docker run -p3000:3000 -it rails
#
# in production you might want to map /data to somewhere on the host,
# but you don't have to!
#
FROM ruby:3.0.2
@tgross
tgross / vmctl
Created July 27, 2021 19:27
Fircracker virtual machine control script
#!/usr/bin/env bash
set -euo pipefail
help() {
cat <<EOF
vmctl [COMMAND] [ARGS]
Launch firecracker VMs from configuration templates with networks
managed by CNI. VM configuration is stored in $VM_CONFIG_DIR
and network configuration is stored in $NET_CONFIG_DIR
@gabrielsson
gabrielsson / minecraft-on-raspberry-pi.md
Last active July 19, 2024 11:37
Minecraft on Raspberry Pi cluster with metrics

alt

Minecraft on Raspberry Pi cluster with metrics

Ever wanted to put your Rapsberry Pi cluster to great use? Our team is working remotely, so we started to play Minecraft. I decided I would host the Minecraft server on my Raspberry Pi cluster. This gist will guide you through the steps I took to get a k3s cluster up with k3sup and later installed Minecraft as well as metrics exporter and Prometheus Operator

Why?

Quoniam Possumus - Because we can

You'll need

3 Ways to design the lightmap API

The purpose of the module is to create and update path-traced 2D lightmaps. For example, to create interesting dynamic top-down lighting in a 2D game.

Option 1: Trace on lightmap

lm := lightmap.New(image.Rect(0, 0, 100, 100))
light := lightmap.Light{
/*
Code to perform L1, L2 cache locality experiments
https://kaushikghose.wordpress.com/2020/01/27/profiling-and-improving-cache-performance/
*/
#include <iostream>
#include <vector>
const size_t N = 1200;
class Matrix {