Skip to content

Instantly share code, notes, and snippets.

View levchenkod's full-sized avatar
🏄‍♂️

Dmytro Levchenko levchenkod

🏄‍♂️
View GitHub Profile
@levchenkod
levchenkod / Create Social LA Campaign.json
Created July 18, 2025 21:49
Create Social LA Campaign - Crome Recording
{
"title": "Create Social LA Campaign",
"steps": [
{
"type": "setViewport",
"width": 1447,
"height": 742,
"deviceScaleFactor": 1,
"isMobile": false,
"hasTouch": false,
@levchenkod
levchenkod / useResetFormAsync.test.tsx
Created July 18, 2025 17:08
useResetFormAsync - React Hook Form async reset
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { render, act } from '#tests/utils';
import { FormProvider, useForm } from 'react-hook-form';
import { useResetFormAsync } from './useResetFormAsync';
import React, { useEffect } from 'react';
vi.useFakeTimers();
// Mock requestAnimationFrame to work with fake timers
vi.spyOn(global, 'requestAnimationFrame').mockImplementation((cb) => {
@levchenkod
levchenkod / .zshrc
Created April 20, 2025 18:47
`p` - terminal command to add all, commit and push to the current branch
function gitacp() {
if git diff --quiet && git diff --cached --quiet; then
echo "✅ No changes to commit. Exiting."
return 0
fi
if [ -z "$1" ]; then
echo "Usage: gitac \"commit message\""
return 1
fi
//https://www.youtube.com/watch?v=AdmGHwvgaVs&t=414s
const catchErrorTyped = <T, E extends new (message?: string) =>
Error>(
p: Promise<T>,
customErrors?: E[]
):Promise<(undefined| T)[] | [E]> => {
return p.then((data:T) => {
return [undefined, data];
@levchenkod
levchenkod / next-router-mock.test.jsx
Created July 2, 2024 23:07
Mock next/router with next-router-mock lib
import mockRouter from "next-router-mock";
jest.mock("next/router", () => jest.requireActual("next-router-mock"));
describe("Page useRouter hook", () => {
it("renders", () => {
mockRouter.push("/home?with=query");
//...
});
@levchenkod
levchenkod / swr-infinite-mock.test.jsx
Created July 2, 2024 23:05
Mock useSWRInfinite with Jest
import useSWRInfinite from "swr/infinite";
jest.mock("swr/infinite");
describe("Page with SWRInfinite", () => {
it("renders", () => {
(useSWRInfinite as jest.Mock).mockResolvedValue({
data: [{ data: [] }],
error: null,
});
@levchenkod
levchenkod / zoho.getAccessToken.ts
Last active June 10, 2024 00:12
Zoho API create Lead example
/**
* Based on this article
* https://medium.com/geekculture/using-zoho-api-for-leads-in-node-js-ea204e98d41b
*/
/**
* IMPORTANT: pay attention to the super-domain ("com", "eu", etc).
* Must be the same you used for the client registration.
* Otherwise will cause: `{ "error": "invalid_client" }`
*/
@levchenkod
levchenkod / enumToArray.test.ts
Created April 22, 2024 01:47
Safely convert enum to array
import enumToArray from "./enumToArray";
enum Numbers {
One = 'One',
Two = 'Two',
Three = 'Three'
};
enum Empty {}
@levchenkod
levchenkod / nullish_coalescing_replacement.md
Last active March 21, 2024 20:29
RegExp to replace Nullish coalescing assignment with a custom logic. For old Node.js versions

RegExp Query:

([\(\)\._a-zA-Z]*)\s\?\?=\s([\._a-zA-Z\(\)]*)

RegExp Substitue With:

$1 = ($1 === null || $1 === undefined) ? $2 : $1

Example:

@levchenkod
levchenkod / next.config.js
Last active February 12, 2023 18:53
NextJS config to ignore test files inside /page dir
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
pageExtensions: [
'mdx',
'md',
'jsx',
'tsx',
'ts'