Skip to content

Instantly share code, notes, and snippets.

View alldayalone's full-sized avatar

Pavel Kaluhin alldayalone

View GitHub Profile
@alldayalone
alldayalone / wet.js
Last active September 17, 2020 09:09
[My WET codebase trying] WET part
import { useMutation, queryCache } from 'react-query';
import { useLocation, useHistory } from 'react-router-dom';
import { UserStatus, api, showSuccessMessage } from 'package';
const SuccessMessageByStatus = {
[UserStatus.BLOCKED]: 'User blocked',
[UserStatus.PROMOTED]: 'User promoted',
[UserStatus.ACTIVE]: 'User activated',
};
@alldayalone
alldayalone / dry.js
Last active September 17, 2020 09:09
[My WET codebase trying] DRY part
import { useMutation, queryCache } from 'react-query';
import { useLocation, useHistory } from 'react-router-dom';
import { UserStatus, api, showSuccessMessage } from 'package';
const SuccessMessageByStatus = {
[UserStatus.BLOCKED]: 'User blocked',
[UserStatus.PROMOTED]: 'User promoted',
[UserStatus.ACTIVE]: 'User activated',
};
1. Two-way referencing in MongoDB with ChangeStream
2. Building SaaS with custom subdomains with Kubernetes
function binarySearch(arr, x, index = 0) {
if (arr.length == 0) {
return -1;
}
let halfN = half(arr.length);
if (arr[halfN] == x) {
return index + halfN;
}
@alldayalone
alldayalone / fuzzySearch.js
Last active January 26, 2020 10:38
Fuzzy Search
function fuzzySearchFirstTry(array, input) {
var halved = [].concat(array);
var output = [].concat(array);
for (var letter of input) {
if (letter === ' ') {
continue;
}
halved = halved
@alldayalone
alldayalone / typeOf.js
Last active January 26, 2020 10:39
JavaScript Types
function typeOf(input) {
return Object
.prototype
.toString
.call(input)
.replace(/\[object (\w+)\]/, '$1')
.toLowerCase();
}
// boolean
@alldayalone
alldayalone / difference.js
Last active January 26, 2020 10:40
Difference
function difference(a, b) {
var result = [];
for (var i = 0; i < a.length; i++) {
if (b.indexOf(a[i]) === -1) {
result.push(a[i]);
}
}
return result;
@alldayalone
alldayalone / mergeSort.js
Last active January 26, 2020 10:40
Merge Sort
function merge(a, b) {
var result = [];
var i = 0;
var j = 0;
while(i + j < a.length + b.length) {
if (j >= b.length || a[i] <= b[j]) {
result.push(a[i]);
i++;
} else {