Skip to content

Instantly share code, notes, and snippets.

@hos
hos / LICENSE.md
Last active May 26, 2025 08:21
Plugin for generating sdk for postgraphile schema direct usage.

The MIT License (MIT) Copyright © 2025 Hovhannes Sanoyan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH TH

import type { PgCodec } from '@dataplan/pg';
import { EXPORTABLE } from 'graphile-build';
import { sql } from 'pg-sql2';
import { Geometry } from 'wkx';
interface State {
geometryCodec: PgCodec<string, any, any, any, undefined, any, any>;
}
declare global {
@hos
hos / knex-typed-clip-columns.ts
Last active August 8, 2024 13:39
Typed function to use with knex tables, to remove some columns from provided object.
import 'types/schemas/knex-tables'
import { Tables } from 'knex/types/tables'
type TableColumns<TTableName extends keyof Tables = keyof Tables> = {
[T in TTableName]: (keyof Tables[T]['base'])[]
}
const deleteColumns: Partial<TableColumns> = {
users: ['name'],
}
export function bigIntP(value: bigint, percentage: number, scalingFactor = 1000000000): bigint {
const scaledPercentage = BigInt(Math.round(percentage * 100 * scalingFactor))
const result = (value * scaledPercentage) / (BigInt(100) * BigInt(scalingFactor))
return result
}
@hos
hos / InjectRuntimePublicEnv.ts
Last active October 8, 2024 08:56
Workaround to use runtime variables in the next.js app (App Router), so you can change them after build.
import Script from 'next/script'
// Add this file to some Server Component, in my case I use this in `app/layout.tsx`
// Next.js, will inline all the process.env.SOMETHING variables into the code at build time.
// Which will force us to build the app for each environment we want to deploy to, with the
// only different being few environment variables. Instead, what we want is to get the environment
// dynamically from the runtime, so if we change them in the env and run the app again, it must
// use the new environment variables. To do this, we will inject the environment variables into
// the window object, so we can access them in the runtime.
We can make this file beautiful and searchable if this error is corrected: It looks like row 8 should actually have 9 columns, instead of 6 in line 7.
city 1, city 2 distance, city 2, city 3 distance, city 3, city 4 distance, city 4, city 5 distance, city5
Bronx , 23 , Brooklyn , 11 , Manhattan , 18 , New York , 13 , Queens
Bronx , 23 , Brooklyn , 11 , Manhattan , 13 , Queens , 18 , New York
Bronx , 23 , Brooklyn , 18 , New York , 11 , Manhattan , 13 , Queens
Bronx , 23 , Brooklyn , 18 , New York , 13 , Queens , 11 , Manhattan
Bronx , 23 , Brooklyn , 13 , Queens , 11 , Manhattan , 18 , New York
Bronx , 23 , Brooklyn , 13 , Queens , 18 , New York , 11 , Manhattan
Bronx , 11 , Manhattan , 23 , Brooklyn , 1
@hos
hos / supabase-client.ts
Last active January 2, 2025 18:19
Validate telegram mini app init data in PostgreSQL, can be useful when you want to use supabase client in TMA, pass `initDataRaw` to headers, then in SQL queries get init data (username, user id...)
const supabase = useMemo(() => {
return createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_KEY!,
{
global: {
headers: {
telegram_init_data: initDataRaw || "",
},
},
--[[
=====================================================================
==================== READ THIS BEFORE CONTINUING ====================
=====================================================================
Kickstart.nvim is *not* a distribution.
Kickstart.nvim is a template for your own configuration.
The goal is that you can read every line of code, top-to-bottom, and understand
import { jsonParse } from "@dataplan/json";
import { access, context, lambda, listen } from "grafast";
import { gql, makeExtendSchemaPlugin } from "graphile-utils";
const PackagePlugin = makeExtendSchemaPlugin((build) => {
const { sql } = build;
if (!sql) {
throw new Error("sql not found");
}
import cors from "cors";
import express, { Express, NextFunction } from "express";
import { IncomingMessage, Server, ServerResponse } from "http";
import inspector from "inspector";
import { Duplex } from "stream";
import { isDev, isLocal } from "./config.js";
import * as middleware from "./middleware/index.js";
import { firebaseAuthMiddleware } from "./middleware/installFirebaseAuth.js";
import { makeShutdownActions, ShutdownAction } from "./shutdownActions.js";