Skip to content

Instantly share code, notes, and snippets.

Avatar

Johann Schopplich johannschopplich

View GitHub Profile
@johannschopplich
johannschopplich / main.js
Created September 5, 2023 07:20
Check which tables are available for Seven SwansSEVEN SWANS restaurant in Frankfurt am Main
View main.js
// Function to fetch reservation data from API
async function fetchReservationData(date, capacity = 2, agentId = 2) {
const baseUrl =
'https://9110-api.quandoo.com/merchants/56296/reservation-options'
const url = `${baseUrl}?date=${date}&capacity=${capacity}&agentId=${agentId}`
try {
const response = await fetch(url)
const data = await response.json()
@johannschopplich
johannschopplich / auth.server.ts
Last active September 22, 2023 07:51
Nuxt API Party usage with auth store
View auth.server.ts
import { useAuthStore } from '~/stores/auth'
export default defineNuxtPlugin(async () => {
const authStore = useAuthStore()
// Refresh the token once on the server
if (authStore.isLoggedIn && authStore.isTokenExpired()) {
await authStore.refresh()
}
})
@johannschopplich
johannschopplich / nginx.conf
Last active June 21, 2023 09:30
Custom nginx caching headers for Ploi.io for Kirby CMS
View nginx.conf
# assets and media
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|heic|webp|svgz?|mp3|m4a|aac|ogg|wav|mp4|mov|webm|mpe?g|avi|ogv|wmv|woff2?)$ {
try_files $uri $uri/ /index.php?$query_string;
add_header Cache-Control "public, max-age=31536000, immutable";
access_log off;
}
@johannschopplich
johannschopplich / README.md
Last active June 23, 2023 15:45
OpenAI audio transcriptions from folder
View README.md

Create Transcripts from Audio Files

This script uses OpenAI's Whisper ASR (Automatic Speech Recognition) system to generate transcripts from the audio files.

In addition to the Python packages mentioned above, you need to provide an OpenAI API key as an environment variable:

export OPENAI_API_KEY=your-api-key
@johannschopplich
johannschopplich / better-scroller.client.ts
Created June 7, 2023 17:19
Nuxt plugin for `vue-router-better-scroller` with with Suspense route resolution
View better-scroller.client.ts
import { createRouterScroller } from 'vue-router-better-scroller'
interface ScrollPositionCoordinates {
behavior?: ScrollOptions['behavior']
left?: number
top?: number
}
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(
@johannschopplich
johannschopplich / password.ts
Last active May 3, 2023 21:40
Password strength meter calculation
View password.ts
const SPECIAL_CHAR_RE = /[^A-Za-z0-9]/g
const LOWERCASE_RE = /[a-z]/g
const UPPERCASE_RE = /[A-Z]/g
const NUMBER_RE = /[0-9]/g
const SCORE_MAP = ['risky', 'guessable', 'weak', 'safe', 'secure'] as const
export function getPasswordStrength(input: string | number) {
const score = typeof input === 'string' ? getPasswordScore(input) : input
return SCORE_MAP[score]
@johannschopplich
johannschopplich / index.ts
Created April 20, 2023 09:58
Rust-like result type in TypeScript
View index.ts
/**
* First, create a type helper that represents
* the Result that we'll get from our safe function
*/
type Result<T> =
| {
ok: true;
value: T;
}
| {
@johannschopplich
johannschopplich / AppIcon.vue
Created February 24, 2023 13:41
Auto-import icons from `assets` in Nuxt
View AppIcon.vue
<template>
<span
v-if="icon"
:class="[
'children-[svg]:h-full children-[svg]:w-full',
defaultStyles && 'inline-block h-[1em] w-[1em] align-middle',
]"
v-html="icon"
/>
</template>
@johannschopplich
johannschopplich / MasonryGrid.vue
Last active July 4, 2023 12:06
Vue 3 component for masonry grid polyfill
View MasonryGrid.vue
<script setup lang="ts">
const props = withDefaults(
defineProps<{
columnMaxWidth?: string;
}>(),
{
columnMaxWidth: "25rem",
}
);
@johannschopplich
johannschopplich / form-data-utils.ts
Created December 12, 2022 21:23
Serialize FormData to object with support for Blobs
View form-data-utils.ts
import { FormData as _FormData } from 'formdata-polyfill/esm.min.js'
export async function formDataToObject(formData: FormData) {
const obj: Record<string, any> = {}
for (const [key, value] of formData.entries()) {
if (value instanceof Blob) {
obj[key] = {
__type: 'blob',
...(await serializeBlob(value)),