Skip to content

Instantly share code, notes, and snippets.

View kitze's full-sized avatar
🚀
Solving problems

Kitze kitze

🚀
Solving problems
View GitHub Profile
@kitze
kitze / use-resizer.ts
Created December 17, 2019 12:13
A hook that gives you resize logic that you can attach to an element
import { useLocalStore } from 'mobx-react-lite';
import { clamp } from 'lodash';
type Props = {
height: number;
maxHeight?: number;
minWidth: number;
minHeight: number;
measureWidth?: boolean;
measureHeight?: boolean;
@kitze
kitze / lemon.page.ts
Last active March 21, 2024 07:59
lemon squeezy helpers
import { NextApiRequest, NextApiResponse } from "next";
import { validateLemonSqueezyHook } from "@/pages/api/lemon/validateLemonSqueezyHook";
import getRawBody from "raw-body";
import { LemonEventType, ResBody } from "@/pages/api/lemon/types";
import { onOrderCreated } from "@/pages/api/lemon/hooks/onOrderCreated";
import { returnError, returnOkay } from "@/pages/api/lemon/utils";
export const config = {
api: {
bodyParser: false,
@kitze
kitze / trim.py
Created April 6, 2023 14:14
trim blank space around images in a folder
from PIL import Image
import os
input_folder = "./public/old"
output_folder = "./public"
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for filename in os.listdir(input_folder):
@kitze
kitze / conditionalwrap.js
Created October 25, 2017 16:54
one-line React component for conditionally wrapping children
import React from 'react';
const ConditionalWrap = ({condition, wrap, children}) => condition ? wrap(children) : children;
const Header = ({shouldLinkToHome}) => (
<div>
<ConditionalWrap
condition={shouldLinkToHome}
wrap={children => <a href="/">{children}</a>}
>
@kitze
kitze / useMagicalMutation.ts
Created April 14, 2021 14:46
magical mutation for blitz
import { useToast } from "@chakra-ui/react";
import { exists } from "app/core/utils/js-utils";
import { QueryFn, useMutation } from "blitz";
import { MutationOptions } from "react-query";
type ShowLoginOnFailFn = (s: any) => boolean;
type CustomOptions = {
errorMessage?: string;
showLoginOnFail?: boolean | ShowLoginOnFailFn;
@kitze
kitze / speaking.mdx
Last active February 1, 2023 08:44
Speaking
@kitze
kitze / rename-next-pages-prefix.js
Created December 8, 2022 10:29
if you want to switch to .page syntax for next.js, this script renames all the files in the /pages folder recursively to append .page before the file extension
const fs = require('fs');
const path = require('path');
// Function to rename files in the given directory
const renameFiles = (dir) => {
// Read the contents of the directory
fs.readdir(dir, (err, files) => {
if (err) {
// If there is an error, log it and return
console.error(err);
@kitze
kitze / codafix.css
Created October 5, 2022 19:04
Coda fix css
.kr-column-group {
width: 100vw !important;
}
[data-coda-ui-id="dialog"] > div {
max-width: 1600px;
width: 90%;
}
@media (max-height: 900px) {
@kitze
kitze / codafix.js
Created October 5, 2022 19:03
coda fix js
(function() {
'use strict';
function onDocReady(fn) {
// see if DOM is already available
if (document.readyState === "complete" || document.readyState === "interactive") {
// call on next available tick
setTimeout(fn, 3000);
} else {
document.addEventListener("DOMContentLoaded", fn);
@kitze
kitze / paddle.ts
Created April 16, 2021 17:39
paddle thingie
//methods
import { BaseSchemaThingie, RawPaddleEvent } from "app/core/paddle/types";
import { filterWebookEvents } from "app/core/paddle/utils/filter-webook-events";
import axios, { AxiosResponse } from "axios";
import { GetPayments } from "./types/getPayments";
import { Schema as GetSubscriptionDetails } from "app/core/paddle/sdk/requests/getSubscriptionDetails/type";
import { GetWebhookEvents, PaddleClientConfig, PaddleRequest } from "./types/types";