Skip to content

Instantly share code, notes, and snippets.

View ryanlid's full-sized avatar
🎯
Focusing

ryanlid ryanlid

🎯
Focusing
View GitHub Profile
@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 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 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 / 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 / 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 / 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 / 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 / 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 / index.html
Created December 23, 2019 09:27
WebRTC-音视频采集
<!DOCTYPE html>
<html lang="zh-CN">
<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>WebRTC-音视频采集</title>
<style>
.none {
@ryanlid
ryanlid / http2-server.js
Created December 24, 2019 06:12
HTTP2 Server by Node.js
const http2 = require('http2');
const fs = require('fs');
const server = http2.createSecureServer({
key: fs.readFileSync('./cert/domain.key'),
cert: fs.readFileSync('./cert/domain.pem')
});
server.on('error', (err) => console.log(err));