Skip to content

Instantly share code, notes, and snippets.

@nikbabchenko
nikbabchenko / closure.js
Created August 17, 2021 07:36
private methods in closure
function getEngine() {
let counterValue = 1;
const changeCounter = (increment = true) => {
return increment ? ++counterValue : --counterValue;
}
return {
increment: () => changeCounter(true),
decrement: () => changeCounter(false),
@nikbabchenko
nikbabchenko / types.js
Last active May 14, 2024 03:17
Преобразование типов
true + false
12 / "6"
"number" + 15 + 3
15 + 3 + "number"
null == ''
null == 0
null == null
undefined == undefined
null == undefined
@nikbabchenko
nikbabchenko / scope.js
Last active May 14, 2024 03:17
Потеря контекста
for (var i = 1; i <= 5; i++) {
setTimeout(function() { console.log(i) }, 1000);
}
@nikbabchenko
nikbabchenko / commodity.js
Created August 15, 2021 15:25
O notation simple coding task
export const COMMODITY = [
{
id: 933,
name: 'General Goods',
description: 'General Goods',
},
{
id: 221,
name: 'Advertising Materials/Books/Magazines',
description: 'Advertising Materials/Books/Magazines',
// disable
sudo mdutil -a -i off
// enable
sudo mdutil -a -i on
@nikbabchenko
nikbabchenko / diff.js
Created April 25, 2021 17:19
diff lodash
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
return _.transform(object, function(result, value, key) {
if (!_.isEqual(value, base[key])) {
@nikbabchenko
nikbabchenko / pods.sh
Created March 4, 2021 07:47
clear pods
pod cache clean --all
pod cache clean 'alamofire'
pod cache clean 'alamofire' --all
@nikbabchenko
nikbabchenko / helloComponent.ts
Created October 16, 2020 17:07
Getters and Setters
export class HelloComponent {
innerFirstName: string;
history = [];
constructor() {}
get fullName() {
console.log("calculate fullName");
return `${this.innerFirstName} ${this.lastName}`;
}
@nikbabchenko
nikbabchenko / column-state.js
Created October 13, 2020 11:06
Persist column state
// if (localStorage.getItem('colums')) {
// const columns = JSON.parse(localStorage.getItem('colums'));
// this.gridOptions.columnApi.setColumnState(columns);
// }
@nikbabchenko
nikbabchenko / Commands.sh
Last active August 2, 2020 13:43
Mobx dart Flutter
# generate mobx boilerplate
flutter packages pub run build_runner build
# generate mobx boilerplate --watch
flutter packages pub run build_runner watch
# delete before generation
flutter packages pub run build_runner watch --delete-conflicting-outputs