Skip to content

Instantly share code, notes, and snippets.

View Zomatree's full-sized avatar
:fishsticks:

Angelo Kontaxis Zomatree

:fishsticks:
View GitHub Profile
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)
}
<!DOCTYPE HTML>
<html>
<head>
<meta charset='utf-8'>
<title>Hello, Zomatree</title>
<link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
<script>
const transferToDDG = () => {
let content = document.querySelector('input.searchField').value;
window.open(`https://duckduckgo.com/?t=ffab&q=${content}`, '_self')

Overview

messages can be sent with the components key to add buttons and other components (when discord brings them out), you can edit and add new buttons via editing the message, this is useful for the disabled key to stop people from clicking it.

Example Payload

{
    "content": "this is an example message for components",
    "components": [
        {"type": 1, "components": [
 {"type": 2, "style": 2, "label": "Button 1", "custom_id": "1"},
NzU0MjAzODEwMjA5MjAyMzI2.X1xVCA.8gzWvhv7T9HwQTSd8EPNVtkRLmQ
~/alacritty-0.5.0 $ cargo build
Downloaded log v0.4.8
Downloaded proc-macro2 v1.0.18
Downloaded utf8parse v0.2.0
Downloaded adler32 v1.1.0
Downloaded filetime v0.2.10
Downloaded clap v2.33.1
Downloaded signal-hook-registry v1.2.0
Downloaded syn v1.0.33
Downloaded serde_json v1.0.56