Skip to content

Instantly share code, notes, and snippets.

- name: Overprovision like the pros'
hosts: all
tasks:
- name: Install early OOM killer and zram
ansible.builtin.apt:
pkg:
- earlyoom
- zram-tools
- name: Configure early OOM killer
ansible.builtin.lineinfile:

A Somewhat More Involved Date Comparison

An example page for https://www.evidence.studio/

Introduction

Many Components now have a "compare to" option, and thats going to serve most purposes, but what if you want to plot a metric over time against a comparison period?

This is definitely more involved, but it solves that case, and allows for a little less repetition in component settings. This is probably not the only way to do it, just an example for anyone that might find it useful

This example only uses the demo_daily_orders source, so can be tried out by anyone

@NatElkins
NatElkins / cloud-init.yaml
Created March 8, 2025 22:09
cloud-init script for VPS
#cloud-config
# Enable automatic package updates and upgrades during cloud-init execution
package_update: true
package_upgrade: true
packages:
# Security and Hardening
- ufw
- fail2ban
@robertvanhoesel
robertvanhoesel / form.ts
Last active November 1, 2025 23:02
Astro createForm implementation
import { getZodConstraint, parseWithZod } from "@conform-to/zod"
import type { HTMLAttributes } from "astro/types"
import { ZodAny, z, type ZodIssue } from "zod"
export type Constraint = ReturnType<typeof getZodConstraint>[0]
export type FieldAttributes = {
name: string
value: string
type: NonNullable<HTMLAttributes<"input">["type"]>
} & Partial<Record<Lowercase<keyof Constraint>, any>>
@faizanakram99
faizanakram99 / QueryHydrator.php
Created January 20, 2024 00:15
DBAL results to object hydrator
<?php
declare(strict_types=1);
namespace HakunaMatata;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Types\Type;
<?php
declare(strict_types=1);
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class SessionListener
{
public function __construct(
@sannajammeh
sannajammeh / Image.astro
Last active June 11, 2025 10:38
Astro Responsive Image
---
import type { ImageMetadata, ImageTransform } from "astro";
import { getImage } from "astro:assets";
import LoadableImage from "./LoadableImage.astro";
type Props = {
src: ImageMetadata;
alt: string;
/**
* Array of screens to generate the image for i.e [320, 480, 1200]
@gimenete
gimenete / safeParse.ts
Last active March 15, 2024 16:05
A wrapper around the fetch function that validates the response body against a Zod schema
import z from "zod";
export async function safeFetch<T>(
schema: z.Schema<T>,
input: RequestInfo,
init?: RequestInit
): Promise<T> {
const response = await fetch(input, init);
if (!response.ok) {
Array.from(document.styleSheets).filter((sheet) => { try { sheet.cssRules; return true; } catch (err) { console.log(`Due to CORS issues, this script can't access "${sheet.href}"`); return false; }}).map((sheet) => Array.from(sheet.cssRules).map((rule) => rule.type === rule.FONT_FACE_RULE ? rule.cssText : rule.type === rule.STYLE_RULE ? Array.from(document.querySelectorAll(rule.selectorText)).some((node) => node.getBoundingClientRect().top < window.innerHeight && window.getComputedStyle(node).display !== 'none') ? rule.cssText : null : rule.type === rule.MEDIA_RULE ? `@media ${rule.conditionText} {${Array.from(rule.cssRules).map((mediaRule) => mediaRule.type === mediaRule.FONT_FACE_RULE ? mediaRule.cssText : mediaRule.type === mediaRule.STYLE_RULE ? Array.from(document.querySelectorAll(mediaRule.selectorText)).some((node) => node.getBoundingClientRect().top < window.innerHeight && window.getComputedStyle(node).display !== 'none') ? mediaRule.cssText : null : null).filter((mediaRule) => mediaRule != null).join(
@jreviews
jreviews / htmx-loading-states-extension.md
Last active April 1, 2024 22:22
htmx loading states extension

htmx loading states extension

The loading-states extension allows you to easily manage loading states while a request is in flight, including disabling elements, and adding and removing CSS classes.

Using the extension

Add the hx-ext="loading-states" attribute to the body tag or to any parent element containing your htmx attributes.

Add the following class to your stylesheet to make sure elements are hidden by default: