Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Oleksandr Kovalov okovalov

🏠
Working from home
  • Toronto
View GitHub Profile
@okovalov
okovalov / index.js
Last active Jul 17, 2020
ECMAScript 6 sets: union, intersection, difference
View index.js
// ECMAScript 6 sets: union, intersection, difference
// 1 union
let a = new Set([1,2,3]);
let b = new Set([4,3,2]);
let union = new Set([...a, ...b]); // {1,2,3,4}
// 2 intersection
let a = new Set([1,2,3]);
let b = new Set([4,3,2]);
@okovalov
okovalov / index.js
Last active Jul 13, 2020
How to use cusrtom events
View index.js
// In JavaScript we can create custom events, and the way it works changes in the
// browser and in Node.js.
// In the frontend we use the Event object which is provided by the browser:
const anEvent = new Event('start');
// You can trigger the event using
document.dispatchEvent(anEvent)
@okovalov
okovalov / index.js
Last active Jul 13, 2020
How to create a custom JS Error
View index.js
class OutOfFuelError extends Error {
constructor(message) {
super(message)
this.name = "OutOfFuelError"
}
}
class FlatTireError extends Error {}
try {
@okovalov
okovalov / tab.bash
Created Jul 7, 2020 — forked from bobthecow/tab.bash
Open new Terminal tabs from the command line
View tab.bash
#!/bin/bash
#
# Open new Terminal tabs from the command line
#
# Author: Justin Hileman (http://justinhileman.com)
#
# Installation:
# Add the following function to your `.bashrc` or `.bash_profile`,
# or save it somewhere (e.g. `~/.tab.bash`) and source it in `.bashrc`
#
View Array_shuffle.js
const shuffle = arr => arr.sort(() => Math.random() - 0.5)
const data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
console.log('Data 1', data)
console.log('Data 2', shuffle(data))
console.log('Data 3', shuffle(data))
console.log('Data 4', shuffle(data))
console.log('Data 5', shuffle(data))
View playground.json
{
"scripts": [],
"showConsole": true,
"scriptType": "module"
}
View js_Logging_objects.js
//
// Logging objects
//
// Don't use
console.log(obj);
//use
console.log(JSON.parse(JSON.stringify(obj)));
View eslint_prettier_vscode_js_ts_jsx_tsx.txt
Set UP Eslint + Prettier in VSCode
// Docs (JS only) - https://github.com/wesbos/eslint-config-wesbos
// Anoter docs (TS and JSX) - https://github.com/sarpik/eslint-config-sarpik
https://gist.github.com/okovalov/aaf8bc5d05b59caa98eeec5e89612bd3
1. Create react app
npx create-react-app react-ts --template typescript
@okovalov
okovalov / axios_send_auth_token.js
Created Jan 22, 2020
Learn how to send the authorization header using Axios (from https://flaviocopes.com/axios-send-authorization-header/)
View axios_send_auth_token.js
const username = ''
const password = ''
const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')
const url = 'https://...'
axios.post(url, {
headers: {
'Authorization': `Basic ${token}`
@okovalov
okovalov / .eslintrc.js
Last active Jan 22, 2020
temporary fork from eslint-config-sarpik
View .eslintrc.js
#!/usr/bin/env node
// .eslintrc.js
/**
* The ESLint + Prettier config from Kipras <kipras@kipras.org> (https://kipras.org)
*
* Supports TypeScript!
* (
* https://javascriptplayground.com/typescript-eslint/
* & https://www.robertcooper.me/using-eslint-and-prettier-in-a-typescript-project
You can’t perform that action at this time.