Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

ryanlid ryanlid

🎯
Focusing
Block or report user

Report or block ryanlid

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ryanlid
ryanlid / index.html
Created Aug 19, 2019
JavaScript 断言的简单实现
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Test Suite</title>
<style>
#results li.pass {
@ryanlid
ryanlid / app.js
Created Aug 14, 2019
koa-router 基本使用
View app.js
const Koa = require("koa");
const Route = require("koa-router");
const app = new Koa();
const router = Route();
router
.get("/", async (ctx, next) => {
ctx.body = "Hello World";
console.log("get");
@ryanlid
ryanlid / app.js
Created Aug 14, 2019
koa 简单的路由示例
View app.js
const Koa = require('koa');
const app = new Koa()
const Router = require("./router");
const router = new Router();
router.get('/',(context,next)=>{
context.body = 'index Page'
})
@ryanlid
ryanlid / app.js
Created Aug 13, 2019
koa 常用中间件
View app.js
const koa = require("koa");
const views = require("koa-views");
const path = require("path");
const bodyParser = require("koa-bodyparser");
const static = require("koa-static");
const Router = require("koa-router");
const app = new koa();
const router = new Router();
// 加载模版引擎
app.use(views(__dirname + "/views"), {
@ryanlid
ryanlid / app.js
Created Aug 13, 2019
使用 koa-bodyparser 中间件解析POST请求参数
View app.js
const koa = require("koa");
const app = new koa();
const bodyParser = require("koa-bodyparser");
app.use(bodyParser());
app.use(async ctx => {
if (ctx.url === "/" && ctx.method === "GET") {
ctx.type = "html";
let html = `
<h1>登录</h1>
@ryanlid
ryanlid / app.js
Created Aug 12, 2019
使用中间件获取响应时间
View app.js
const koa = require("koa");
const app = new koa();
app.use(async (ctx, next) => {
let stime = new Date().getTime();
await next();
let etime = new Date().getTime();
ctx.response.type = "text/html";
ctx.response.body = "<h1>Hello World</h1>";
console.log(`请求地址:${ctx.path},响应时间:${etime - stime}`);
});
View promise.js
function ajax(method, url, data) {
var request = new XMLHttpRequest();
return new Promise(function (resolve, reject) {
request.onreadystatechange = function () {
if (request.readyState === 4) {
if (request.status === 200) {
resolve(request.responseText);
} else {
reject(reject(reject.status));
}
@ryanlid
ryanlid / server.js
Created Aug 3, 2019
http sever && https server
View server.js
const http = require("http");
const https = require("https");
const fs = require("fs");
const express = require("express");
const app = express();
// http server
const http_server = http.createServer(app);
http_server.listen(80, "0.0.0.0");
const options = {
View gist:0efe874b771e984df1f8001e1801fba5
void main() {
Car myCar = Car();
print(myCar.numberOfSeat);
myCar.drive();
ElectriCar myTesla = ElectriCar();
myTesla.drive();
print(myTesla.batteryLevel);
}
@ryanlid
ryanlid / main.dart
Created Jul 6, 2019
dart async await Future (flutter)
View main.dart
import 'dart:io';
void main() {
performTask();
}
void performTask() async {
task1();
String task2result = await task2();
task3(task2result);
You can’t perform that action at this time.