Skip to content

Instantly share code, notes, and snippets.

View DragorWW's full-sized avatar

Andreev Sergey DragorWW

View GitHub Profile
function textNodesUnder(el){
var n, a=[], walk=document.createTreeWalker(el,NodeFilter.SHOW_TEXT,null,false);
while(n=walk.nextNode()) a.push(n);
return a;
}
function removeText(text) {
return 'ауоыиэяюёе'.split('').reduce((acc, i) => acc.replace(RegExp(i,'gi'), ''),text)
}
textNodesUnder(document.body).forEach(i => i.replaceWith(removeText(i.wholeText)))
@DragorWW
DragorWW / storybook-config-auto-title.js
Created November 26, 2019 23:28
Storybook: auto title base on file path
/*
Read the https://storybook.js.org/docs/guides/guide-react/
Configure:
1) open ./storybook/config.js
2) remove configure(require.context('../src', true, /\.stories\.js$/), module);
3) replace with the code below
4) change path prepare in to getTitle function
5) remove in story files export default.title
@DragorWW
DragorWW / import-stats.js
Created November 17, 2019 17:29
Get import statistics by webpack
const fs = require('fs');
// run `webpack --profile --json > compilation-stats.json` before this script
const stats = require('./compilation-stats');
fs.writeFileSync(
'import-top.tsv',
stats.modules
.map(i => {
return {
@DragorWW
DragorWW / schema-normalizer.js
Created March 26, 2019 17:37
Flow type frendly normalize js object by schema
// @flow
type ExtractReturnType = <V>(() => V) => V;
type ExtractReturnOptionalType = <V>(() => V) => ?V;
export const schema = {
default<T: string | number | {} | boolean | []>(
fn: mixed => ?T,
defaultValue: T | (() => T)
): mixed => T {
const newFn = (i: mixed): T => {
@DragorWW
DragorWW / react-select_v2.x.x.js
Last active January 29, 2019 08:31
Flow types react-select v2 (incomplete version)
// @flow
import type { ComponentType, Element as ReactElement, ElementRef, Node, Ref } from "react";
declare module 'react-select' {
declare export default React.Component<$Shape<{
/* Aria label (for assistive tech) */
'aria-label'?: string,
/* HTML ID of an element that should be used as the label (for assistive tech) */
'aria-labelledby'?: string,
/* Focus the control when it is mounted */
@DragorWW
DragorWW / size-bar.css
Created January 4, 2018 06:57
Size bar
.size-bar {
background-color: #555b5e;
background-image: linear-gradient(270deg,#eac3d6 1px,transparent 0,transparent),linear-gradient(270deg,hsla(0,0%,87%,.5) 1px,transparent 0,transparent),linear-gradient(270deg,hsla(0,0%,87%,.25) 1px,transparent 0,transparent);
background-position: 0 100%;
background-repeat: repeat-x;
background-size: 100px 75%,10px 50%,5px 25%;
border-radius: .175rem;
display: inline-block;
}
@DragorWW
DragorWW / normalizeValidator.js
Created October 7, 2017 16:15
normalize js validator
const normalizedData = normalizr.normalize(data, article);
console.log(article, data, normalizedData);
const errors = normalizeValidator(normalizedData, article);
console.log(errors);
normalizeValidatorLogger(errors);
function getSchemasByName(schemas) {
let newSchemas = {}
newSchemas[schemas._key] = schemas;
Object.keys(schemas.schema).forEach((schemaName) => {
@DragorWW
DragorWW / game.js
Created June 26, 2017 01:37
game of life
// https://learn.javascript.ru/settimeout-setinterval
// https://learn.javascript.ru/js-animation
(function () {
var cells = [];
for (var i=0; i<64; i++) {
cells[i] = [];
for (var j=0; j<64; j++) {
cells[i][j] = Math.random() >= 0.5;
@DragorWW
DragorWW / git-aliases.md
Created June 15, 2017 17:28 — forked from mwhite/git-aliases.md
The Ultimate Git Alias Setup

The Ultimate Git Alias Setup

If you use git on the command-line, you'll eventually find yourself wanting aliases for your most commonly-used commands. It's incredibly useful to be able to explore your repos with only a few keystrokes that eventually get hardcoded into muscle memory.

Some people don't add aliases because they don't want to have to adjust to not having them on a remote server. Personally, I find that having aliases doesn't mean I that forget the underlying commands, and aliases provide such a massive improvement to my workflow that it would be crazy not to have them.

The simplest way to add an alias for a specific git command is to use a standard bash alias.

# .bashrc
@DragorWW
DragorWW / .gitconfig
Created June 15, 2017 17:27 — forked from pksunkara/config
Sample of git config file (Example .gitconfig)
[user]
name = Pavan Kumar Sunkara
email = pavan.sss1991@gmail.com
[core]
editor = vim
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
excludesfile = ~/.gitignore
[sendemail]
smtpencryption = tls
smtpserver = smtp.gmail.com