Skip to content

Instantly share code, notes, and snippets.

@loburets
loburets / mode.sql
Last active January 20, 2024 13:52
In aggregated query without GROUP BY, expression contains nonaggregated; this is incompatible with sql_mode=only_full_group_by
SET GLOBAL sql_mode = (SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
SET SESSION sql_mode = (SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
SELECT @@sql_mode;
@loburets
loburets / removePhpStorm.sh
Last active June 22, 2022 17:09
remove phpsotrm from osx mac or other utils (КриптоПро CSP)
rm -rf /Applications/PhpStorm.*
rm -rf ~/Library/Preferences/jetbrains.*
rm -rf ~/Library/Logs/JetBrains/PhpStorm*
rm -rf ~/Library/Caches/PhpStorm*
rm -rf ~/Library/Caches/JetBrains/PhpStorm*
rm -rf ~/Library/Application\ Support/PhpStorm*
rm -rf ~/Library/Application\ Support/JetBrains*
rm -rf ~/Library/ApplicationSupport/PhpStorm*
rm -rf ~/Library/ApplicationSupport/JetBrains*
@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 / 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 / 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) {
@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;