Skip to content

Instantly share code, notes, and snippets.

@10xjs
10xjs / cursor-query.ts
Created October 28, 2025 20:29
Kysely cursor query
import { Selection, SelectQueryBuilder, StringReference } from "kysely";
type ExtractSelection<DB, TE extends keyof DB & string, SE> = Selection<
DB,
TE,
SE
>[keyof Selection<DB, TE, SE>];
type ExtractTableName<
DB,
@10xjs
10xjs / index.ts
Last active April 22, 2024 18:35
Service Worker Router
type Prettify<T> = { [K in keyof T]: T[K] } & {};
type RemoveTail<
S extends string,
Tail extends string
> = S extends `${infer P}${Tail}` ? P : S;
type GetPathParam<S extends string> = RemoveTail<
RemoveTail<S, `.${string}`>,
`/${string}`
@10xjs
10xjs / drizzle-kit+0.19.13.patch
Last active October 30, 2023 01:30
Drizzle Supabase patch
diff --git a/node_modules/drizzle-kit/index.cjs b/node_modules/drizzle-kit/index.cjs
index d608580..e4096af 100755
--- a/node_modules/drizzle-kit/index.cjs
+++ b/node_modules/drizzle-kit/index.cjs
@@ -4862,7 +4862,8 @@ var init_pgSchema = __esm({
}).strict();
enumSchema = objectType({
name: stringType(),
- values: recordType(stringType(), stringType())
+ values: recordType(stringType(), stringType()),
@10xjs
10xjs / machine.js
Created October 21, 2023 03:11
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine({
id: 'churnDeflection',
initial: 'startDialog',
context: {
feedback: '',
},
states: {
startDialog: {
on: {
LIFE_CHANGE: { target: 'pauseSubDialog', actions: 'sendLifeChangeEvent' },
@10xjs
10xjs / semver.pro
Last active October 16, 2020 21:32
Prolog Semver Parser
% True if Atom contains only numeric characters.
%
% numeric('10'). true
% numeric('x'). false
numeric(Atom) :-
atom(Atom),
atom_chars(Atom, Chars),
catch(number_chars(_, Chars), _, false).
semver_tag_char('-').
@10xjs
10xjs / spyPromise.test.ts
Last active April 16, 2020 15:57
Solution for testing the "rejection handled" status of a promise instance
function spyPromise() {
const _then = Promise.prototype.then;
const _catch = Promise.prototype.catch;
const handled = new WeakSet<Promise<any>>();
// eslint-disable-next-line no-extend-native
Promise.prototype.then = function thenSpy(this: any, ...args: any) {
if (args.length > 1) {
handled.add(this);
@10xjs
10xjs / environment.sh
Last active November 20, 2019 22:13
Get name of PR target branch in CI
# Install hub cli tool from https://github.com/github/hub as it is not available as a debian package.
# We use hub to fetch additional repo information from github (in this case the target branch ref of a PR).
curl -L https://github.com/github/hub/releases/download/v2.13.0/hub-linux-386-2.13.0.tgz | tar -xz
mv hub-linux-386-2.13.0/bin/* /usr/local/bin
rm -rf hub-linux-386-2.13.0
// Type declarations for https://github.com/metalabdesign/pages-webpack-plugin
/// <reference types="webpack" />
declare module 'pages-webpack-plugin' {
import webpack from 'webpack';
interface Result {
markup: string;
redirect?: string;
status?: number;
import ts from 'typescript';
import sources from 'polyfill-library/lib/sources';
import * as tsMorph from 'ts-morph';
interface Match {
kind?: ts.SyntaxKind;
operatorTokenKind?: ts.SyntaxKind;
typeSymbolName?: string;
symbolName?: string;
expression?: Match;
@10xjs
10xjs / classFromFactory.ts
Last active July 2, 2019 04:11
classFromFactory
function proxyAll<T extends object>(source: any): ProxyHandler<T> {
return {
apply(target, thisArg, argumentsList) {
return Reflect.apply(source, thisArg, argumentsList);
},
construct(target, argumentsList, newTarget) {
return Reflect.construct(source, argumentsList, newTarget);
},
defineProperty(target, property, descriptor) {
return Reflect.defineProperty(source, property, descriptor);