Skip to content

Instantly share code, notes, and snippets.

@loburets
loburets / useElementsSizes.js
Last active Sep 13, 2021
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
View useElementsSizes.js
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 Apr 11, 2021
Switch ssh credentials to use another key for git when you use multiple accounts and return back
View swicth-ssh-key-for-git.sh
ssh-add -D && ssh-add ~/.ssh/id_rsa_personal
ssh-add -D && ssh-add ~/.ssh/id_rsa
@loburets
loburets / FormikExamplePage.js
Created Oct 7, 2020
Example of formik page
View FormikExamplePage.js
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 Apr 30, 2020
Spreadsheet formula to show list of values for sql query
View Spreadsheet-to-sql.txt
=CONCATENATE("""",TEXTJOIN(""",""", true,B2:B2387),"""")
@loburets
loburets / remove_git_tags.sh
Created Feb 4, 2020
Remove git tags which don't satisfy regexp
View remove_git_tags.sh
#!/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 Dec 27, 2019
How to generate image on canvas and use it in file input in cypress tests without real file storing.
View random_image_canvas_cypress.js
// 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;
View 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",
View 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 Apr 9, 2021
To get mysql query from laravel with embed parameters of the binding
View laravel_full_mysql_query.php
<?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 / ES5_js_inheritance_example.js
Last active Oct 24, 2018
ES5 js multiple inheritance example
View ES5_js_inheritance_example.js
function Machine() {
this._enabled = false;
this.enable = function() {
this._enabled = true;
};
this.disable = function() {
this._enabled = false;
};
}