Skip to content

Instantly share code, notes, and snippets.

View knksmith57's full-sized avatar

Kyle Smith knksmith57

View GitHub Profile
@Cikmo
Cikmo / README.md
Last active April 18, 2025 11:19
Connection handler that keeps Supabase Realtime channels alive. It automatically reconnects after errors, handles reauthentication, and more.

I had some issues getting a reliable connection up. Made this after a lot of experimentation and it now works well.

Includes how to keep the connection alive when the document is not visible, handles reconnecting on errors, and also fixes certain authentication issues when coming back to a document that has not been visible while the token expired.

To use it, you pass in a factory function for your RealtimeChannel. Do not call .subscribe() on the channel, the handler will do this for you. See example.

PS: If you're not using supabase-js you'll need to change stuff a bit. Instead of passing in SupabaseClient switch it to use RealtimeClient, and update the refreshSessionIfNeeded method to your authentication implementation.

If you see any problems or have suggestions for improvements, please leave a comment.

@GollyJer
GollyJer / app.config.ts
Last active December 9, 2024 14:15
app.config.ts
import { ConfigContext } from '@expo/config';
// eslint-disable-next-line no-console
// console.log('ENV', process.env);
// expands type in the vscode tooltip.
type ExpandTooltip<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
const EXPO_SDK = '51';
const BINARY_ITERATION_FOR_SDK = '1'; // start with 1. CAN NOT BE 0.
@LionelB5
LionelB5 / MockedLink.ts
Last active March 10, 2025 19:28
Apollo Client V3 link that supports mocking GraphQL subscriptions, mutations and queries. Particularly useful when testing components that rely on queries/mutations that execute concurrently to subscriptions that must be mocked.
@masonwolters
masonwolters / build-and-upload-simulator-binary.sh
Last active February 18, 2025 22:14
React native iOS with pre-built binaries
#
# This script is run in CI on master commits. It builds a debug binary
# for the iOS simulator and uploads it to the mobile-binaries repo.
#
# Then, when developer run `yarn ios` to develop locally, instead of
# having to build all of the native code, we just download the pre-built
# binary and install it on the simulator.
#
REPO_URL="{YOUR_GIT_URL}"
@JBGruber
JBGruber / docker-compose.yml
Last active March 10, 2025 01:26
My compose file to run ollama and ollama-webui
services:
# ollama and API
ollama:
image: ollama/ollama:latest
container_name: ollama
pull_policy: missing
tty: true
restart: unless-stopped
# Expose Ollama API outside the container stack (but only on the same computer;
@imankulov
imankulov / sqlalchemy_with_pydantic.py
Last active March 10, 2025 10:05
Using pydantic models as SQLAlchemy JSON fields (convert beween JSON and pydantic.BaseModel subclasses)
#!/usr/bin/env ipython -i
import datetime
import json
from typing import Optional
import sqlalchemy as sa
from sqlalchemy.orm import declarative_base, sessionmaker
from sqlalchemy.dialects.postgresql import JSONB
from pydantic import BaseModel, Field, parse_obj_as
@bmeck
bmeck / wip.mjs
Created June 24, 2021 14:00
in-progress in-thread heapsnapshot reflective API
import * as ns from './index.js';
import {promisify} from 'util';
import {createReadStream, createWriteStream} from 'fs';
import {Session} from 'inspector';
import {PassThrough} from 'stream';
import {createHash} from 'crypto';
const session = new Session();
const stream = new PassThrough();
@danopia
danopia / Dockerfile
Last active May 2, 2024 18:30
ERCOT Frozen Grid 2021 - Metrics Reporters
FROM hayd/alpine-deno:1.10.1
WORKDIR /src/app
ADD deps.ts ./
RUN ["deno", "cache", "deps.ts"]
ADD *.ts ./
RUN ["deno", "cache", "mod.ts"]
ENTRYPOINT ["deno", "run", "--unstable", "--allow-net", "--allow-hrtime", "--allow-env", "--cached-only", "--no-check", "mod.ts"]
#!/bin/zsh
### Added by Zinit's installer
if [[ ! -f $HOME/.zinit/bin/zinit.zsh ]]; then
print -P "%F{33}▓▒░ %F{220}Installing %F{33}DHARMA%F{220} Initiative Plugin Manager (%F{33}zdharma/zinit%F{220})…%f"
command mkdir -p "$HOME/.zinit" && command chmod g-rwX "$HOME/.zinit"
command git clone https://github.com/zdharma/zinit "$HOME/.zinit/bin" && \
print -P "%F{33}▓▒░ %F{34}Installation successful.%f%b" || \
print -P "%F{160}▓▒░ The clone has failed.%f%b"
fi
@goliatone
goliatone / README.md
Last active February 1, 2025 14:55 — forked from colophonemes/create_triggers
Postgres TRIGGER to call NOTIFY with a JSON payload

This TRIGGER function calls PosgreSQL's NOTIFY command with a JSON payload. You can listen for these calls and then send the JSON payload to a message queue (like AMQP/RabbitMQ) or trigger other actions.

Create the trigger with notify_trigger.sql.

When declaring the trigger, supply the column names you want the JSON payload to contain as arguments to the function (see create_triggers.sql)

The payload returns a JSON object: