Skip to content

Instantly share code, notes, and snippets.

View Zomatree's full-sized avatar
:fishsticks:

Zomatree Zomatree

:fishsticks:
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
use std::{borrow::Cow, mem};
use chumsky::{Parser as _, prelude::*};
use freya::{icons::lucide::hash, prelude::*};
use pulldown_cmark::{Event, HeadingLevel, Options, Parser, Tag, TagEnd};
define_theme! {
%[component]
pub MarkdownViewer {
%[fields]
fn app() -> impl IntoElement {
let value = use_state(|| 0);
rect()
.background(0xff292a2f)
.color(0xffe3e1e9)
.width(Size::Fill)
.height(Size::Fill)
.spacing(8.)
.font_size(14.)
@Zomatree
Zomatree / partial.rs
Created February 1, 2026 02:08
partials
macro_rules! generate_field_diff {
(optional, $self:ident, $before:ident, $partial:ident, $field:ident) => {
if $partial.$field.is_some() {
$before.$field = $self.$field.clone();
};
};
($self:ident, $before:ident, $partial:ident, $field:ident) => {
if $partial.$field.is_some() {
$before.$field = Some($self.$field.clone());
type StringFlags = "c" | "b" | "B";
type NumberFlags = "n"
type Resolve<T extends string> = (
T extends StringFlags ? [string] :
T extends NumberFlags ? [number] :
[] // ignore stuff like ">"
);
type Repeat<
from __future__ import annotations
from typing import TYPE_CHECKING, Any, ClassVar, Generic, Literal, Self, TypeVar, Annotated, TypeVarTuple, get_args, overload, get_origin, reveal_type, cast
import asyncpg
T = TypeVar("T")
T_T = TypeVar("T_T", bound="Table", covariant=True)
T_OT = TypeVar("T_OT", bound="Table", covariant=True)
T_Ts = TypeVarTuple("T_Ts")
@Zomatree
Zomatree / sql.ts
Created April 13, 2023 02:46
Type-safe sql parameters
type IsValid<Name> = Name extends `${infer _} ${infer _}`
? never
: Name;
type IsParameter<Part> = Part extends `\$${infer Parameter}`
? IsValid<Parameter>
: never;
type QueryParser<Query> = Query extends `${infer A}${' ' | '='}${infer B}`
? IsParameter<A> | QueryParser<B>
@Zomatree
Zomatree / serde.py
Last active December 28, 2022 22:49
from __future__ import annotations
from dataclasses import dataclass
from types import NoneType, UnionType
from typing import Annotated, Any, Callable, Generic, Iterable, TypeGuard, TypeVar, Union, cast, get_origin as _get_origin, get_args, Self
T = TypeVar("T")
# isistance doesnt allow the second paramter to be generic so we must get the origin, however typing.get_origin doesnt return the class if its not generic
# so we default back to the type ourself
use std::{any::Any, collections::HashMap};
trait VTable<G = ()> {
const NAME: &'static str;
fn table(&self) -> HashMap<&str, &'static dyn Any>;
fn get<T: 'static>(&self, name: &str) -> &T {
let table = self.table();
let any = table[name];
use bumpalo::Bump;
use std::fmt;
mod lifetimes {
use std::mem;
pub unsafe fn extend_lifetime<'a, 'b, T>(value: &'a T) -> &'b T {
mem::transmute(value)
}