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 / 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 };
@SirSerje
SirSerje / hoc.js
Created January 22, 2019 08:09
simple hoc js usage
const highOrderComponent = (WrappedComponent) => {
class HOC extends React.Component {
render() {
return <WrappedComponent/>;
}
}
HOC.displayName = `HOC of ${WrappedComponent.displayName || WrappedComponent.name || 'Component'}`;
return HOC;
};
@SirSerje
SirSerje / withStorage.js
Created January 22, 2019 07:45 — forked from treyhuffine/withStorage.js
A higher-order component to access localStorage
import React from 'react';
const withStorage = (WrappedComponent) => {
class HOC extends React.Component {
state = {
localStorageAvailable: false,
};
componentDidMount() {
this.checkLocalStorageExists();
@SirSerje
SirSerje / docker-kill.txt
Last active March 18, 2021 22:11
Remove all docker's shit
kill all running containers with docker kill $(docker ps -q)
delete all stopped containers with docker rm $(docker ps -a -q)
delete all images with docker rmi $(docker images -q)
@SirSerje
SirSerje / es5.js
Last active September 24, 2018 13:18
'barking dog'
function Animal(name) {
this.name = name
}
Animal.prototype.getName = function() {
return this.name
}
function Dog(name) {
@SirSerje
SirSerje / example.js
Created July 5, 2018 20:58
How to filter array with similar object (small check of deep compare)
function getUniqueObject(nonUniqueArray) {
let result = [];
for (let i = 0; i < nonUniqueArray.length; i++) {
let currentItem = nonUniqueArray[i];
if (isObjectPresent(result, currentItem)) {
console.log('object is similar')
} else {
result.push(currentItem)
}