Skip to content

Instantly share code, notes, and snippets.

@mhuggins
mhuggins / app.js
Last active October 25, 2019 10:10
Higher-order component for rendering server-side status codes with react-router v4
import express from "express";
import { renderToString } from "react-dom/server";
import { StaticRouter } from "react-router-dom";
import routes from "./routes";
const app = express();
app.use((req, res) => {
const context = {};
@jslatts
jslatts / app.js
Last active December 8, 2019 22:19
Utility to bind selectors to a slice of state. Helpful for keeping things DRY when colocating selectors and reducers
// Example of usage
import { selectors } from './rootReducer';
import { selectors } from '../../reducers/rootReducer';
const mapStateToProps = (state: State, ownProps: any) => ({
theseObjects: selectors.getTheseObjects(state),
thoseObjects: selectors.getThoseObjects(state),
showSomethinginUi: selectors.getSomethingFromUiSelectors(state),
@moodysalem
moodysalem / render-text.jsx
Created November 11, 2016 19:18
Render React component to text
import { render, unmountComponentAtNode } from 'react-dom';
export function renderText(component) {
const _el = document.createElement('div');
document.body.appendChild(_el);
render(component, _el);
const text = _el.innerText;
unmountComponentAtNode(_el);
document.body.removeChild(_el);
return text;
@PieterScheffers
PieterScheffers / mysql_get_last_updated_id.sql
Created June 21, 2016 10:56
MySQL - Get id of updated rows
# http://stackoverflow.com/questions/1388025/how-to-get-id-of-the-last-updated-row-in-mysql
# single row update
SET @update_id := 0;
UPDATE some_table SET column_name = 'value', id = (SELECT @update_id := id)
WHERE some_other_column = 'blah' LIMIT 1;
SELECT @update_id;
# Multiple rows updated
SET @uids := null;
@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:

@wesbos
wesbos / tab-trigger.js
Created November 16, 2015 19:33
How to properly get a TAB trigger working with Emmet inside of JSX
{
"keys": ["tab"],
"command": "expand_abbreviation_by_tab",
// put comma-separated syntax selectors for which
// you want to expandEmmet abbreviations into "operand" key
// instead of SCOPE_SELECTOR.
// Examples: source.js, text.html - source
"context": [
{
@joshnuss
joshnuss / app.js
Last active March 4, 2024 00:01
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./authorization"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
@evanrs
evanrs / Await.js
Last active September 14, 2019 17:55
React WaitOn component
const Promise = require('bluebird');
const React = require('react');
const superagent = require('superagent');
const assign = require('lodash/object/assign');
const isArray = require('lodash/lang/isArray');
const isFunction = require('lodash/lang/isFunction');
const isObject = require('lodash/lang/isArray');
const isString = require('lodash/lang/isString');
const log = require('debug')('component:await');
@sebmarkbage
sebmarkbage / Enhance.js
Last active January 31, 2024 18:33
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() {
@joyrexus
joyrexus / README.md
Last active August 21, 2023 16:59
Node.js streams demystified

A quick overview of the node.js streams interface with basic examples.

This is based on @brycebaril's presentation, Node.js Streams2 Demystified

Overview

Streams are a first-class construct in Node.js for handling data.

Think of them as as lazy evaluation applied to data.