Skip to content

Instantly share code, notes, and snippets.

@KrisKnez
KrisKnez / next.config.js
Created March 8, 2022 23:51
Sample of a webpack video loader configuration for Next.JS
const nextConfig = {
webpack: function (config, options) {
config.module.rules.push({
test: /\.mp4$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "static/media",
@KrisKnez
KrisKnez / modal-open-disable-scroll.js
Last active May 5, 2022 18:17
Oxygen Builder Disable Scrolling On Modal Open With Pure JS using MutationObserver
function DisableEvent(e) {
e.preventDefault();
e.stopPropagation();
return false;
}
new MutationObserver(function(e) {
let isMobile = window.innerWidth - document.body.offsetWidth < 10;
if (e[0].target.classList.contains("live")) {
if (isMobile)
@KrisKnez
KrisKnez / custom-image-sizes.php
Created May 5, 2022 18:20
Custom Image Sizes For Wordpress
<?php
add_image_size( 'image-480', 480, 9999 );
add_image_size( 'image-640', 640, 9999 );
add_image_size( 'image-720', 720, 9999 );
add_image_size( 'image-960', 960, 9999 );
add_image_size( 'image-1168', 1168, 9999 );
add_image_size( 'image-1440', 1440, 9999 );
add_image_size( 'image-1920', 1920, 9999 );
@KrisKnez
KrisKnez / nodemon_not_working.txt
Last active June 6, 2022 16:42
FIX: nodemon not working inside docker container
PROBLEM: nodemon does not working inside docker container
sample errors:
[name] exited with code 243
[name] exited with code 127
e.g.
SOLUTION:
install nodemon globally inside the container and do not run it with npx but directly
@KrisKnez
KrisKnez / SomeComponent.tsx
Created December 4, 2022 19:51
Next.JS Link while keeping query / url parameters
import React, { ReactNode } from 'react'
// Next
import Link from 'next/link'
import { useRouter } from 'next/router'
const SomeComponent = () => {
const router = useRouter();
return (
@KrisKnez
KrisKnez / inspectRules.ts
Created February 15, 2023 18:19
A Function That Executes An Array Of Function Call Instructions In Typescript Using A Helper Function That Generates A Branded Function Call Instruction
export type InspectRulesArgs<T extends (...args: any) => any> =
| T[]
| [T, ...Parameters<T>][];
export type InspectRulesResult = "pending" | "approved" | "denied";
declare const brand: unique symbol;
type Branded<T, Brand extends string> = T & {
[brand]: Brand;
}
@KrisKnez
KrisKnez / gist:11c4786e5fc25f7e74d56271f1dcefb5
Created May 31, 2023 23:50
Fix LF / CRLF Error - Insert `␍`eslintprettier/prettier
In the .eslintrc file add the following:
extends: ['prettier'] and plugins: ['prettier']
rules: {'prettier/prettier': ['error', {endOfLine: 'auto'}]}
In .prettierrc remove this:
endOfLine: 'auto'
It works for me.
@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) =>
@KrisKnez
KrisKnez / emEmoji.ts
Last active December 1, 2024 07:21
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 / 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 }
);