Skip to content

Instantly share code, notes, and snippets.

View ryanlid's full-sized avatar
🎯
Focusing

ryanlid ryanlid

🎯
Focusing
View GitHub Profile
@ryanlid
ryanlid / https.js
Created December 16, 2019 17:02
HTTPS Server by Node.js
const https = require('https');
const fs = require('fs')
const options = {
key: fs.readFileSync('./cert/domain.key'),
cert: fs.readFileSync('./cert/domain.pem')
}
const app = https.createServer(options, (req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('Hello World!\n')
@ryanlid
ryanlid / http.js
Last active December 16, 2019 16:57
HTTP Server by Node.js
const http = require('http')
const app = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': "text/plain" });
res.end('Hello World\n');
})
app.listen(4000, '0.0.0.0');
@ryanlid
ryanlid / main.dart
Created November 15, 2019 08:07
创建一个名称列表,包含收藏功能
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Startup name',
@ryanlid
ryanlid / main.dart
Created November 15, 2019 06:33
flutter 创建一个无限滚动的 ListView
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final wordPair = new WordPair.random();
// return new MaterialApp(
@ryanlid
ryanlid / index.html
Created August 19, 2019 14:45
JavaScript 断言的简单实现
<!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 August 14, 2019 08:44
koa-router 基本使用
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 August 14, 2019 06:12
koa 简单的路由示例
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 August 13, 2019 01:44
koa 常用中间件
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 August 13, 2019 01:27
使用 koa-bodyparser 中间件解析POST请求参数
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 August 12, 2019 10:07
使用中间件获取响应时间
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}`);
});