Skip to content

Instantly share code, notes, and snippets.

View oscartbeaumont's full-sized avatar

Oscar Beaumont oscartbeaumont

View GitHub Profile
@oscartbeaumont
oscartbeaumont / [path].ts
Last active January 17, 2022 13:07
Cloudflare Workers Serve Specific File from Function Issue
// This handler does a 301 redirect to `/test` in a loop until browser throws ERR_TOO_MANY_REDIRECTS (using wrangler@beta)
export const onRequest: PagesFunction<unknown> = async ({ request, env }) => {
// The goal of this handler is to return a static file called `test.html`.
// Parsing `/test.html` directly returns a URL parsing error as per issue https://github.com/cloudflare/wrangler2/issues/165
const assetReq = new Request("http://fakehost/test.html", {
cf: request.cf,
});
const response = await env.ASSETS.fetch(assetReq);
return new Response(response.body, response);
@oscartbeaumont
oscartbeaumont / Cargo.toml
Created December 26, 2021 01:30
Async GraphQL Field Guard on Complex Object Not Working
[package]
name = "async-graphql-example"
version = "0.1.0"
authors = ["Oscar Beaumont <oscar@otbeaumont.me>"]
edition = "2018"
[dependencies]
async-graphql = "3.0.17"
actix-web = "4.0.0-beta.14"
async-graphql-actix-web = "3.0.17"
@oscartbeaumont
oscartbeaumont / generic.rs
Created December 24, 2021 02:45
SeaORM Custom Value
# This code does not work.
# The DeriveEntityModel panics with error `message: `"AccountId<String>"` is not a valid identifier`
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, SimpleObject)]
#[sea_orm(table_name = "tenant")]
#[graphql(name = "Tenant")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: AccountId<String>,
pub name: String,
@oscartbeaumont
oscartbeaumont / Cargo.toml
Created December 22, 2021 10:24
Async GraphQL Generic Interface Bug
[package]
name = "async-graphql-relay-example"
version = "0.1.0"
authors = ["Oscar Beaumont <oscar@otbeaumont.me>"]
edition = "2018"
[dependencies]
async-graphql = "3.0.17"
actix-web = "4.0.0-beta.14"
async-graphql-actix-web = "3.0.17"
@oscartbeaumont
oscartbeaumont / Cargo.toml
Created December 17, 2021 17:49
SeaORM Test
[package]
name = "sea-orm-test"
version = "0.1.0"
edition = "2021"
[dependencies]
sea-orm = { version = "0.4.2", features = [ "sqlx-sqlite", "runtime-tokio-native-tls", "macros" ], default-features = false }
tokio = { version = "1", features = ["full"] }
@oscartbeaumont
oscartbeaumont / README.md
Last active September 12, 2021 04:10
A Problem

Items: A - 158mm B - 128mm C - 143mm D - 60mm E - 93mm

How many of each fit into 1500mm with only 5-10mm of wastage

a158 + b128 + c143 + d60 + e*60

hello: {{ (datasource "config").test }}
@oscartbeaumont
oscartbeaumont / Cargo.toml
Created June 13, 2021 17:27
Rust Actix Scope Middleware
[package]
name = "rust-actix-scope-middleware-bug"
version = "0.1.0"
authors = ["Oscar Beaumont <oscar@otbeaumont.me>"]
edition = "2018"
[dependencies]
actix-web = "3.3.2"
@oscartbeaumont
oscartbeaumont / Cargo.toml
Last active May 21, 2021 19:13
async-graphql Renaming Fields
[package]
name = "async-graphql-issue"
version = "0.1.0"
authors = ["Oscar Beaumont <oscar@otbeaumont.me>"]
edition = "2018"
[dependencies]
async-graphql = "2.8.5"
tokio = { version = "0.2.22", features = ["full"] }
@oscartbeaumont
oscartbeaumont / setup.ps1
Created December 22, 2020 06:29
Setup Machine
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
echo "Configure Computer Name"
$computerName = Read-Host 'Enter New Computer Name'
Write-Host "Renaming this computer to: " $computerName -ForegroundColor Yellow
Rename-Computer -NewName $computerName
echo "Fixing time"
Set-TimeZone "W. Australia Standard Time"
net start w32time