Skip to content

Instantly share code, notes, and snippets.

View maietta's full-sized avatar

Nick Maietta maietta

View GitHub Profile
@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;
}
@maietta
maietta / +page.server.ts
Created November 18, 2024 21:24
Nearly entire reactive Search Form for Real Estate websites
import type { PageServerLoad } from './$types';
import pb from '$lib/pocketbase';
import { propertyClassMap } from './guards'; // Import the source of truth
export const load: PageServerLoad = async ({ url, depends, params }) => {
depends('app:search'); // Revalidate on every request to this tag.
const slugs = params.slugs?.replace(/^\/|\/$/g, '').split('/') || [];
const [classSlug, typeSlug] = slugs;
@maietta
maietta / +page.svelte
Created November 18, 2024 03:38
Example Svelte 5 Real Estate Form
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { onMount } from 'svelte';
import { queryParameters, ssp } from 'sveltekit-search-params';
import Pagination from './pagination.svelte';
let { records, ...props } = $props();
const system = $state({ Class: '', Type: '', page: 1 });
@maietta
maietta / SecretFormula.ts
Created November 16, 2024 21:10
The secret formula search form.
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { onMount } from 'svelte';
import { queryParameters } from 'sveltekit-search-params';
// Initialize query parameters management
const params = queryParameters(
{
test: {
@maietta
maietta / RETSMetadataTable.d.ts
Last active November 12, 2024 04:02
generateCreateTableSql function
// Define the type for individual fields
export interface RETSField {
SystemName?: string | string[];
Interpretation?: string[];
DataType?: string[];
MaximumLength?: number[];
Precision?: number[];
LongName?: string[];
}