Skip to content

Instantly share code, notes, and snippets.

View anatooly's full-sized avatar

Anatolii B anatooly

View GitHub Profile
@anatooly
anatooly / get-background-image-url.ts
Created May 19, 2025 18:32
get-background-image-url.ts
const assetPrefix = process.env.NEXT_PUBLIC_ASSET_PREFIX || "";
export const ALLOWED_WIDTHS = [16, 32, 48, 64, 96, 128, 256, 384, 640, 750, 828, 1080, 1200, 1920, 2048, 3840] as const;
export type AllowedWidth = (typeof ALLOWED_WIDTHS)[number];
export const getBackgroundImageUrl = (path: string, width: AllowedWidth = 1920, quality = 75) => {
const encodedUrl = encodeURIComponent(path);
return `${assetPrefix}/_next/image?url=${encodedUrl}&w=${width}&q=${quality}`;
};
@anatooly
anatooly / route.ts
Created May 19, 2025 15:06
/api/image/route.ts - next.js
import { NextRequest, NextResponse } from "next/server";
import path from "path";
import fs from "fs/promises";
import sharp from "sharp";
const SUPPORTED_FORMATS = ["avif", "webp", "jpeg", "png"] as const;
type Format = (typeof SUPPORTED_FORMATS)[number];
const PUBLIC_ROOT = path.join(process.cwd(), "public");
const CACHE_ROOT = path.join(process.cwd(), ".next/cache/images");
<Switch
style={{ transform: [{ scaleX: 0.9 }, { scaleY: 0.9 }] }}
onValueChange={handleValueChange}
value={value}
ios_backgroundColor={value ? '#B3BCB4' : '#B6B6B6'}
trackColor={{
false: '#B6B6B6',
true: '#B3BCB4',
}}
thumbColor={value ? palette.green : palette.gray}
@anatooly
anatooly / validate-branch-name
Created October 26, 2022 16:03
validate-branch-name
"postinstall": "husky install",
"validate-branch-name": {
"pattern": "^(feature|release|hotfix)/(KB-[0-9]+)-([a-zA-Z]+)",
"errorMsg": "Invalid branch name, please use name rule like this: feature/KB-123-implementNewLogic"
}
husky
husky-check-email
@anatooly
anatooly / PressableHighlight.js
Created October 17, 2022 07:53
PressableHighlight
export default function PressableHighlight(props) {
return (
<Pressable
android_ripple={{
color: '#676B5F',
}}
style={({ pressed }) => [
Platform.select({
ios: {
backgroundColor: pressed ? 'rgba(0,0,0,0.1)' : 'transparent',
@anatooly
anatooly / ArbitrarySizeViewIos.js
Created October 11, 2022 08:49
ArbitrarySizeViewIos
import React from 'react'
import {View, Platform} from 'react-native'
const ARBITRARY_SIZE = 1000
const ArbitrarySizeViewIos = (props) => {
if (Platform.OS !== 'ios') return null
const backgroundColor = props?.backgroundColor
@anatooly
anatooly / SafeAreaBackground.js
Created October 11, 2022 08:48
SafeAreaBackground.js
import React from 'react'
import {SafeAreaView} from 'react-native-safe-area-context'
const SafeAreaBackground = ({
children = null,
backgroundColorTop = '',
backgroundColorBottom = '',
}) => {
return (
<>
@anatooly
anatooly / pre-commit
Created August 12, 2022 09:40
pre-commit
#!/bin/bash
#
# Pre-commit hooks
# Check branch name
BRANCH_NAME_LENGTH=`git rev-parse --abbrev-ref HEAD | grep -E '^(?!((fix|feature)\/[a-zA-Z0-9\-]+)$).*' | wc -c`
if [ ${BRANCH_NAME_LENGTH} -eq 0 ] ; then
echo -e '\E[37;44m'"\033[1mERROR\033[0m in pre-commit hook: vim .git/hooks/pre-commit"
echo "Branch name should be like feature/lowerUpper09-EXY-134 - brand is two letters"
@anatooly
anatooly / gist:502618ee6b73b9946350ea83b07db084
Created February 17, 2022 14:47
Git push code to dev (origin/master) & customer repo (customer/main)
git remote add customer [email protected]:anatooly/test.git
git co -b main <Initial commit>
git merge --squash master
git commit -m <Commit text>
git push customer
or
rsync -rv --exclude=.git --exclude=node_modules --exclude=.next dev-dir/ customer-dir
manual commit & push from customer-dir
@anatooly
anatooly / addon.contentscript.js
Created October 15, 2021 11:52 — forked from kucheruk/addon.contentscript.js
ATI.su morpheus gist.
//content script = ship, feature component = morpheus.
console.log("Morpheus injected");
const features = new Map();
function messageToMorpheus(msg) {
window.postMessage({ direction: "from-ship", message: msg }, "*");
}
chrome.runtime.onMessage.addListener((msg, _, sendResponse) => {