Skip to content

Instantly share code, notes, and snippets.

View caesaneer's full-sized avatar

Dan Casler caesaneer

View GitHub Profile
@caesaneer
caesaneer / user.ts
Last active December 28, 2022 06:18
Firebase user store that derives from a Firebase auth store
// SVELTE
import { derived, type Readable } from 'svelte/store';
// FIREBASE
import { onAuthStateChanged } from 'firebase/auth';
import type { Auth, User } from 'firebase/auth';
// LIB
import { firebaseAuth } from '$lib/firebaseAuth';
import { authEmitter } from '$lib/urqlClient';
function newUserStore() {
@caesaneer
caesaneer / urqlClient.ts
Last active December 28, 2022 03:19
urql client using Mitt to receive authState changes from Firebase onAuthStateChanged
// URQL
import { makeOperation, fetchExchange } from '@urql/core';
import { createClient } from '@urql/svelte';
import { authExchange } from '@urql/exchange-auth';
import type { ClientOptions, Operation } from '@urql/svelte';
// MITT
import mitt from 'mitt';
type AuthState = {
accessToken?: string;
@caesaneer
caesaneer / api.rs
Created February 10, 2022 03:56
FRB
#![allow(unused_variables)]
use anyhow::Result;
use flutter_rust_bridge::StreamSink;
#[derive(Debug, Clone)]
pub struct MySize {
pub width: i32,
pub height: i32,
}
@caesaneer
caesaneer / svelte.config.js
Created August 5, 2021 22:42
Final svelte.config.js file
import preprocess from 'svelte-preprocess';
import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),
kit: {
import preprocess from 'svelte-preprocess';
import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),
kit: {
@caesaneer
caesaneer / worker.js
Created August 18, 2019 22:17
Part 2 - Worker Threads - Worker.js
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
const { parentPort, workerData } = require('worker_threads')
const bench = require('./bench')
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
parentPort.on('message', () => {
const result = bench(100)
parentPort.postMessage(result)
@caesaneer
caesaneer / index.js
Created August 18, 2019 22:16
Part 2 - Worker Threads - Index.js
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
const http = require('http')
const { StaticPool } = require('node-worker-threads-pool')
const numCPUs = require('os').cpus().length
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
const host = '192.168.0.14'
const port = 8080
@caesaneer
caesaneer / index.js
Last active August 18, 2019 23:22
Part 2 - Node Cluster Module
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
const cluster = require('cluster')
const http = require('http')
const numCPUs = require('os').cpus().length
const bench = require('./bench')
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
const host = '192.168.0.14'
@caesaneer
caesaneer / index.js
Created August 18, 2019 22:14
Part 2 - Node.js Single Process
const http = require('http')
const bench = require('./bench')
const host = '192.168.0.14'
const port = 8000
const start = function startServer() {
// Simple request router
const router = function requestRouter(request, reply) {
const result = bench(100)
@caesaneer
caesaneer / index.js
Created August 18, 2019 22:12
Node Bench Module
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
// Calculate Fibonacci sequence for num
function fib(n) {
if (n > 40) {
throw new TypeError('Fib: N is greater than 40.')
}
const s = [1]