Skip to content

Instantly share code, notes, and snippets.

View Lyokolux's full-sized avatar
🦄
Building something

Lyokolux Lyokolux

🦄
Building something
View GitHub Profile
@Lyokolux
Lyokolux / client.ts
Last active October 26, 2022 08:23
Server Side Events implementation in a Nuxt 3 backend of notifications retrieved from the prisma ORM. A second file provide an example of use as snippet.
import { NotificationEvent } from '~~/server/api/v1/user/notifications/live.get'
/** Init the listener on the dedicated API endpoint */
const evtSource = new EventSource("/api/live")
/** Callback on message recieved */
evtSource.onmessage = (e: MessageEvent<string>) => {
if (e.data) {
this.notifications = [...JSON.parse(e.data) as NotificationEvent[], ...this.notifications]
}
}
@Lyokolux
Lyokolux / lightdarkmode.css
Created October 17, 2022 07:04
Masterarbeit light/dark mode demonstration
html {
--text-color: white;
--label-field-color: white;
--bg-color: black;
&.light {
--text-color: black;
--label-field-color: grey;
--bg-color: white;
}
@Lyokolux
Lyokolux / buttons.scss
Created October 17, 2022 06:49
Materarbeit button styling
// default abtract btn definition
%btn {
font-family: 'Logical-Regular';
width: fit-content;
height: fit-content;
padding: 4px 18px; // -2px for the border
border-radius: var(--radius-m);
transition: filter 0.3s ease-in-out, background-color 0.3s ease-in-out, color 0.3s ease-in-out;
border: 2px solid transparent;
@Lyokolux
Lyokolux / docker-compose.yml
Created October 10, 2022 08:39
Docker Compose for the deployment of the Masterarbeit application
version: "3.9"
volumes:
db:
services:
app:
image: ${APP_IMAGE_TAG}
container_name: app
ports:
@Lyokolux
Lyokolux / useAPIError.ts
Created October 6, 2022 12:42
Error format implementation of the RFC 7807 for NodeJS HTTP environments
import type { CompatibilityEvent } from 'h3'
import HttpStatusCode from '~~/const/httpStatusCode'
import { APIErrorTitle } from './apiErrorTitle'
/** Format of the [RFC 7807](https://www.rfc-editor.org/rfc/rfc7807) */
export type useAPIErrorOptions<T> = T & {
/** A URI that identifies the problem type.
* This specification encourages that, when dereferenced,
* it provide human-readable documentation for the problem type
*/
/**
* Hypertext Transfer Protocol (HTTP) response status codes.
* @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
*/
enum HttpStatusCode {
/**
* The server has received the request headers and the client should proceed to send the request body
* (in the case of a request for which a body needs to be sent; for example, a POST request).
@Lyokolux
Lyokolux / triggers.sql
Last active September 28, 2022 10:42
Masterarbeit - Notification Triggers
-- VOTE NOTIFICATIONS --
-- Notify the author of the participation that a vote is given --
CREATE TRIGGER IF NOT EXISTS VOTE_INSERT_NOTIFICATION
AFTER INSERT ON Vote
FOR EACH ROW
BEGIN
INSERT INTO Notification(notificationTypeId, content, toUserId)
SELECT 'vote', Participation.id, Participation.authorId
FROM Participation
@Lyokolux
Lyokolux / Icon.vue
Last active September 27, 2022 11:21
Integration of an Iconfont (dripicons) in Vue 3 (<3.2)
<script setup lang="ts">
type Props = {
icon: `dripicons-${string}`
size?: string
alt?: string
}
const props = withDefaults(defineProps<Props>(), {
size: '1rem'
@Lyokolux
Lyokolux / endpoint.ts
Last active September 23, 2022 11:48
Masterarbeit - PoC for Mattermost in a nuxt environment.
import { mattermostClient, channel_id } from '~/server/lib/mattermost'
const message = {
channel_id,
message: 'Send from Nitro!',
}
// SUCCESSFUL:
@Lyokolux
Lyokolux / tokenHelper.ts
Last active September 25, 2022 06:44
An helper function for easy token manipulation based on the package jsonwebtoken.
import jsonwebtoken from "jsonwebtoken"
import type { JwtPayload } from "jsonwebtoken"
export type JwtAppPayload = {
username: string
// more properties to store in the token
}
// augmented type containing the custom informations that
export type JwtApp = JwtPayload & JwtAppPayload