Skip to content

Instantly share code, notes, and snippets.

@gthrm
gthrm / getFilterString.js
Created December 4, 2019 09:37
Что-то странное
getFilterString = (chips = []) => {
const filterArray = chips.filter((item) => item.selected).map((item) => item.title);
let filter = '';
filterArray.forEach((item, index) => {
filter += `${index === 0 ? '{' : ''}"tags":"${item}"${index === filterArray.length - 1 ? '}' : ','}`;
});
return filter;
}
@gthrm
gthrm / checkInDayInterval.js
Created December 12, 2019 09:55
checkInDayInterval
export const checkInDayInterval = (dateFrom, dateTo, date = new Date()) => moment(date).isSame(dateFrom, 'day') || moment(date).isSame(dateTo, 'day');
@gthrm
gthrm / asyncForEach.js
Created January 9, 2020 20:30
asyncForEach function
const waitFor = (ms) => new Promise(r => setTimeout(r, ms));
const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
};
};
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
@gthrm
gthrm / redux-ducks-snippet-to-vscode.json
Created January 20, 2020 10:37
redux-ducks-snippet-to-vscode
{
"redux-ducks": {
"prefix": "rds",
"body": [
"import {",
" put,",
" take,",
" select,",
" call,",
" all",
@gthrm
gthrm / react-functional-component-snippet-to-vscode.json
Last active April 25, 2022 11:06
react-functional-component-snippet
{
"react-functional-component": {
"prefix": "rfc",
"body": [
"import React from 'react';",
"",
"function ${TM_FILENAME_BASE}({ ${2:propName} }) {",
" return (",
" <></>",
" );",
@gthrm
gthrm / react-class-component-snippet-to-vscode.json
Last active April 25, 2022 11:10
react-class-component-snippet
{
"react-class-component": {
"prefix": "rcc",
"body": [
"import React, { Component } from 'react';",
"",
"class ${TM_FILENAME_BASE} extends Component {",
" render() {",
" const {",
" ${2:propsName}",
@gthrm
gthrm / reset.css
Created January 28, 2020 09:45
reset.css
/* Указываем box sizing */
*,
*::before,
*::after {
box-sizing: border-box;
}
/* Убираем внутренние отступы */
ul[class],
ol[class] {
@gthrm
gthrm / removeFalsy.js
Last active February 9, 2020 18:39
Удаляет ложные значения из массива
function removeFalsy(array = []) {
return array.filter(item => item)
}
console.log('====================================')
console.log(removeFalsy([null, undefined, false, 0, NaN, 1, 'a', true]))
console.log('====================================')
// ====================================
// [1, "a", true]
@gthrm
gthrm / JSONUtils.js
Created March 29, 2020 15:30
Utils to JSON
import fs from 'fs';
import path from 'path';
/**
* Чтение JSON
* @param {string} filepath - путь к файлу JSON
* @return {object} - весь JSON
*/
export function getJSON(filepath = path.join(__dirname, '../../base', 'topics.json')) {
return JSON.parse(fs.readFileSync(filepath));
@gthrm
gthrm / expoImagePicker.js
Last active March 31, 2020 09:24
Получение фото с камеры/ библиотеки на react native (expo)
import React from 'react';
import { Alert } from 'react-native';
import * as ImagePicker from 'expo-image-picker';
import * as Permissions from 'expo-permissions';
import * as ImageManipulator from 'expo-image-manipulator';
export default class ImagePickerClass {
// хэндлер на onPress
pickPhoto = () => {