Skip to content

Instantly share code, notes, and snippets.

View johannschopplich's full-sized avatar

Johann Schopplich johannschopplich

View GitHub Profile
@johannschopplich
johannschopplich / proxy.ts
Created August 30, 2024 08:19
unenv `createMock`, but optimized
const fn = function () {}
function createMock(name: string, overrides: Record<any, any> = {}): any {
fn.prototype.name = name
const props: Record<any, any> = {}
return new Proxy(fn, {
get(_target, prop) {
if (prop === 'caller') {
return null
}
@johannschopplich
johannschopplich / polyfill.ts
Created June 24, 2024 08:22
Polyfill for `Promise.witResolvers()` in TypeScript
Promise.withResolvers ??= function <T>() {
let resolve: PromiseWithResolvers<T>["resolve"];
let reject: PromiseWithResolvers<T>["reject"];
const promise = new Promise<T>((res, rej) => {
resolve = res;
reject = rej;
});
return { promise, resolve: resolve!, reject: reject! };
};
@johannschopplich
johannschopplich / backup-env.mjs
Created April 24, 2024 07:53
Backup all your .env files while keeping the directory structure of the source directory
import process from "node:process";
import fsp from "node:fs/promises";
import path from "node:path";
import fg from "fast-glob";
async function copyEnvFiles(sourceDir, backupDir) {
try {
const envFiles = await fg(["**/.env"], {
cwd: sourceDir,
ignore: ["**/node_modules/**"],
@johannschopplich
johannschopplich / blueprint.yaml
Created April 19, 2024 05:43 — forked from lukaskleinschmidt/blueprint.yaml
Kirby 4 query pages from a searchengine for the pages field
fields:
articles:
type: pages
query: kirby.collection('articles')
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Patrick Marsceill, software designer</title>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicon-32x32.png"
@johannschopplich
johannschopplich / storage.ts
Created October 30, 2023 11:05
Capacitor Preferences binding for VueUse `useStorageAsync`
import { Preferences } from "@capacitor/preferences";
import type {
MaybeRefOrGetter,
RemovableRef,
StorageLikeAsync,
UseStorageAsyncOptions,
} from "@vueuse/core";
const capacitorPreferenceStorage: StorageLikeAsync = {
async getItem(key: string): Promise<string | null> {
@johannschopplich
johannschopplich / main.js
Created September 5, 2023 07:20
Check which tables are available for Seven SwansSEVEN SWANS restaurant in Frankfurt am Main
// 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
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 27, 2024 15:26
Custom nginx caching headers for Ploi.io for Kirby CMS
# 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

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