Skip to content

Instantly share code, notes, and snippets.

View MarkSFrancis's full-sized avatar

Mark Francis MarkSFrancis

View GitHub Profile
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
BenchmarkRunner.Run<Benchmarks>();
[MemoryDiagnoser]
public class Benchmarks
@MarkSFrancis
MarkSFrancis / README.md
Last active June 28, 2025 09:30
Valibot utils for validation

Valibot Utils

Included

  • vTrimString -> validate it's a non-empty string after trimming for whitespace
  • vTrimStringOptional -> same as above, but allowing undefined. Converts empty strings (after trimming) to undefined
  • vAfter -> validate it's a base64 encoded JSON object + matches the given schema. Useful for encoded pagination variables, such as ?after={id: 10}
  • vCoerceObject -> coerce values from string to whatever the provided schema needs. Useful for parsing query strings, path params, etc.

Prerequisites

@MarkSFrancis
MarkSFrancis / README.md
Created March 8, 2024 15:31
Builder pattern with async execution, demoing how to create a tiny shell script utility

Async builder

DO NOT COPY THIS CODE INTO PRODUCTION!

For this specific example, you should use packages like zx or bun shell which are battle-tested shell script runners for javascript environments

This is meant to showcase what a builder pattern for await operators can do.

Example usage

@MarkSFrancis
MarkSFrancis / README.md
Created January 4, 2024 14:31
AWS API Gateway CDK Construct

API Construct for API Gateway V2

This gist represents an API construct on top of API Gateway V2. It's designed to make it easy to add lots of protected endpoints to a serverless API.

It introduces the following opinions:

  • Sandbox environments exist in the same AWS account as "dev"
  • There are only dev and production accounts - no test account
  • Dev and prod have static DNS records, but sandbox DNS records are dynamically generated by AWS
  • All API endpoints are authenticated by default. You opt out rather than in to authentication
  • All endpoints are either one verb only or all HTTP verbs. You cannot have a handler for only GET and POST but not PUT, for example. Instead, you must create separate endpoints for each verb (unless you use ANY, in which case your lambda will be triggered for all HTTP verbs on that endpoint)
@MarkSFrancis
MarkSFrancis / LICENSE
Last active June 14, 2023 10:53
Reading raw PDFs from evs.ee
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
@MarkSFrancis
MarkSFrancis / BlobsBackground.tsx
Created January 6, 2023 11:20
Generates cool looking blurry blobs. Useful as a background for a glassmorphism-style
import { forwardRef, Box, BoxProps, Icon, IconProps } from "@chakra-ui/react";
import React, { FC, ReactText } from "react";
export interface BlobProps {
fill: string;
cx: ReactText;
cy: ReactText;
r?: ReactText;
}
@MarkSFrancis
MarkSFrancis / farm-money.js
Last active November 1, 2022 18:14
Bitburner scripts
const HOME_HOST = 'home'
/** @param {NS} ns */
export async function main(ns) {
ns.disableLog("ALL")
while (true) {
const hosts = getAllHosts(ns)
const targets = ['foodnstuff']
@MarkSFrancis
MarkSFrancis / README.md
Created June 6, 2021 08:56
Nice colors

Nice Colors

This little bit of HTML will generate a slider to change the hue, with a fixed saturation and lightness.

This produces consistently nice "pastel" like colors

@MarkSFrancis
MarkSFrancis / README.md
Last active December 28, 2020 13:53
Useful bash scripts

Run a script in here (using curl)

curl https://gist.githubusercontent.com/MarkSFrancis/c571d5f1003eb630ac3d142cb26f9805/raw/filename | bash

Add to your alias to allow easily running a script from bash:

# Usage: gist convert-audio
alias gist='function _gist(){ curl -S -s "https://gist.githubusercontent.com/MarkSFrancis/c571d5f1003eb630ac3d142cb26f9805/raw/$1.sh" | bash -s "${@:2}"; };_gist'