Skip to content

Instantly share code, notes, and snippets.

View sanusart's full-sized avatar

Sasha Khamkov sanusart

View GitHub Profile
@sanusart
sanusart / Table.js
Created July 18, 2020 14:31
React [{}] to table #reactjs
const Table = ({data }) => {
if(data.length === 0) return null;
const rows = Object.keys(data[1]);
return (
<table>
<thead>
<tr>
{rows.map(key => (
<th>{key}</th>
@sanusart
sanusart / meta-middlware.js
Last active July 17, 2020 08:55
Redux meta-middlware to add some meta to every action #redux
import { PACKAGE_NAME } from 'src/constants';
const metaMiddleware = ({ getState }) => next => (action) => {
const store = getState();
const user = store[PACKAGE_NAME].user;
const transport = store[PACKAGE_NAME].transport;
next({
...action,
meta: {
@sanusart
sanusart / useListIterate.js
Last active March 7, 2020 09:13
useListIterate hook - iterates over array of items with predefined timing #react #hooks
import React, { useState, useEffect } from 'react';
export default function useListIterate(items, interval = 3000) {
const [item, setItem] = useState(items[0]);
useEffect(() => {
let index = 0;
const timer = setInterval(() => {
setItem(items[index]);
@sanusart
sanusart / git-files-changes.sh
Created December 9, 2019 19:42
Git match changes in commit #bash #shell
#!/usr/bin/env bash
set -e
# Usage:
#
# bash ./scripts/git-files COMMIT_HASH
#
# Usage in script:
#
@sanusart
sanusart / Portal.jsx
Created October 25, 2019 20:52
React portal component #reactjs #react #portal #hooks
import React, { useEffect } from 'react';
import ReactDOM from 'react-dom';
const portalTarget = document.getElementById('portal');
const Portal = ({ children }) => {
const element = document.createElement('div');
useEffect(() => {
portalTarget.appendChild(element);
@sanusart
sanusart / git-files-match.sh
Last active December 8, 2019 22:29
Check if file with certain extension exists in a commit #nodejs #git
#!/bin/bash
# Usage:
# ./scripts/git-files d304b82
#
# Or in script:
#
# if [ `sh ./scripts/git-files d304b82` -gt 0 ];
# then
# echo "matches";
@sanusart
sanusart / color.js
Last active October 8, 2019 19:58
Light or dark hex color #color #hex
export const lightOrDark = (color, ratio = 155) => {
const hex = color.replace('#', '');
const red = parseInt(hex.substr(0, 2), 16);
const green = parseInt(hex.substr(2, 2), 16);
const blue = parseInt(hex.substr(4, 2), 16);
const brightness = (red * 299 + green * 587 + blue * 114) / 1000;
return brightness > ratio ? 'light' : 'dark';
};
@sanusart
sanusart / create_training_data.py
Last active August 29, 2019 20:44
Create training data #spacy #nlp
import spacy
from spacy.matcher import Matcher
from spacy.lang.en import English
nlp = English()
matcher = Matcher(nlp.vocab)
# create some patterns and add to matcher
pattern1 = [{"LOWER": "iphone"}, {"LOWER": "x"}]
pattern2 = [{"LOWER": "iphone"}, {"IS_DIGIT": True, "OP": "?"}]
@sanusart
sanusart / 0-readme.md
Last active November 9, 2022 10:45
Use custom icons in Antd v3 #antd #ant-design #icons #webpack

Ant design v3.9.0 custom svg icons and icons overrides

Why?

  • If you need to use material icons in your project for example.
  • If you need to add cusom icons

Preparations

File examples bellow

@sanusart
sanusart / demojs
Last active April 18, 2019 10:21
faker
import faker from 'faker';
export const dataStreamEntities = {
data: [
{
id: 6248,
name: 'Data Stream',
enabled: true,
sourceDisplayName: 'Google Analytics',
lastRunStatus: false,