Skip to content

Instantly share code, notes, and snippets.

View dumpsayamrat's full-sized avatar
:octocat:
be kind

Sayamrat dumpsayamrat

:octocat:
be kind
View GitHub Profile
@dumpsayamrat
dumpsayamrat / server.js
Created May 31, 2018 16:37
HTTP/2 (server.js)
'use strict'
const http2 = require('http2')
const fs = require('fs')
const path = require('path')
const helper = require('./helper')
const { HTTP2_HEADER_PATH } = http2.constants
const PUBLIC_PATH = path.join(__dirname, '../public')
const SSL_PATH = path.join(__dirname, '../ssl')
@dumpsayamrat
dumpsayamrat / index.html
Created May 31, 2018 15:04
HTTP/2 Server push (index.html)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello HTTP/2</title>
<link rel="stylesheet" href="/app.css" media="all">
</head>
<body>
<h1>Hello HTTP/2</h1>
<script src="app.js"/></script>
import React from 'react';
import { compose, withState, mapProps } from 'recompose';
const FooComponent = (props) => (
<div>
<h1>
Clicks: { props.count }
</h1>
<button onClick={props.incrementCount}>+</button>
<button onClick={props.decrementCount}>-</button>
import React from 'react';
const mapProps = mapFn => BaseComponent =>
(props) => (
<BaseComponent
{...mapFn(props)}
/>
);
export default mapProps;
import React from 'react';
import withState from './withState';
import mapProps from './mapProps';
const FooComponent = (props) => (
<div>
<h1>
Clicks: { props.count }
</h1>
<button onClick={props.incrementCount}>+</button>
import React from 'react';
import withState from './withState';
const FooComponent = (props) => (
<div>
<h1>
Clicks: { props.count }
</h1>
<button onClick={() => props.updateCount((count) => count + 1)}>+</button>
<hr />
import React from 'react';
const withState = (stateName, stateUpdateName, initialValue) => BaseComponent =>
class extends React.Component {
constructor(props) {
super(props);
this.state = {
value: initialValue,
};
}
import React from 'react';
import withState from './withState';
const FooComponent = (props) => (
<div>
<h1>
Clicks: { props.count }
</h1>
<button onClick={() => props.updateCount((count) => count + 1)}>+</button>
<hr />
class NoHoC extends React.Component {
constructor(props) {
super(props);
this.state = {
count: 0,
text: '',
};
this.incrementCount = this.incrementCount.bind(this);
this.onTextChange = this.onTextChange.bind(this);
}
const removeSpecialChar = word => word.replace(/[^a-zA-Z0-9]/g, '');
const split = splitOn => str => str.split(splitOn);
const toLowerCase = word => word.toLowerCase();
const join = str => arr => arr.join(str);
const map = fn => arr => arr.map(fn);
const compose = (...fns) => x => fns.reduceRight((v, f) => f(v), x);
// without compose
const toSlug = input => join('-')(
map(toLowerCase)(