Skip to content

Instantly share code, notes, and snippets.

View anatooly's full-sized avatar

Anatolii B anatooly

View GitHub Profile
@anatooly
anatooly / es6-iterators.js
Last active August 19, 2019 08:40
es6 iterator cycle
var arr = [1, 2, 3];
var greeting = "hello world";
var m = new Map();
m.set("foo", 42);
m.set({cool: true}, "hello world");
var it = arr[Symbol.iterator]();
it.next();
it.next();
it.next();
@anatooly
anatooly / es5-genarator.js
Last active August 19, 2019 14:58
ES5 generator like ES6 yeald & *foo
function foo() {
function nextState(v) {
switch (state) {
case 0:
state++;
return 42; // yield
case 1:
state++;
x = v; // yield ended
console.log(x);
@anatooly
anatooly / settings.json
Created March 23, 2020 18:47
VS Code italic font
{
"files.autoSave": "onFocusChange",
"explorer.confirmDelete": false,
"editor.fontFamily": "Victor Mono",
"editor.fontWeight": "600",
"editor.fontSize": 15,
"editor.fontLigatures": true,
"editor.lineHeight": 16,
"editor.tokenColorCustomizations": {
"textMateRules": [
@anatooly
anatooly / useLocalStorage.js
Created October 13, 2020 06:19
useLocalStorage
import { useState } from "react";
// использование
function App() {
// аналогично useState, но первым аргументом является ключ значения, хранящегося в локальном хранилище
const [name, setName] = useLocalStorage("name", "Igor");
return (
<div>
<input
@anatooly
anatooly / useEventListener.js
Created October 13, 2020 06:22
useEventListener
import { useState, useRef, useEffect, useCallback } from "react";
// использование
function App() {
// состояние для хранения координат курсора
const [coords, setCoords] = useState({ x: 0, y: 0 });
// обработчик событий обернут в useCallback,
// поэтому ссылка никогда не изменится
const handler = useCallback(
[alias]
co = checkout
br = branch
ci = commit
di = diff
st = status --short --branch
pullhead = "!git pull origin $(git rev-parse --abbrev-ref HEAD)"
@anatooly
anatooly / abort.js
Created November 2, 2020 16:13
Fetch abort
/**
* @docs https://dev.to/ruheni/fetch-is-all-you-need-e8f
*/
const controller = new AbortController();
const signal = controller.signal;
let url = 'https://jsonplaceholder.typicode.com/todos/1'
setTimeout(() => controller.abort(), 100);
@anatooly
anatooly / bemTool.js
Created November 8, 2020 12:13
BEM tool className
export default (block, element, modifier) => {
let prefix, ret;
if (!element) {
prefix = block;
} else {
prefix = block + '__' + element;
}
if (modifier) {
if (modifier instanceof Array) {
@anatooly
anatooly / .zshrc
Last active November 20, 2020 11:48
ZSH project node_modules bin file run
# Adds node_modules/.bin to the PATH
# vi -c ":set nobomb" -c ":wq" ~/.zshrc macOs utf-8 char problem
npm_chpwd_hook() {
if [ -n "${PRENPMPATH+x}" ]; then
PATH=$PRENPMPATH
unset PRENPMPATH
fi
if [ -f package.json ]; then
PRENPMPATH=$PATH
PATH=$(npm bin):$PATH
@anatooly
anatooly / complete-zsh
Created December 1, 2020 13:44
Complete for terminal zsh
#
# Sets completion options.
#
# Authors:
# Robby Russell <[email protected]>
# Sorin Ionescu <[email protected]>
#
# Return if requirements are not found.
if [[ "$TERM" == 'dumb' ]]; then