Skip to content

Instantly share code, notes, and snippets.

@evisotskiy
evisotskiy / es6-notices.js
Last active May 6, 2024 11:03
es6 features I keep forgetting
// создать массив из N элементов, и заполнить его числами от 1 до N:
[...Array(N+1).keys()].slice(1)
// деструктуризация и присваивание в уже существующие переменные:
let isOnline = true;
let isLoggedIn = false;
const data = { isOnline: false, isLoggedIn: true };
({ isOnline, isLoggedIn } = data);
# How to rebase automatically on git pull
https://dev.to/mliakos/don-t-git-pull-use-git-pull-rebase-instead-5b8k
# How to remove untraceable files
git clean -df
@evisotskiy
evisotskiy / wp-notices.php
Last active May 6, 2024 11:03
wp-notices
<?php
/***************
* set attr defer for js-scripts
***************/
add_filter( 'script_loader_tag', 'add_defer_attribute', 10, 2 );
function add_defer_attribute( $tag, $handle ) {
$scripts_to_defer = array( 'google-map', 'google-map-init' );
foreach ( $scripts_to_defer as $defer_script ) {
class Configuration {
private static $instance;
private function __construct() {/* */}
public static function getInstance() {
if (self::$instance === null) {
self::$instance = new Configuration();
}
return self::$instance;
}
public function get($key) {/* */}
`npx npm-check -u` - checks all available updates, shows safe and unsafe updates, and give ability to make updates
OR
https://stackoverflow.com/questions/16525430/npm-check-and-update-package-if-needed
@evisotskiy
evisotskiy / this-in-functions.js
Last active May 6, 2024 11:03
How this applies inside functions
function myFunc() {
console.log(this);
return function () {
console.log(this);
}
}
var user = {
name: 'Vasya'
};
@evisotskiy
evisotskiy / cli-tools.txt
Last active May 6, 2024 11:03
prettier cli command to fix all errors in the project
npx prettier --check '{worker-exercise,worker-solution}/**/!({.gitignore,package.json})*.*'
npx prettier --check 'src/**/!(*{.svg,.pdf,.png})*.*' // for MMS 2.0
npx eslint --fix '{worker-exercise,worker-solution}/**/*.{js,jsx,ts,tsx}' --ignore-pattern node_modules
// negating pattern '!(*test).js' will match all JS files, except those ending in test.js, so foo.js but not foo.test.js
@evisotskiy
evisotskiy / remove all node_modules.md
Last active May 6, 2024 11:03
How to list or delete all node_modules folders inside current directory

List all node_modules found in the current dir, ubuntu/macOS

find . -name "node_modules" -type d -prune -print | xargs du -chs

the same for windows from command prompt (didn't check if it works)

FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" echo %d"

Delete all node_modules found in the current dir, ubuntu/macOS

find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;

the same for windows from command prompt (didn't check if it works)

@tadast
tadast / ruby.yml
Created April 26, 2020 20:29
Example github actions config for Rails with postgres using DATABASE_URL
name: Ruby
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
@evisotskiy
evisotskiy / dynamic-import.js
Last active May 6, 2024 11:01
Right gynamic import
/* for vanilla js */
async function getComponent() {
const element = document.createElement('div');
const { default: _ } = await import(/* webpackChunkName: "lodash" */ 'lodash');
element.innerHTML = _.join(['Hello', 'webpack'], ' ');
return element;
}