Skip to content

Instantly share code, notes, and snippets.

View pokorson's full-sized avatar

Mateusz Pokora pokorson

  • Motimate
  • Lodz
View GitHub Profile
@pokorson
pokorson / clear_node_modules.sh
Created November 15, 2017 15:52
Clear node_modules recursively
find . -name "nodemodules" -type d -prune -exec rm -rf '{}' +
@pokorson
pokorson / server.js
Last active November 8, 2017 18:29
Simple read/create server with in-memory storage for nodeschool React workshop
const koa = require('koa');
const cors = require('kcors');
const uuid = require('uuid/v1');
const bodyParser = require('koa-bodyparser');
const app = new koa();
let tweets = {};
app.use(cors());
@pokorson
pokorson / Enhance.js
Created September 8, 2017 12:58 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@pokorson
pokorson / greeting.js
Created August 23, 2017 10:25
currying
const greet = (greeting, name) => {
console.log(`${greeting} ${name}`);
};
greet("hello", "Adam");
greet("hello", "Mateusz");
greet("hi", "Mateusz");
greet("hi", "Adam");
const createGreeting = greeting => {
@pokorson
pokorson / home.js
Created August 22, 2017 12:37
Stateless vs Statefull components
import React from "react";
const StatelessFunctionalComponent = ({ title }) => {
console.log("StatelessFunctionalComponent");
return (
<div>
hello from stateless functional component {title}
</div>
);
};
@pokorson
pokorson / state.js
Created August 22, 2017 12:13
Normalized state shape example
const posts = [
{title: 'title 1', id: 1231},
{title: 'title 2', id: 1232},
{title: 'title 3', id: 1233},
{title: 'title 4', id: 1234},
{title: 'title 5', id: 1235},
{title: 'title 6', id: 1236},
{title: 'title 7', id: 1237},
{title: 'title 8', id: 1238},
{title: 'title 9', id: 1239},
class ParentComponent extends React.Component {
handleChange(val) {
this.setState({val: val})
}
render() {
<Select onChange={handleChange} />
}
}
class Select extends React.Component {
@pokorson
pokorson / sample.js
Last active June 30, 2017 10:39
Sample data for workshops
var markers = [
{
score: 9,
count: 145,
homeTeam: "Lawrence Library",
awayTeam: "LUGip",
markerImage: "images/red.png",
information: "Linux users group meets second Wednesday of each month.",
fixture: "Wednesday 7pm"
},
@pokorson
pokorson / list.js
Last active January 16, 2018 09:53
List stateless with recompose
import React from "react";
import { pure, withReducer, compose, withHandlers, mapProps } from "recompose";
import R from "ramda";
import { createReducer } from "./utils";
const ListItem = pure(({ text }) => <li>{text}</li>);
const renderItems = R.map(t => <ListItem key={t} text={t} />);
const ListComponent = ({ todos, name, updateName, addTodo }) =>
<div>
@pokorson
pokorson / list.js
Created June 18, 2017 20:16
list class component
import React from "react";
class ListItem extends React.PureComponent {
render() {
return <li>{this.props.children}</li>;
}
}
class List extends React.PureComponent {
constructor(props) {