Skip to content

Instantly share code, notes, and snippets.

View TheRealOwenRees's full-sized avatar

Owen Rees TheRealOwenRees

View GitHub Profile
@TheRealOwenRees
TheRealOwenRees / context.ex
Created April 8, 2025 18:56
Phoenix Absinthe GraqhQL Contex
defmodule AppWeb.GraphQL.Context do
@moduledoc """
This module is responsible for setting up the context for GraphQL requests.
in a production environment, the session token is used internally. In development, this is often too long to be uses as a bearer token in GraphiQL playground.
In a development environment, we encode our session token in base64 and use it as a bearer token.
eg.
@TheRealOwenRees
TheRealOwenRees / logger.ts
Last active February 4, 2025 07:53
Basic Discord Logger
type DiscordLogType = 'error' | 'info'
interface IDiscordLog {
type: DiscordLogType
message: string
}
const embedColours: Record<DiscordLogType, number> = {
error: 0xff0000,
info: 0x00ff00
@TheRealOwenRees
TheRealOwenRees / tsconfig.json
Created August 30, 2024 10:23
React + Vite + TS alias "@" for src
{
"compilerOptions": {
//...
"paths": {
"@/*": ["./src/*"]
},
//...
},
"include": ["src"],
//...
@TheRealOwenRees
TheRealOwenRees / app.ts
Last active August 29, 2024 14:04
Auth Directive for Apollo GraphQL
//...
export const httpServer = http.createServer(app);
let schema = makeExecutableSchema({
typeDefs,
resolvers,
});
schema = authDirectiveTransformer(schema, "auth");
@TheRealOwenRees
TheRealOwenRees / numberToCurrency.ts
Last active January 28, 2025 13:14
Convert a number to a currency with your chose locale and currency type. Use 'undefined' to adjust to the host's locale.
export const numberToCurrency = (value: number | string): string => {
const numericValue =
typeof value === "string" ? Number.parseFloat(value) : value;
return numericValue.toLocaleString(undefined, {
style: "currency",
currency: "EUR",
});
};
@TheRealOwenRees
TheRealOwenRees / downloadString.js
Last active April 5, 2023 06:55
Download any string as a file
const downloadString = (string, filename) => {
try {
const element = document.createElement("a");
const file = new Blob([string], {
type: "text/plain",
});
element.href = URL.createObjectURL(file);
element.download = filename;
document.body.appendChild(element);
element.click();