Skip to content

Instantly share code, notes, and snippets.

View okovalov's full-sized avatar
🏠
Working from home

Oleksandr Kovalov okovalov

🏠
Working from home
View GitHub Profile
<div
dangerouslySetInnerHTML={{
__html: props.house.description
}}></div>
const data = {
foo: 'bar',
falsyValue: false
}
// this one is good
const containerOne = data.foo || 'fallback'
console.log('container one =', containerOne); // container one = bar
// non existed - still "good"

You can disable one or more specific ESLint rules for a whole file by adding on a few lines:

/* eslint-disable no-debugger, no-console */
console.log('test')

or you can just do so in a block, re-enabling it afterwards:

Read:
Most of them are based on streams, like csv-parser or node-csv.
Those are great to deal with CSV in a production system.
I like to keep things simple when I don’t have performance in mind. For example, for a one-time parsing of CSV that I had to do to consolidate my backend systems.
To do so, I used neat-csv, a package that exposes the csv-parser functionality to a simple async/await interface.
Install it using npm install neat-csv and require it in your app:
How to make a page editable in the browser
There is a special and pretty secret mode in browsers, called design mode.
When you set a page into design mode, you can edit the content of the page directly inside the browser page, which is very handy to test some prototype or check out how a new headline would look, for example.
How do you enable it? Open the DevTools console, and type:
document.designMode = 'on'
// An example of recursive flattering of a given data (potentially multidimensional)
// 1.
// concat all the arrays of a given array and return a new array with a result
const concat = arr => [].concat(...arr)
// recursively flattern a given data into a new array (ES6)
const flattern = el => Array.isArray(el) ? concat(el.map(flattern)) : Array.of(el)
/**
* Checks if dates are on the same day
*
* @param {Object} first First date to comapre
* @param {Object} second Second date to compare
*/
const datesAreOnSameDay = (first, second) =>
first.getFullYear() === second.getFullYear() &&
first.getMonth() === second.getMonth() &&
first.getDate() === second.getDate()
@okovalov
okovalov / delete_git_submodule.md
Created October 22, 2019 17:30 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule

JavaScript Private Class Fields

taken from https://flaviocopes.com/javascript-private-class-fields/

Introduction and code samples on using private class fields in JavaScript.

Before the introduction of private class fields, we could not really enforce private properties on a class. We used conventions instead, maybe using _ as an hint that the field is private, like this:

class Counter {
const factorial = n => n < 0 ? 'n must be > 0' : n < 2 ? 1 : n * factorial(n - 1)
for (let i = -2; i <= 10 ; i++ ) {
console.time(`Time for ${i}`);
console.log(`factorial(${i}) = ${factorial(i)}`)
console.timeEnd(`Time for ${i}`)
}
console.log('-----')