Skip to content

Instantly share code, notes, and snippets.

View kidqueb's full-sized avatar

Nick Quebbeman kidqueb

View GitHub Profile
@kidqueb
kidqueb / json-agg.ts
Last active March 13, 2024 15:41
json agg for drizzle
export function jsonAgg<T extends Record<string, AnyColumn>>(select: T) {
const chunks: SQL[] = [];
Object.entries(select).forEach(([key, column], index) => {
if (index > 0) chunks.push(sql`,`);
chunks.push(sql.raw(`'${key}',`), sql`${column}`);
});
return sql<InferColumnsDataTypes<T>[]>`
coalesce(
@kidqueb
kidqueb / db.ts
Last active March 17, 2023 17:38
const fileSchema = z.union([
z.object({
type: z.literal('image'),
width: z.number().int(),
height: z.number().int(),
}),
z.object({
type: z.literal('pdf'),
pages: z.number().int(),
}),
@kidqueb
kidqueb / gen.ts
Last active January 26, 2022 22:58
asd
import { SchemaFormElements, SchemaFormProperties, SchemaFormType } from 'jtd';
import { get, set } from 'lodash';
import { Merge } from 'type-fest';
const RE_TAG = /\{+\s*(.*?)\s*\}+/g;
const RE_THIS = /this.?/;
const RE_WITH = /#with\s+/;
const RE_EACH = /#each\s+/;
const RE_OPTIONAL = /#(if|unless)\s+/;
@kidqueb
kidqueb / Button.styles.ts
Last active December 1, 2021 01:57
React Native light/dark theme styles
export const styles = {
base: StyleSheet.create({
button: { padding: 20 },
}),
light: StyleSheet.create({
button: { background: 'blue', color: 'white' },
}),
dark: StyleSheet.create({
import Link from 'next/link';
import { useRouter } from 'next/router';
import { api } from '@chapterchat/sdk';
import { useAuth } from 'lib/stores/auth_store';
import { Logo } from 'svg';
import { Button } from '../button';
import {
AvatarIcon,
CaretDownIcon,
import { ChangeEvent, useState } from 'react';
type InputEvent = ChangeEvent<HTMLInputElement | HTMLSelectElement>;
type BindValueType = (e: InputEvent) => void;
export type BindInputType<T> = (
name: keyof T
) => {
name: typeof name;
value: T[typeof name];
function createSentenceArray(str) {
const arr = str.split(" ");
const newArr = [];
for (let index = 0; index < arr.length; index++) {
const word = arr[index];
if (DO_YOUR_REGEX_THING) {
// if it is a mention push a span
newArr.push(<span>{word}</span>)
@kidqueb
kidqueb / Example.js
Last active March 31, 2020 01:45
Hu
<!--[if lte IE 8]>
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script>
<![endif]-->
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
hbspt.forms.create({
portalId: "7229407",
formId: "3acc29ec-3985-4f68-afd3-4b1abdd130ec",
cssClass: 'bg-dark',
@kidqueb
kidqueb / gist:4e55494157e6dd2ce10415976ae52772
Last active February 4, 2020 04:41
Twitch bonus collector
setInterval(() => {
const btn = document.querySelector(".community-points-summary button.tw-button--success");
btn && btn.click();
}, 15000)
@kidqueb
kidqueb / useInputHandler.js
Created January 27, 2020 20:54
Simple form management hook
import { useState } from "preact/hooks";
export function useInputHandler(defaultState) {
const [state, setState] = useState(defaultState);
return [
state,
event => setState({ ...state, [event.target.name]: event.target.value }),
newState => setState({ ...state, ...newState })
];