Skip to content

Instantly share code, notes, and snippets.

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

Serhii Viazkov SirSerje

🏠
Working from home
View GitHub Profile
@SirSerje
SirSerje / memo.js
Created November 10, 2021 16:13
Memo on a budget
const add = (a,b) => a+b;
function memo (fn) {
let args = [];
function result(a,b) {
let hasMemo = args.reduce((acc, i) => {
if(i.a === a && i.b === b) {
return i;
}
@SirSerje
SirSerje / 1.js
Last active October 25, 2021 18:45
2 - Object Oriented Programming
class Counter {
constructor(i = 0) {
// this.counter = 999
this._count = i
}
addOne() {
this._count++
}
@SirSerje
SirSerje / index.ts
Created October 25, 2021 14:33
Typescript example or how you can use OOP on more object oriented languages, like C / Java
console.clear() //just clear console
//any instantinated dog should bark somehow
interface IBark {
bark: (param: any) => string
}
// abstract for class means, class should be extended, not instantinated
abstract class AbstractDog implements IBark {
private weight: number = 15;
@SirSerje
SirSerje / extendArrayFucntionality.js
Last active October 21, 2021 06:16
1 - prototype inheritance
Array.prototype.odd = function () {
return this.filter(i => i%2 === 1)
}
console.log([1,2,3,4,5,6].odd())
@SirSerje
SirSerje / tsconfig.json
Created February 9, 2021 08:10
Cant resolve aliases for Webpack with Typescript for React
{
"compilerOptions": {
"sourceMap": true,
"noImplicitAny": false,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"allowJs": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
@SirSerje
SirSerje / index.js
Created April 10, 2020 13:11
write and read string to mongo
import mongoose from 'mongoose';
import dotenv from 'dotenv';
import { Readable } from 'stream'
let bucket;
const envConfig = dotenv.config();
if (envConfig.error) {
console.log('.env file does not loaded');
throw envConfig.error;
@SirSerje
SirSerje / reactRefs.jsx
Last active February 21, 2020 06:56
react how to refs
import React from 'react';
import './App.css';
import './index.css'
function App() {
return (
<div className="App">
<Parent/>
</div>
);
@SirSerje
SirSerje / hoc.js
Last active February 11, 2020 10:45
Any HOC tweaks
const AddWelcome = (GreetingComponent) => {
class TheNewComponent extends Component {
render() {
return (
<div>
<GreetingComponent {…this.props}/>
<p>Welcome to React!</p>
</div>);
}
}
@SirSerje
SirSerje / composeOverPipe.js
Last active February 11, 2020 10:41
Any kind of FP tweaks
const trace=label=>value=>{
console.log(`${ label }: ${ value }`);
return value;
};
const simpleTrace = value => console.log(value);
const pipe = (...fns) => (args) => fns.reduce((arg, fn) => fn(arg), args);
const compose = (...fns) => (args) => fns.reduce((arg, fn) => fn(arg), args);
const mult = a => b => a*b;
const add = (a) => (b) => a+b;
@SirSerje
SirSerje / index.js
Created June 24, 2019 13:26
react hoc example
//функция, которая формирует тему
const makeStyle = theme => ({
background: theme.mainColor,
})
//Сам ХОК
const WithStyle = styleParam => (WrappedComponent) => {
return class withStyleHOC extends React.Component {
render() {
const myProps = { someProp: 123 };