Skip to content

Instantly share code, notes, and snippets.

View virtuallyunknown's full-sized avatar

virtuallyunknown

View GitHub Profile
package main
import (
"fmt"
"os"
"time"
"github.com/charmbracelet/bubbles/stopwatch"
tea "github.com/charmbracelet/bubbletea"
)
package main
import (
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
)
type PageNumber int
import axios from 'axios';
class RedditClient {
constructor({ clientId, clientSecret, refreshToken, userAgent }) {
this.accessTokenExpire = new Date(Date.now() - 1000);
this.authToken = Buffer.from(`${clientId}:${clientSecret}`).toString('base64');
this.refreshToken = refreshToken;
this.userAgent = userAgent;
}
@virtuallyunknown
virtuallyunknown / kanel-kysely.js
Last active July 20, 2023 12:00
Kanel + Kysely
import { join, relative, sep } from "node:path";
import { recase } from '@kristiandupont/recase';
import kanel from 'kanel';
import kanelKysely from 'kanel-kysely';
const toCamelCase = recase('snake', 'camel');
const toPascalCase = recase('snake', 'pascal');
export function trimWhitespaceHook(path, lines, instantiatedConfig) {
return lines.filter((line, index, array) => {
@virtuallyunknown
virtuallyunknown / filter.ts
Created June 26, 2023 00:41
TS: Recursively filter out branches of an array of items (by set criterion)
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
const commands = [
{
name: 'foo',
options: [
{ name: 'foo-string', type: 'STRING', autocomplete: true },
{ name: 'foo-integer', type: 'INTEGER' },
],
},
@virtuallyunknown
virtuallyunknown / kysely-runtime.js
Last active April 25, 2023 02:08
Generate runtime types from .ts file generated by kysely-codegen.
import { readFile, writeFile } from "node:fs/promises";
import { normalize } from "node:path";
import { inspect } from "node:util";
import { Project } from "ts-morph";
async function tryReadFile(path) {
try {
return await readFile(path, { encoding: "utf-8" });
} catch {
return null;