Skip to content

Instantly share code, notes, and snippets.

@prologic
prologic / LearnGoIn5mins.md
Last active April 17, 2024 18:49
Learn Go in ~5mins
@jaredpalmer
jaredpalmer / EmailInput.jsx
Created November 29, 2017 18:06
Formik async email signup input
import React from 'react';
import debounce from 'utils/debounce';
class EmailInput extends React.Component {
checkEmail = value => {
// only check if the field passes Yup email validation first
if (
!this.props.form.errors[this.props.name].includes(
'invalid' /* or whatever your error message is*/
)
@liuyanghejerry
liuyanghejerry / index.html
Last active April 2, 2024 20:16
Modern index file in 2017
<!DOCTYPE html>
<html prefix="og: http://ogp.me/ns#">
<head>
<!-- content-type, which overrides http equivalent header. Because of charset, this meta should be set at first. -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<!-- Overrides http equivalent header. This tells IE to use the most updated engine. -->
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<!-- Tells crawlers how to crawl this page, and the role of this page. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta -->
<meta name="robots" content="index, follow">
function increment(props, state) {
return {
value: state.value + props.step,
};
}
function decrement(props, state) {
return {
value: state.value - props.step,
};
@acdlite
acdlite / app.js
Last active January 20, 2023 08:23
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
@cecilemuller
cecilemuller / letsencrypt_2020.md
Last active April 15, 2024 02:19
How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SSL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SLL rating)


Virtual hosts

Let's say you want to host domains first.com and second.com.

Create folders for their files:

class Nav extends React.Component {
constructor() {
super();
this.onNav = this.onNav.bind(this);
}
onNav(idx) {
// do something with `this` and `idx`
}
render() {
return (
@zalmoxisus
zalmoxisus / configureStore.dev.js
Last active August 25, 2016 15:14
Open Redux DevTools in a new window
import { createStore, applyMiddleware, compose } from 'redux';
// import { persistState } from 'redux-devtools';
import rootReducer from '../reducers';
import DevTools from '../containers/DevTools';
export default function configureStore(initialState) {
const finalCreateStore = compose(
DevTools.instrument(),
// persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))
)(createStore);
@ohanhi
ohanhi / joy-of-composition.md
Last active February 3, 2021 18:14
The Joy of Composition - Why stateless rendering is pure bliss

This is a proposal for a lightning talk at the Reactive 2015 conference.

NOTE: If you like this, star ⭐ the Gist - the amount of stars decides whether it makes the cut!

The Joy of Composition

Why stateless rendering is pure bliss

React just got stateless components, meaning that they are in essence pure functions for rendering. Pure functions make it dead simple - even fun - to refactor your views

@justinwoo
justinwoo / Counter.js
Last active September 29, 2022 08:29
React 0.14 function components and a fake Elm Architecture written with RxJS subjects (instead of Signal.mailbox). Inspired by Dan's tweet: https://twitter.com/dan_abramov/status/648517117176745984 ((i guess this is pretty ugly so please don't take it super seriously))
import React from 'react';
/**
* Counter.js
*
* exposes:
* init
* update
* view
*/