Skip to content

Instantly share code, notes, and snippets.

View KrisKnez's full-sized avatar

Kristijan KrisKnez

View GitHub Profile
@KrisKnez
KrisKnez / nest.js vercel serverless function
Created June 2, 2024 11:10
Deploy NEST.JS to Vercel Serverless Functions
// vercel.json
{
"version": 2,
"builds": [
{
"src": "package.json",
"use": "@vercel/static-build",
"config": {
"distDir": "public"
@KrisKnez
KrisKnez / IPrismaStringFilter.ts
Created March 27, 2024 23:35
IPrismaStringFilter.ts
import { Prisma } from '@prisma/client';
type IPrismaStringFilter<
Prefix extends string,
Delimiter extends string = '_',
Operations extends keyof Prisma.StringFilter = keyof Prisma.StringFilter,
> = {
[K in `${Prefix}${Delimiter}${keyof Pick<
Prisma.StringFilter,
Extract<'equals' | 'contains' | 'startsWith' | 'endsWith', Operations>
@KrisKnez
KrisKnez / IPrismaIntFilter.ts
Created March 27, 2024 23:34
IPrismaIntFilter.ts
import { Prisma } from '@prisma/client';
type IPrismaIntFilter<
Prefix extends string,
Delimiter extends string = '_',
Operations extends keyof Prisma.IntFilter = keyof Prisma.IntFilter,
> = {
[K in `${Prefix}${Delimiter}${keyof Pick<
Prisma.IntFilter,
Extract<'equals' | 'gt' | 'gte' | 'lt' | 'lte' | 'not', Operations>
@KrisKnez
KrisKnez / IPrismaDateTimeFilter.ts
Last active March 27, 2024 23:34
IPrismaDateTimeFilter.ts
import { Prisma } from '@prisma/client';
type IPrismaDateTimeFilter<
Prefix extends string,
Delimiter extends string = '_',
Operations extends keyof Prisma.DateTimeFilter = keyof Prisma.DateTimeFilter,
> = {
[K in `${Prefix}${Delimiter}${keyof Pick<
Prisma.IntFilter,
Extract<'equals' | 'gt' | 'gte' | 'lt' | 'lte' | 'not', Operations>
@KrisKnez
KrisKnez / order-by-note.dto.ts
Created February 24, 2024 18:49
Order By Dto For Notes
import { ApiProperty } from '@nestjs/swagger';
import { IsEnum, IsOptional } from 'class-validator';
import { Prisma } from '@prisma/client';
const orderByKeys = [
'id',
'title',
'content',
'createdAt',
@KrisKnez
KrisKnez / env.ts
Created July 29, 2023 01:45
Next.JS env with envalid
import { cleanEnv, url } from "envalid";
// We have to do this because of how Next.JS handles process.env
const processEnv = {
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL,
};
const env = cleanEnv(processEnv, {
NEXT_PUBLIC_API_URL: url(),
});
@KrisKnez
KrisKnez / gist:af2233d1d6064ff07ab698a969fd9195
Created June 15, 2023 20:38
React Typescript Hight Order Component (HOC) inherit Compound Components
If you have a React component with compount components e.g. List, List.Item using HOC will remove compound components.
For the HOC to inherit compound components you need to do it manually.
Use a library like: https://www.npmjs.com/package/hoist-non-react-statics
@KrisKnez
KrisKnez / example.ts
Created June 9, 2023 01:19
reactjs-social-login: window is not defined
// This problem occurs when using reactjs-social-login with a SSR metaframework.
// The solution below is for Next.JS. Your framework may do dynamic imports differently.
const LoginSocialInstagram = dynamic(
() => import('reactjs-social-login').then((lib) => lib.LoginSocialInstagram),
{ ssr: false }
);
@KrisKnez
KrisKnez / emEmoji.ts
Last active August 20, 2024 12:55
em-emoji props
/*
This is the solution to the following error:
Property 'em-emoji' does not exist on type 'JSX.IntrinsicElements'.ts(2339)
*/
// Define em-emoji web component inside React
// https://github.com/missive/emoji-mart#-emoji-component
interface EmEmojiProps {
id?: string
shortcodes?: string
@KrisKnez
KrisKnez / emojiUtils.ts
Last active June 3, 2023 22:37
JS Emoji utilities
// https://ihateregex.io/expr/emoji/
export const emojiRegExpString =
'(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])'
export const emojiToUnified = (emoji: string) =>
[...emoji].map((e) => e.codePointAt(0)?.toString(16)).join('-')
export const unifiedRegExpString = '\b([da-fA-F]{4,5}|[da-fA-F]{6}|[da-fA-F]{8})\b'
export const unifiedToEmoji = (unified: string) =>