Skip to content

Instantly share code, notes, and snippets.

View norfish's full-sized avatar
🎯
Focusing

李永翔 norfish

🎯
Focusing
View GitHub Profile
#!/bin/sh
# create self-signed server certificate:
read -p "Enter your domain [www.example.com]: " DOMAIN
echo "Create server key..."
openssl genrsa -des3 -out $DOMAIN.key 1024
@norfish
norfish / javascript
Created July 30, 2018 07:44
tiny xhr-ajax
const tinyAjax = function tinyAjax(config) {
return new Promise((resolve, reject) => {
let request = new XMLHttpRequest()
request.open(config.method.toUpperCase(), config.url, true)
request.timeout = config.timeout || 60000
// Listen for ready state
request.onreadystatechange = function handleLoad() {
if (!request || (request.readyState !== 4)) {
return;
}
@norfish
norfish / middleware.js
Last active August 19, 2018 11:15
middleware_edit from koa
class Middleware {
constructor() {
this._middleware = []
}
use(...fns) {
fns.forEach(fn => {
if (typeof fn !== 'function') {
throw new TypeError('Middleware must be function!')
}