Skip to content

Instantly share code, notes, and snippets.

import ProofWidgets.Demos.Graph.ExprGraph
import ProofWidgets.Component.GraphDisplay
import ProofWidgets.Component.HtmlDisplay
import Lean.Data.Json
import Mathlib.Tactic.Ring
import Architect
open Lean ProofWidgets Jsx
--------------------------------------------------------------------------------
@nileshtrivedi
nileshtrivedi / crdt-distsys-simulator.ts
Created November 12, 2025 03:13
Simulator for Reactivity in Distributed System with CRDT-based state
// A CRDT is a wrapper data-structure for a value that knows
// how to synchronize with other replicas to achieve eventual consistency
// A single special method "apply" is expected to incorporate messages received from replicas.
// Local mutations are applied immediately ("optimistically")
// Eventual consistency is achieved with the apply method being commutative, associative and sometimes idempotent
// Mutators must produce a new local CRDT instance (that includes the changes requested) and a Message/Effect to broadcast
// For state-based CRDT, the whole internal state gets broadcasted
// For op-based CRDT, the operation itself gets broadcasted
// message = null is treated as a no-op (for eg: adding an existing item to a set) and skips broadcasting when not needed
@nileshtrivedi
nileshtrivedi / game.ex
Created July 9, 2025 07:52
distributed reactivity example
defmodule ExampleWeb.LiveSigil do
use ExampleWeb, :live_view
def render(assigns) do
~V"""
<script>
import { onMount } from 'svelte';
// props sent from the server
let { shown_word, leaderboard, live } = $props();
@nileshtrivedi
nileshtrivedi / aichat.exs
Last active June 16, 2025 03:21
WIP: AI Chat using Tamnoon
# Run this with: OPENAI_API_KEY= elixir bot.exs
Mix.install([
{:tamnoon, "== 1.0.0-a.5"},
{:langchain, "== 0.4.0-rc.0"}
])
defmodule Bot.Components.Root do
@behaviour Tamnoon.Component
@nileshtrivedi
nileshtrivedi / app.exs
Created June 13, 2025 06:29
tamnoon single-file demo
# Run this as `elixir app.exs`
Mix.install([
{:tamnoon, "~> 0.1.0"}
])
defmodule TamnoonSample do
end
defmodule TamnoonSample.Router do
@nileshtrivedi
nileshtrivedi / app.exs
Created June 11, 2025 11:57
single-file todo with ash without auth
Mix.install([
{:ash, "~> 3.0"},
{:phoenix_playground, "== 0.1.6"},
], consolidate_protocols: false)
defmodule Helpdesk do
end
defmodule Helpdesk.Support do
use Ash.Domain, validate_config_inclusion?: false
@nileshtrivedi
nileshtrivedi / todo.exs
Created June 11, 2025 11:16
single-file todo list app with ash framework and elixir
Mix.install([
{:ash, "== 3.5.17"},
{:ash_authentication, "== 4.9.0"},
{:ash_authentication_phoenix, "== 2.8.0"},
{:phoenix_playground, "== 0.1.6"},
{:picosat_elixir, "== 0.2.3"},
{:jason, "== 1.4.4"},
{:bcrypt_elixir, "== 3.3.2"}
], consolidate_protocols: false)
@nileshtrivedi
nileshtrivedi / app.exs
Created December 9, 2024 12:17
Attempt to make a single-file multi-user liveview-based ToDo application
# postgres should be running
# it should have a table called todos
# See Migrations module on how to create the table
# The application can be started with
# JWT_SECRET=6fa91f11ca785e9a73d340ea8d3d03ed SECRET_KEY_BASE=6fa91f11ca785e9a73d340ea8d3d03ed6fa91f11ca785e9a73d340ea8d3d03ed elixir app.exs
# To access the app with authentication, visit this URL that includes the JWT token:
# http://localhost:4000/?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.keYoDT2sQMzTicz_1oqmfduw0HYrwnxc4iwoq9Vr-hQ
# Current issues:
# LiveView's second mount() does not include session data
@nileshtrivedi
nileshtrivedi / create_google_cal_event.js
Created September 8, 2024 15:47
Create Google Calendar event from selected text on web via OpenRouter LLM
// ==UserScript==
// @name Create Google Calendar Event from Selected Text
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Create a Google Calendar event using selected text and current page URL as the description
// @match *://*/*
// @grant GM_openInTab
// @grant GM_registerMenuCommand
// @grant GM_xmlhttpRequest
// ==/UserScript==
@nileshtrivedi
nileshtrivedi / app.ru
Created August 16, 2024 03:29
Single-file Rails app experiment
# frozen_string_literal: true
# Run this app as: puma app.ru
# Most of this was taken from: https://greg.molnar.io/blog/a-single-file-rails-application/
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'