Skip to content

Instantly share code, notes, and snippets.

View DylanPiercey's full-sized avatar

Dylan Piercey DylanPiercey

View GitHub Profile
@DylanPiercey
DylanPiercey / rill-lodash-email-example.js
Last active December 17, 2015 02:56
An Isomorphic lodash snippet.
const _ = require("lodash")
_.chain(emails)
.chunk(100)
.filter("to")
.unshift(Promise.resolve())
.reduce((p, batch)=> {
p.then(()=> {
fetch("http://myapi.com/email", {
method: "POST",
@DylanPiercey
DylanPiercey / rill-example-1.js
Last active August 2, 2016 14:40
An Isomorphic Rill snippet.
// Creating an app is familiar.
const app = require("rill")();
// Lets pull in some middleware!
app.use(require("@rill/logger")()); // Setup logging.
app.use(require("@rill/react")()); // Setup our react renderer.
// Lets make our index page!
app.get("/", ({ req, res })=> {
// Simply set the response body to a React Element.
@DylanPiercey
DylanPiercey / rill-example-2.js
Created December 17, 2015 03:00
An Isomorphic Rill snippet
// Lets register another route.
app.get("/away", ({ req, res })=> {
res.body = <AwayPage/>;
});
// And make another simple React component.
function AwayPage (props) {
return (
<html>
<head>
@DylanPiercey
DylanPiercey / rill-example-3.js
Last active June 12, 2016 18:34
An isomorphic Rill snippet.
// Use an isomorphic form-data/body parser.
app.use(require("@rill/body")());
// Register our form page route as normal.
app.get("/my-form-page", ({ req, res })=> {
res.body = <MyForm/>
});
// Setup our post route.
app.post("/my-form-submit", ({ req, res })=> {
'use strict'
var TEXT_TYPE = 3
var ELEMENT_TYPE = 1
var NODE_KEY = '__set-dom-key__'
var NODE_INDEX = '__set-dom-index__'
var HTML_ELEMENT = document.createElement('html')
var BODY_ELEMENT = document.createElement('body')
module.exports = setDOM
var Express = require('express')
var Rill = require('rill')
// Setup express app.
var expressApp = Express()
expressApp.use(...)
expressApp.get('/', ...)
// Setup rill app.
var rillApp = Rill()
import http from 'http'
http.get('http://www.google.com/index.html', (res) => {
console.log(`Got response: ${res.statusCode}`);
// consume response body
res.resume();
}).on('error', (e) => {
console.log(`Got error: ${e.message}`);
});
const xhr = new XMLHttpRequest();
xhr.onload = () => {
// Consume response body.
const body = xhr.responseText;
}
xhr.onerror = (e) => {
console.log(`Got error: ${e.message}`);
}
import 'isomorphic-fetch'
fetch('http://www.google.com/index.html')
.then((response) => response.text())
.then((html) => {
// Work with the body.
})
.catch((e) => {
console.log(`Got error: ${e.message}`);
})
@DylanPiercey
DylanPiercey / bundle.js
Created May 23, 2017 17:11
butternut-error-bundle
This file has been truncated, but you can view the full file.
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;