Skip to content

Instantly share code, notes, and snippets.

View maietta's full-sized avatar

Nick Maietta maietta

View GitHub Profile
@maietta
maietta / coolify_webhook_proxy_handler.ts
Created January 12, 2025 06:20
Proxies webhook payloads from Gitea and triggers a deploy for a matching repo and branch.
import { serve } from "bun";
import fs from "fs";
// Extract the repository name and branch from the payload
function extractRepoInfo(payload: { repository: { full_name: string }; ref: string }) {
const repoName = payload?.repository?.full_name; // Repository name is in 'full_name'
const branch = payload?.ref?.split("/").pop(); // Branch name is after 'refs/heads/'
return { repoName, branch };
}
@maietta
maietta / +page.svelte
Created December 30, 2024 05:51
Svelte 5 reactive grid/list layout.
<script lang="ts">
import { preferences } from '$lib/stores/preferences'; // Reactive store
import Pagination from './pagination.svelte';
import { truncateDescription, glance } from '$lib/realty/presentation';
let { data } = $props();
let selectedIndex = $state(1);
let listings = $derived(data.results.records);
let pagination = $derived(data.results.pagination);
@maietta
maietta / gallery.svelte
Last active February 15, 2025 04:58
SwiperJS with Svelte 5
@maietta
maietta / SearchForm.svelte
Created December 11, 2024 04:26
Insanely stupid Search Form
<script>
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { onMount } from 'svelte';
import { queryParameters, ssp } from 'sveltekit-search-params';
import { propertySchema } from '$lib/helpers/propertySchema';
import CurrencyInput from '@canutin/svelte-currency-input';
let system = $state({ Class: '', Type: '' });
@maietta
maietta / import.ts
Last active December 8, 2024 04:58
Impersonate Superuser via API token to import CSV
import fs from 'fs';
import csv from 'csv-parser';
import PocketBase from 'pocketbase';
const token = "API_KEY_OF_IMPERSONATED_SUPERUSER";
// Initialize PocketBase client
const pb = new PocketBase('https://<YOUR-POCKETBASE-URL>');
pb.authStore.save(token, null);
@maietta
maietta / +page.svelte
Last active December 2, 2024 14:56
WebSocket for SvelteKit using Bun.
<script lang="ts">
import { browser } from '$app/environment';
let ws: WebSocket | null = null;
let connecting = true;
let connected = false;
let messages: string[] = [];
let sendValue: string = '';
@maietta
maietta / InMemoryKeyValueStore.ts
Last active November 29, 2024 16:45
In-Memory Key Value Store with Bun's SQLite implementation.
import { Database } from "bun:sqlite";
export class InMemoryKeyValueStore {
private static instance: InMemoryKeyValueStore | null = null;
private db: Database;
// Private constructor to initialize the SQLite database
private constructor() {
this.db = new Database(":memory:"); // In-memory SQLite database
this.initializeDatabase();
@maietta
maietta / +layout.svelte
Last active November 28, 2024 22:03
Front-end reacting to changes in Pocketbase, but using Pocketbase on the backend, not the front-end.
<script lang="ts">
import '../app.css';
let { children }: { children: any } = $props();
import { source } from 'sveltekit-sse';
const value = source('/api/config').select('message'); // Use $value to access the store
</script>
<p>Fiddle with field change in Pocketbase to see this update in realtime</p>
{JSON.stringify($value)}
@maietta
maietta / Dockerfile
Created November 26, 2024 20:37
Example real-time replication from Pocketbase to MySQL with different data schemas.
FROM oven/bun:latest
WORKDIR /app
COPY . .
RUN bun install
RUN bun build ./realtime.ts --compile --outfile realtime
RUN chmod +x /app/realtime
@maietta
maietta / DatabaseFieldMapper.ts
Created November 22, 2024 03:57
Cache example in SQLite for realty websites
import { Database } from "bun:sqlite";
import jsonData from '$lib/server/utils/realty/fieldMaps.json'; // Import the JSON directly
// Define structure for the JSON object
interface FieldMapping {
fieldName: string;
alias: string;
description: string;
}