Skip to content

Instantly share code, notes, and snippets.

@loburets
loburets / chec-sizes-of-directories-terminal-mac.sh
Last active November 24, 2021 07:50
check mac folders size
du -sh *
# OR
sudo du -hs * | sort -h
@loburets
loburets / useElementsSizes.js
Last active September 13, 2021 04:54
React hook to check element sizes and do it in 1 render cycle so in the next one they can be covered by preloader/sekeleton component using the sizes
import { useState, useEffect, useRef } from 'react'
/**
* This hook provides an array of refs with a fixed length.
* Then you can set the refs to any of your elements and on the next render tick, you will now size of such elements.
*
* Example of usage:
*
* const reservedQuantityOfElements = 2
* const [elementsToBeSized, elementsSizes, temporaryShowElementsAsIs] = useElementsSizes(reservedQuantityOfElements)
@loburets
loburets / swicth-ssh-key-for-git.sh
Last active February 28, 2022 12:32
Switch ssh credentials to use another key for git when you use multiple accounts and return back
# to switch:
ssh-add -D && ssh-add ~/.ssh/id_rsa_personal
ssh-add -D && ssh-add ~/.ssh/id_rsa
ssh-add -D && ssh-add ~/.ssh/id_rsa_gmail
# to generate such file:
ssh-keygen -t ed25519 -C "dmitry.loburets@gmail.com" -f ~/.ssh/id_rsa_gmail
ssh-keygen -t ed25519 -C "dima-loburec@yandex.ru" -f ~/.ssh/id_rsa_personal
ssh-keygen -t ed25519 -C "Dmitry L for work" -f ~/.ssh/id_rsa
@loburets
loburets / FormikExamplePage.js
Last active December 20, 2021 11:21
Real-world example of formik page with some complicated (but still pretty common for web forms) UI behaviour. See the first comment for details.
import React, { Component, useEffect, useRef, useState } from 'react'
import { withRouter } from 'next/router'
import { Formik, Form, Field, useFormikContext } from 'formik'
import * as Yup from 'yup'
import Select from 'react-select'
import Moment from 'moment'
import { extendMoment } from 'moment-range'
import { withStyles } from '@material-ui/core/styles'
import { DATE_API_FORMAT } from 'consts/dates'
import Input from '@material-ui/core/Input'
@loburets
loburets / Spreadsheet-to-sql.txt
Created April 30, 2020 09:59
Spreadsheet formula to show list of values for sql query
=CONCATENATE("""",TEXTJOIN(""",""", true,B2:B2387),"""")
@loburets
loburets / remove_git_tags.sh
Created February 4, 2020 12:18
Remove git tags which don't satisfy regexp
#!/bin/bash
TAGS=''
REFS=''
for i in $( git tag -l | grep -E '^[0-9]{2}-[0-9]{2}' );
do
TAGS+=" ${i}"
REFS+=" :${i}"
done
@loburets
loburets / random_image_canvas_cypress.js
Last active December 27, 2019 14:45
How to generate image on canvas and use it in file input in cypress tests without real file storing.
// install package:
import 'cypress-file-upload';
// add the command:
Cypress.Commands.add('makeRandomisedImage', (callback) => {
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
const width = 1200
const height = 1200
canvas.width = width;
@loburets
loburets / example.json
Created October 5, 2019 15:00
example.json
[
{
"_id": "5d98afd8ce81e302aaff42e0",
"index": 0,
"guid": "d43750c8-a6b4-4c3c-a959-c16375443339",
"isActive": true,
"balance": "$3,804.20",
"picture": "http://placehold.it/32x32",
"age": 40,
"eyeColor": "blue",
@loburets
loburets / form-builder-1.php
Created August 25, 2019 09:24
form-builder-1.php
{!! Form::create('ArticleController@update', $article) !!}
{!! Form::input('name', 'Name') !!}
{!! Form::buttonGroup() !!}
{!! Form::buttonLink('Cancel', '/') !!}
{!! Form::reset() !!}
{!! Form::submit() !!}
{!! Form::buttonGroupEnd() !!}
{!! Form::end() !!}
@loburets
loburets / laravel_full_mysql_query.php
Last active April 9, 2021 08:53
To get mysql query from laravel with embed parameters of the binding
<?php
// Use your query before you make get(), first() etc
$query = \Model::where()->join()->etc();
$sql = $query->toSql();
$sql = str_replace('"', '`', $sql);
// just for the raw queries too look normal in the console:
$sql = str_replace("\n", ' ', $sql);
$sql = str_replace("\t", ' ', $sql);
foreach ($query->getBindings() as $binding) {