Skip to content

Instantly share code, notes, and snippets.

@barbinbrad
barbinbrad / schema.sql
Last active August 2, 2025 12:19
Structured Raw Material Schema
CREATE TABLE "material" (
"id" TEXT NOT NULL PRIMARY KEY DEFAULT xid(),
"materialFormId" TEXT,
"materialSubstanceId" TEXT,
"materialTypeId" TEXT,
"finishId" TEXT,
"gradeId" TEXT,
"dimensionId" TEXT,
"companyId" TEXT,
"customFields" JSONB,
@barbinbrad
barbinbrad / index.ts
Created July 9, 2024 10:50
supabase/functions/post-purchase-invoice/index.ts
// deno-lint-ignore-file no-case-declarations
import { serve } from "https://deno.land/[email protected]/http/server.ts";
import { format } from "https://deno.land/[email protected]/datetime/mod.ts";
import { nanoid } from "https://deno.land/x/[email protected]/mod.ts";
import { DB, getConnectionPool, getDatabaseClient } from "../lib/database.ts";
import { corsHeaders } from "../lib/headers.ts";
import { getSupabaseServiceRole } from "../lib/supabase.ts";
import type { Database } from "../lib/types.ts";
import { credit, debit, journalReference } from "../lib/utils.ts";
import { getCurrentAccountingPeriod } from "../shared/get-accounting-period.ts";
@barbinbrad
barbinbrad / routing.md
Created April 1, 2024 14:22
Visualizing Routes

Visualizing Routes

A manufacturing process is a function that turns inputs to outputs. We can think of it like a math function:

f(x) = y

In this simplified example x is all inputs, y is the manufactured good, and f is a transformation function that turns x into y. Of course we know that f is not necessarily one process, but multiple processes such that:

f(x) = g1(x) + g2(x) + ... gn(x)

@barbinbrad
barbinbrad / purchasing-general-ledger-flow.md
Last active November 19, 2023 21:39
Posting of Receipts/Invoices/Payments
  • Goods Received Before Invoice:
    • Goods Received:
      • Accrual Entry
        • Debit the asset Interim Inventory Accrual
        • Credit the liability Inventory Received Not Invoiced
    • Invoice Received:
      • Reversing the Accrual Entry:
        • Debit the liability Inventory Received Not Invoiced
        • Credit the asset Interim Inventory Accrual
  • This reversing entry cancels out the initial accrual
@barbinbrad
barbinbrad / inbox.json
Last active February 3, 2025 13:29
API response
[
{
"id": "1",
"from": "Sample User",
"address": "[email protected]",
"time": "2021-10-07 15:35:14",
"message": "Duis cursus, diam at pretium aliquet, metus urna convallis erat, eget tincidunt dui augue eu tellus. Phasellus elit pede, malesuada vel, venenatis vel, faucibus id, libero. Donec consectetuer mauris id sapien. Cras",
"subject": "CarbonOS Interview",
"tag": "inbox",
"read": "false"
@barbinbrad
barbinbrad / city-timezones.json
Created August 17, 2023 04:06
City Timezones
[
{
"city": "Qal eh-ye Now",
"timezone": "Asia/Kabul",
"pop": 2997
},
{
"city": "Chaghcharan",
"timezone": "Asia/Kabul",
"pop": 15000
CREATE TABLE "group" (
"id" TEXT NOT NULL DEFAULT uuid_generate_v4(),
"name" TEXT NOT NULL,
"isIdentityGroup" BOOLEAN NOT NULL DEFAULT false,
"isEmployeeTypeGroup" BOOLEAN NOT NULL DEFAULT false,
"isCustomerOrgGroup" BOOLEAN NOT NULL DEFAULT false,
"isCustomerTypeGroup" BOOLEAN NOT NULL DEFAULT false,
"isSupplierTypeGroup" BOOLEAN NOT NULL DEFAULT false,
"isSupplierOrgGroup" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
@barbinbrad
barbinbrad / reactive.js
Last active May 13, 2022 14:16
Reactivity in javascript
function observe (obj) {
if (Object.prototype.toString.call(obj) !== '[object Object]') {
throw new TypeError()
}
Object.keys(obj).forEach(key => {
let internalValue = obj[key]
let dep = new Dependencies()
Object.defineProperty(obj, key, {
@barbinbrad
barbinbrad / http.js
Last active April 26, 2022 22:19
REST API Client
const http = {
stream(url) {
return http.fetchBlob(url);
},
get(url) {
return http.fetchJson(url);
},
post(url, data) {