Skip to content

Instantly share code, notes, and snippets.

View Xevion's full-sized avatar
⚜️
Chaos Order

Xevion Xevion

⚜️
Chaos Order
View GitHub Profile
import asyncio
import io
import os
from typing import Optional
import websockets
from PIL import Image
from constants import Environment
-- Find all threads that have zero subscriptions BUT have at least one attachment
SELECT *
FROM (SELECT "Thread".id, "Thread".subject,
COUNT(DISTINCT(S."threadId")) AS Subscriptions,
COUNT(A.id) AS Attachments
FROM "Thread"
LEFT JOIN "Post" P on "Thread".id = P."threadId"
LEFT JOIN "Attachment" A on P.id = A."postId"
LEFT JOIN "Subscription" S on "Thread".id = S."threadId"
GROUP BY "Thread".id)
@Xevion
Xevion / sets.ts
Created February 8, 2023 05:51
Typescript Set Functions
export const union = <T>(a: Set<T>, b: Set<T>) => new Set([...a, ...b]);
export const intersection = <T>(a: Set<T>, b: Set<T>) => new Set([...a].filter(x => b.has(x)));
export const difference = <T>(a: Set<T>, b: Set<T>) => new Set([...a].filter(x => !b.has(x)));
export const symmetric = <T>(a: Set<T>, b: Set<T>) => union(difference(a, b), difference(b, a));
export const isSubsetOf = <T>(a: Set<T>, b: Set<T>) => [...b].every(x => a.has(x));
export const isSupersetOf = <T>(a: Set<T>, b: Set<T>) => [...a].every(x => b.has(x));
export const isDisjointFrom = <T>(a: Set<T>, b: Set<T>) => !intersection(a, b).size;
/*
The router query parameters are not immediately made available on first render.
Here I use a reference to track when the router's query parameter were first made available.
A reference is used instead of state to ensure no unnecessary re-renders are made.
*/
const routerExecutionRef = useRef(false);
useEffect(() => {
if (router.isReady && !routerExecutionRef.current) {
routerExecutionRef.current = true;
import React from "react";
import { Button } from "@chakra-ui/react";
import ReactDOMServer from "react-dom/server";
interface DipswitchProps {
length: number;
value: number;
}
interface DipswitchExporterProps {
import { z } from "zod";
import { getMonth } from "date-fns";
export const SeasonEnum = z.enum(["FALL", "SPRING"]);
export type Season = z.TypeOf<typeof SeasonEnum>;
export const SemesterSchema = z.object({
season: SeasonEnum,
year: z.number().min(2000).max(2050),
});
import { createContext, Dispatch, ReactNode, useContext, useReducer } from "react";
export interface GlobalContextProps {
loggedIn: boolean;
background: boolean;
}
export interface GlobalContextAction {
type: string;
value: any;
@Xevion
Xevion / slug.py
Created August 26, 2022 05:37
Slug + base64 identifier URL generation
"""
slug.py
Contains operations and functions integral to slug processing and identifier extraction
"""
from math import ceil
from slugify import slugify
from typing import Optional
@Xevion
Xevion / bitwise_versus_addition.py
Last active August 4, 2022 19:30
Bitwise vs Addition in Python (1 million loops)
In [1]: def bitwise_or():
...: x = 0
...: for i in range(1, 32):
...: x |= 1 << i
...: return x
...:
In [2]: def addition():
...: x = 0
...: for i in range(1, 32):
@Xevion
Xevion / asb_union.c
Created July 7, 2022 00:17
Addressed Single Block Write Union Magic
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
struct AddressedSingleBlockWrite {
uint8_t Flag;
uint8_t Command;
uint8_t Address[8];
uint8_t Block;