Skip to content

Instantly share code, notes, and snippets.

Avatar

Mateusz Pokora pokorson

  • Motimate
  • Lodz
View GitHub Profile
View server.js
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();
View server.js
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())
View tasks.js
// 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 Jun 12, 2019
Stick div to cursor
View index.html
<html>
<head></head>
<body>
<div></div>
<span id="drag-test"></span>
</body>
<script>
document.addEventListener(
'mousemove',
function(ev) {
@pokorson
pokorson / shallow.js
Created Oct 5, 2018
Javascript shallow copying example
View shallow.js
// 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 Sep 17, 2018
Fix corrupt zsh file
View fix_corrupt_zsh.sh
mv .zsh_history .zsh_history_bad
strings .zsh_history_bad > .zsh_history
fc -R .zsh_history
@pokorson
pokorson / components.js
Created Feb 6, 2018
Recompose examples
View components.js
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 Dec 29, 2017
Apply namespace for selectors, for multiple levels of re-exporting selectors.
View applyScopeToSelectors.js
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 Nov 29, 2017
React vs Recompose unit tests
View CounterClass.js
export default class Counter extends React.Component {
state = {
counter: this.props.counter
};
increment = () => {
this.setState(state => ({
counter: state.counter + 1
}));
};