Skip to content

Instantly share code, notes, and snippets.

View pokorson's full-sized avatar

Mateusz Pokora pokorson

  • Motimate
  • Lodz
View GitHub Profile
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const port = 3000;
app.use(cors());
const jsonParser = bodyParser.json();
const express = require('express')
const bodyParser = require('body-parser')
const uuidv1 = require('uuid/v1');
const cors = require('cors')
const app = express()
const port = 3000
app.use(cors())
@pokorson
pokorson / tasks.js
Created September 30, 2019 13:10
JS tasks
// Zadanie 1
const data1 = [1, 2, 3, 4, 4, 2, 1, 3];
console.log([...new Set(data1)]);
// Zadanie 2
const data2 = [{a: 1, b: 2},{a: 5, b: 8},{a: "aaaa", c: "aaaaa"}];
console.log(data2.map(i => i.a));
@pokorson
pokorson / index.html
Created June 12, 2019 17:40
Stick div to cursor
<html>
<head></head>
<body>
<div></div>
<span id="drag-test"></span>
</body>
<script>
document.addEventListener(
'mousemove',
function(ev) {
@pokorson
pokorson / shallow.js
Created October 5, 2018 11:08
Javascript shallow copying example
// Example of updating record on shallow copied array in Javascript
const arr1 = [{a: 10, b: 15}];
console.log("arr1 before update = ", arr1);
const arr2 = arr1.slice();
console.log("arr2 before update = ", arr2);
arr2[0].b = 15;
@pokorson
pokorson / fix_corrupt_zsh.sh
Created September 17, 2018 19:17
Fix corrupt zsh file
mv .zsh_history .zsh_history_bad
strings .zsh_history_bad > .zsh_history
fc -R .zsh_history
@pokorson
pokorson / components.js
Created February 6, 2018 19:22
Recompose examples
const Buttons = branch(
props => props.loading,
withProps({ label: 'LOADING...', isDisabled: true }),
withProps({ id: 'signIn', label: 'SIGN IN', type: 'submit' })
)(SignInButton);
const Buttons = ({ loading }) =>
loading ? (
<SignInButton label="LOADING..." isDisabled={true} />
) : (
@pokorson
pokorson / applyScopeToSelectors.js
Created December 29, 2017 09:53
Apply namespace for selectors, for multiple levels of re-exporting selectors.
export default function applyScopeToSelectors(selectors, stateKey) {
return Object.keys(selectors).reduce((res, val) => {
if (typeof selectors[val] === 'object') {
return { ...res, [val]: applyScopeToSelectors(selectors[val], stateKey) };
}
return { ...res, [val]: state => selectors[val](state[stateKey]) };
}, {});
}
@pokorson
pokorson / CounterClass.js
Created November 29, 2017 16:25
React vs Recompose unit tests
export default class Counter extends React.Component {
state = {
counter: this.props.counter
};
increment = () => {
this.setState(state => ({
counter: state.counter + 1
}));
};