Skip to content

Instantly share code, notes, and snippets.

View ruvasik's full-sized avatar
👁️‍🗨️
I'm looking for job

Vladimir Alekseev ruvasik

👁️‍🗨️
I'm looking for job
View GitHub Profile
@ruvasik
ruvasik / loadEnv.js
Created May 31, 2024 14:47
Powerful loading .env* files with yarn workspaces
// loadEnv.js
const dotenv = require('dotenv');
const dotenvExpand = require('dotenv-expand').expand;
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
// Функция для загрузки и расширения .env файлов с выводом для отладки
function loadAndExpandEnv(envPaths) {
envPaths.forEach(envPath => {
@ruvasik
ruvasik / log.ts
Created February 6, 2024 09:40
Controlled window.console
export const log = ((c: Console) => {
const log = (...args: unknown[]) => {
if (!import.meta.env.PROD) c.log(...(args as any[]));
};
log.warn = (...args: unknown[]) => {
if (!import.meta.env.PROD) c.warn(...(args as any[]));
};
log.debug = (...args: (boolean | number | string | object)[]) => {
@ruvasik
ruvasik / viewportUnitVariable.tsx
Created December 13, 2023 11:59
Dynamic ViewPort variable in css/sc
import React, {
RefObject,
useCallback,
useEffect,
useRef,
useState,
} from "react";
import { Portal } from "@mui/base";
import { Box } from "@mui/material";
@ruvasik
ruvasik / random-fact.sh
Created November 18, 2023 10:45 — forked from jorpic/random-fact.sh
Get random fact from wikipedia
#!/bin/bash -e
API="http://en.wikipedia.org/w/api.php\
?action=query\
&prop=extracts\
&format=json\
&exsentences=2\
&explaintext=\
&exsectionformat=plain\
&rawcontinue=\
&generator=random\
@ruvasik
ruvasik / RegionMap.tsx
Created April 28, 2023 10:49
SC & TS examples
export interface IMapPoint {
x: number;
y: number;
}
export interface IMapPointItem {
title?: string;
point: IMapPoint;
}
export interface IMapLineItem {
@ruvasik
ruvasik / useOnClickOutside.ts
Created January 17, 2023 14:26
React typed hook useOnClickOutside
import React from "react";
export default function useOnClickOutside(
ref: React.RefObject<HTMLElement>,
handler: (event: TouchEvent | MouseEvent) => void
) {
React.useEffect(() => {
const listener = (event: TouchEvent | MouseEvent) => {
if (!ref.current || ref.current.contains(event.target as HTMLElement)) {
return;
@ruvasik
ruvasik / tool.js
Created January 13, 2023 07:59
NPM utility for run check/format code in folder with eslint/prettier
const execSync = require("child_process").execSync;
const fs = require("fs");
const path = process.argv[3] || 'src/';
const args = Array.prototype.slice.call( process.argv, 4 ).join(' ');
if (!fs.existsSync(path))
throw new Error(`Not found ${path}`);
switch (process.argv[2]) {
@ruvasik
ruvasik / imagesDataUri.ts
Created October 11, 2022 19:53
JS image to/from data URI
import fs from "fs";
export const imageToDataUri = (image: string | Buffer): string | undefined => {
const extTypeMap = {
'png': 'image/png',
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg',
'webp': 'image/webp'
};
@ruvasik
ruvasik / radius.css
Last active May 19, 2022 20:51
Mobile devices corners display radius
/* https://css-tricks.com/snippets/css/media-queries-for-standard-devices/ */
/* ----------- iPhone 5, 5S, 5C and 5SE ----------- */
/* Portrait and Landscape */
@media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2) {
@ruvasik
ruvasik / docker-cleanup-resources.md
Created August 10, 2020 14:13 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm