Skip to content

Instantly share code, notes, and snippets.

View richardzcode's full-sized avatar

Richard Zhang richardzcode

View GitHub Profile
@richardzcode
richardzcode / dispatcher.js
Created December 5, 2011 23:47
A bit more convenient way of routing when developing on expressjs. And add a context object to request
/**
* Path array: [method, pattern, function]
*
* Usage in app.js:
* var dispatcher = require('./routes').getDispatcher(app);
*
* dispatcher.routes('root',
* ['get', '/', 'index']
* );
*
@richardzcode
richardzcode / imageUpload.js
Created August 8, 2012 23:47
Upload image file from Node.js
/**
* Example of simulating file upload post form from node.js
*
* Set your own file and server options.
*/
var img = require('fs').readFileSync('./sample.png');
var options = { host: '...'
, port: ...
@richardzcode
richardzcode / index.js
Created March 7, 2018 02:50
A custom home page that renders README.md in Docusaurus
const React = require('react');
const fs = require('fs-extra');
const path = require('path');
const readMetadata = require('../../server/readMetadata.js');
const CompLibrary = require('../../core/CompLibrary.js');
const MarkdownBlock = CompLibrary.MarkdownBlock; /* Used to read markdown */
const join = path.join;
const CWD = process.cwd();
@richardzcode
richardzcode / App.js
Created March 7, 2018 23:50
Render base on authentication state, aws-amplify.
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Amplify, { Auth } from 'aws-amplify';
import aws_exports from './aws-exports';
import { withAuthenticator } from 'aws-amplify-react';
Amplify.Logger.LOG_LEVEL = 'DEBUG';
Amplify.configure(aws_exports);